[Home] [Help]
PACKAGE BODY: APPS.RLM_CUM_SV
Source
1 PACKAGE BODY RLM_CUM_SV AS
2 /* $Header: RLMCUMMB.pls 120.7.12020000.2 2013/03/28 10:18:56 sunilku ship $ */
3
4 --
5 l_DEBUG NUMBER := NVL(fnd_profile.value('RLM_DEBUG_MODE'),-1);
6 --
7 /*=============================== rlm_cum_sv ===============================*/
8
9 /*============================================================================
10
11 PROCEDURE NAME: CalculateCumKey
12
13 =============================================================================*/
14
15 PROCEDURE CalculateCumKey (
16 x_cum_key_record IN RLM_CUM_SV.cum_key_attrib_rec_type,
17 x_cum_record IN OUT NOCOPY RLM_CUM_SV.cum_rec_type)
18 IS
19 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
20 v_cum_control_code rlm_cust_shipto_terms.cum_control_code%TYPE;
21 v_cum_org_level_code rlm_cust_shipto_terms.cum_org_level_code%TYPE;
22 v_address_id NUMBER;
23 v_terms_level VARCHAR2(20) DEFAULT NULL;
24 v_setup_terms_status BOOLEAN;
25 v_start_date_num NUMBER;
26 v_record_year_num NUMBER;
27 v_setup_terms_msg VARCHAR2(2000);
28
29 /* These are variables used as switches when finding cum key ids.
30 Initially, all the switches are turned OFF by setting each to NULL */
31 p_ship_from_org_id NUMBER DEFAULT NULL;
32 p_ship_to_address_id NUMBER DEFAULT NULL;
33 p_intrmd_ship_to_address_id NUMBER DEFAULT NULL;
34 p_bill_to_address_id NUMBER DEFAULT NULL;
35 p_customer_item_id NUMBER DEFAULT NULL;
36 p_purchase_order_number RLM_CUST_ITEM_CUM_KEYS.PURCHASE_ORDER_NUMBER%TYPE DEFAULT NULL;
37 p_cust_record_year RLM_CUST_ITEM_CUM_KEYS.CUST_RECORD_YEAR%TYPE DEFAULT NULL;
38 p_cum_start_date DATE DEFAULT NULL;
39 E_UNEXPECTED EXCEPTION;
40 v_ship_from_org_name VARCHAR2(250) DEFAULT NULL;
41 v_customer_name VARCHAR2(360) DEFAULT NULL;
42 v_ship_to_location VARCHAR2(250) DEFAULT NULL;
43 v_customer_item_number VARCHAR2(250) DEFAULT NULL;
44 --
45 v_OrgId NUMBER;
46 --
47 BEGIN
48 --
49 -- DEBUGGING - INPUT Values
50 --
51 IF (l_debug <> -1) THEN
52 rlm_core_sv.dpush(C_SDEBUG, 'CalculateCumKey');
53 rlm_core_sv.dlog(C_DEBUG, '');
54 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE INPUT VALUES:');
55 rlm_core_sv.dlog(C_DEBUG, '--------------------------');
56 rlm_core_sv.dlog(C_DEBUG, 'ship_to_address_id', x_cum_key_record.ship_to_address_id);
57 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id', x_cum_key_record.ship_from_org_id);
58 rlm_core_sv.dlog(C_DEBUG, 'bill_to_address_id', x_cum_key_record.bill_to_address_id);
59 rlm_core_sv.dlog(C_DEBUG, 'intrmd_ship_to_address_id', x_cum_key_record.intrmd_ship_to_address_id);
60 rlm_core_sv.dlog(C_DEBUG, 'customer_item_id', x_cum_key_record.customer_item_id);
61 rlm_core_sv.dlog(C_DEBUG, 'purchase_order_number', x_cum_key_record.purchase_order_number);
62 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_key_record.cum_start_date);
63 rlm_core_sv.dlog(C_DEBUG, 'cust_record_year', x_cum_key_record.cust_record_year);
64 rlm_core_sv.dlog(C_DEBUG, 'create_cum_key', x_cum_key_record.create_cum_key_flag);
65 rlm_core_sv.dlog(C_DEBUG, 'actual_shipment_date', x_cum_record.actual_shipment_date);
66 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', x_cum_record.shipped_quantity);
67 END IF;
68 --
69 -- Get the current Org ID and raise error if the current Org is not set
70 -- This piece of code has been added as a fail-safe mechanism, we
71 -- always expect the current org context to be set before this API
72 -- is called
73 --
74 v_OrgId := MO_GLOBAL.get_current_org_id;
75 --
76 IF (l_debug <> -1) THEN
77 rlm_core_sv.dlog(C_DEBUG, 'Current Org ID', v_OrgId);
78 END IF;
79 --
80 IF v_OrgID IS NULL THEN
81 --
82 x_cum_record.msg_name := 'RLM_OU_CONTEXT_NOT_SET';
83 rlm_message_sv.get_msg_text(
84 x_message_name => x_cum_record.msg_name,
85 x_text => x_cum_record.msg_data);
86 --
87 RAISE e_Unexpected;
88 --
89 END IF;
90 --
91 -- Determine whether to use Ship To or Intermediate Ship To
92 --
93 IF x_cum_key_record.intrmd_ship_to_address_id IS NULL THEN
94 --
95 IF x_cum_key_record.ship_to_address_id IS NULL THEN
96 --
97 x_cum_record.msg_name := 'RLM_CUM_ADDRESS_REQUIRED';
98 rlm_message_sv.get_msg_text(
99 x_message_name => x_cum_record.msg_name,
100 x_text => x_cum_record.msg_data);
101 RAISE E_UNEXPECTED;
102 --
103 ELSE
104 --
105 v_address_id := x_cum_key_record.ship_to_address_id;
106 --
107 END IF;
108 --
109 ELSE
110 --
111 IF x_cum_key_record.ship_to_address_id IS NULL THEN
112 --
113 v_address_id := x_cum_key_record.intrmd_ship_to_address_id;
114 --
115 ELSE
116 --
117 v_address_id := x_cum_key_record.ship_to_address_id;
118 --
119 END IF;
120 --
121 END IF;
122 --
123 IF (l_debug <> -1) THEN
124 rlm_core_sv.dlog(C_DEBUG, 'address_id', v_address_id);
125 END IF;
126 --
127 -- Get the CUM Control Code from the setup terms table
128 --
129 RLM_TPA_SV.get_setup_terms(
130 x_ship_from_org_id => x_cum_key_record.ship_from_org_id,
131 x_customer_id => x_cum_key_record.customer_id,
132 x_ship_to_address_id => v_address_id,
133 x_customer_item_id => x_cum_key_record.customer_item_id,
134 x_terms_definition_level => v_terms_level,
135 x_terms_rec => v_rlm_setup_terms_record,
136 x_return_message => v_setup_terms_msg,
137 x_return_status => v_setup_terms_status);
138 --
139 IF v_setup_terms_status = FALSE THEN
140 --
141 v_ship_from_org_name := RLM_CORE_SV.get_ship_from(x_cum_key_record.ship_from_org_id);
142 v_customer_name := RLM_CORE_SV.get_customer_name(x_cum_key_record.customer_id);
143 v_ship_to_location := RLM_CORE_SV.get_ship_to(v_address_id);
144 v_customer_item_number := RLM_CORE_SV.get_item_number(x_cum_key_record.customer_item_id);
145 --
146 x_cum_record.msg_name := 'RLM_CUM_SETUP_TERMS_REQUIRED';
147 --
148 rlm_message_sv.get_msg_text(
149 x_message_name => x_cum_record.msg_name,
150 x_text => x_cum_record.msg_data,
151 x_token1 => 'SF',
152 x_value1 => v_ship_from_org_name,
153 x_token2 => 'CUST',
154 x_value2 => v_customer_name,
155 x_token3 => 'ST',
156 x_value3 => v_ship_to_location,
157 x_token4 => 'CI',
158 x_value4 => v_customer_item_number);
159 --
160 RAISE E_UNEXPECTED;
161 --
162 ELSE
163 --
164 IF v_rlm_setup_terms_record.cum_control_code IS NULL THEN
165 --
166 x_cum_record.msg_name := 'RLM_CUM_CTRLCD_REQUIRED';
167 --
168 rlm_message_sv.get_msg_text(
169 x_message_name => x_cum_record.msg_name,
170 x_text => x_cum_record.msg_data);
171 --
172 RAISE E_UNEXPECTED;
173 --
174 ELSE
175 --
176 IF v_terms_level = 'CUSTOMER_ITEM' THEN
177 --
178 IF v_rlm_setup_terms_record.calc_cum_flag <> 'Y'
179 OR v_rlm_setup_terms_record.calc_cum_flag IS NULL THEN
180 --
181 v_ship_from_org_name := RLM_CORE_SV.get_ship_from(x_cum_key_record.ship_from_org_id);
182 v_customer_name := RLM_CORE_SV.get_customer_name(x_cum_key_record.customer_id);
183 v_ship_to_location := RLM_CORE_SV.get_ship_to(v_address_id);
184 v_customer_item_number := RLM_CORE_SV.get_item_number(x_cum_key_record.customer_item_id);
185 --
186 x_cum_record.msg_name := 'RLM_CUM_NO_CALC_FLAG';
187 --
188 rlm_message_sv.get_msg_text(
189 x_message_name => x_cum_record.msg_name,
190 x_text => x_cum_record.msg_data,
191 x_token1 => 'CI',
192 x_value1 => v_customer_item_number);
193 --
194 RAISE E_UNEXPECTED;
195 --
196 END IF;
197 --
198 END IF;
199 --
200 END IF;
201 --
202 END IF;
203 --
204 -- CUM Organization Level
205 --
206 v_cum_org_level_code := v_rlm_setup_terms_record.cum_org_level_code;
207 --
208 /* Customer Item Id is always populated in the CUM Key table regardless of
209 CUM control code or CUM Organization Level. Ship From Organization Id
210 is always populated in the CUM Key table except for the case of
211 ALL_SHIP_FROMS. Therefore, the switches below are turned ON and
212 assigned to the associated parameters passed by the calling program */
213 --
214 p_customer_item_id := x_cum_key_record.customer_item_id;
215 p_ship_from_org_id := x_cum_key_record.ship_from_org_id;
216 --
217 IF v_rlm_setup_terms_record.cum_control_code <> 'NO_CUM' THEN
218 --
219 IF (x_cum_key_record.cum_start_date
220 = rlm_manage_demand_sv.K_DNULL)
221 AND (NVL(v_rlm_setup_terms_record.cum_control_code,'NO_CUM')
222 IN ('CUM_BY_DATE_PO','CUM_BY_DATE_RECORD_YEAR','CUM_BY_DATE_ONLY'))
223 THEN
224 --
225 rlm_cum_sv.GetLatestCum(x_cum_key_record,
226 v_rlm_setup_terms_record,
227 x_cum_record);
228 --
229 IF x_cum_record.record_return_status = FALSE THEN
230 --
231 fnd_file.put_line(fnd_file.log,x_cum_record.msg_data);
232 --
233 END IF;
234 --
235 IF (l_debug <> -1) THEN
236 rlm_core_sv.dpop(C_DEBUG,'CalculateCumKey');
237 END IF;
238 --
239 RETURN;
240 --
241 END IF;
242 --
243 --Turn ON switches based on cum control code
244 --
245 IF v_rlm_setup_terms_record.cum_control_code = 'CUM_BY_PO_ONLY' THEN
246 --
247 IF (x_cum_key_record.purchase_order_number IS NULL) THEN
248 --
249 x_cum_record.msg_name := 'RLM_CUM_PO_REQUIRED';
250 --
251 rlm_message_sv.get_msg_text(
252 x_message_name => x_cum_record.msg_name,
253 x_text => x_cum_record.msg_data);
254 --
255 RAISE E_UNEXPECTED;
256 --
257 END IF;
258 --
259 p_purchase_order_number := x_cum_key_record.purchase_order_number;
260 --
261 ELSIF v_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_ONLY'
262 OR v_rlm_setup_terms_record.cum_control_code = 'CUM_UNTIL_MANUAL_RESET' THEN
263 --
264 IF x_cum_key_record.cum_start_date IS NULL THEN
265 --
266 x_cum_record.msg_name := 'RLM_CUM_START_DT_REQUIRED';
267 --
268 rlm_message_sv.get_msg_text(
269 x_message_name => x_cum_record.msg_name,
270 x_text => x_cum_record.msg_data);
271 --
272 RAISE E_UNEXPECTED;
273 --
274 END IF;
275 --
276 p_cum_start_date := x_cum_key_record.cum_start_date;
277 --
278 --
279 ELSIF v_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_RECORD_YEAR' THEN
280 --
281 IF (x_cum_key_record.cum_start_date IS NULL)
282 OR (x_cum_key_record.cust_record_year IS NULL) THEN
283 --
284 x_cum_record.msg_name := 'RLM_CUM_REC_YEAR_REQUIRED';
285 --
286 rlm_message_sv.get_msg_text(
287 x_message_name => x_cum_record.msg_name,
288 x_text => x_cum_record.msg_data);
289 --
290 RAISE E_UNEXPECTED;
291 --
292 END IF;
293 --
294 p_cum_start_date := x_cum_key_record.cum_start_date;
295 p_cust_record_year := x_cum_key_record.cust_record_year;
296 --
297 ELSIF v_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_PO' THEN
298 --
299 IF (x_cum_key_record.cum_start_date IS NULL)
300 OR (x_cum_key_record.purchase_order_number IS NULL) THEN
301 --
302 x_cum_record.msg_name := 'RLM_CUM_DATE_PO_REQUIRED';
303 --
304 rlm_message_sv.get_msg_text(
305 x_message_name => x_cum_record.msg_name,
306 x_text => x_cum_record.msg_data);
307 --
308 RAISE E_UNEXPECTED;
309 --
310 END IF;
311 --
312 p_purchase_order_number := x_cum_key_record.purchase_order_number;
313 p_cum_start_date := x_cum_key_record.cum_start_date;
314 --
315 ELSE
316 --
317 x_cum_record.msg_name := 'RLM_CUM_DATE_PO_REQUIRED';
318 --
319 rlm_message_sv.get_msg_text(
320 x_message_name => x_cum_record.msg_name,
321 x_text => x_cum_record.msg_data);
322 --
323 RAISE E_UNEXPECTED;
324 --
325 END IF;
326 --
327 ELSE
328 --
329 v_ship_from_org_name := RLM_CORE_SV.get_ship_from(x_cum_key_record.ship_from_org_id);
330 v_customer_name := RLM_CORE_SV.get_customer_name(x_cum_key_record.customer_id);
331 v_ship_to_location := RLM_CORE_SV.get_ship_to(v_address_id);
332 v_customer_item_number := RLM_CORE_SV.get_item_number(x_cum_key_record.customer_item_id);
333 --
334 x_cum_record.msg_name := 'RLM_CUM_NO_CUM_CALC';
335 --
336 rlm_message_sv.get_msg_text(
337 x_message_name => x_cum_record.msg_name,
338 x_text => x_cum_record.msg_data,
339 x_token1 => 'CUST',
340 x_value1 => v_customer_name,
341 x_token2 => 'ST',
342 x_value2 => v_ship_to_location);
343 --
344 RAISE E_UNEXPECTED;
345 --
346 END IF;
347 --
348 IF (l_debug <> -1) THEN
349 rlm_core_sv.dlog(C_DEBUG, 'cum_control_code', v_rlm_setup_terms_record.cum_control_code);
350 rlm_core_sv.dlog(C_DEBUG, 'cum_org_level_code', v_cum_org_level_code);
351 rlm_core_sv.dlog(C_DEBUG, ' ');
352 rlm_core_sv.dlog(C_DEBUG, 'The setup terms were retrieved at this level: ', v_terms_level);
353 END IF;
354 --
355 -- Turn ON/OFF switches based on cum organization level code
356 --
357 IF v_cum_org_level_code = 'BILL_TO_SHIP_FROM' THEN
358 --
359 IF x_cum_key_record.bill_to_address_id IS NULL THEN
360 --
361 x_cum_record.msg_name := 'RLM_CUM_BILL_TO_REQUIRED';
362 --
363 rlm_message_sv.get_msg_text(
364 x_message_name => x_cum_record.msg_name,
365 x_text => x_cum_record.msg_data);
366 --
367 RAISE E_UNEXPECTED;
368 --
369 END IF;
370 --
371 p_bill_to_address_id := x_cum_key_record.bill_to_address_id;
372 --
373 ELSIF v_cum_org_level_code = 'SHIP_TO_SHIP_FROM' THEN
374 --
375 IF x_cum_key_record.ship_to_address_id IS NULL THEN
376 --
377 x_cum_record.msg_name := 'RLM_CUM_SHIP_TO_REQUIRED';
378 --
379 rlm_message_sv.get_msg_text(
380 x_message_name => x_cum_record.msg_name,
381 x_text => x_cum_record.msg_data);
382 --
383 RAISE E_UNEXPECTED;
384 --
385 END IF;
386 --
387 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
388 --
389 ELSIF v_cum_org_level_code = 'INTRMD_SHIP_TO_SHIP_FROM' THEN
390 --
391 IF x_cum_key_record.intrmd_ship_to_address_id IS NULL THEN
392 --
393 x_cum_record.msg_name := 'RLM_CUM_INTER_SHIP_TO_REQUIRED';
394 --
395 rlm_message_sv.get_msg_text(
396 x_message_name => x_cum_record.msg_name,
397 x_text => x_cum_record.msg_data);
398 --
399 RAISE E_UNEXPECTED;
400 --
401 END IF;
402 --
403 p_intrmd_ship_to_address_id := x_cum_key_record.intrmd_ship_to_address_id;
404 ELSIF v_cum_org_level_code = 'SHIP_TO_ALL_SHIP_FROMS' THEN
405 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
406 p_ship_from_org_id := NULL;
407 --
408 ELSE
409 --
410 x_cum_record.msg_name := 'RLM_CUM_UNKNOWN_ORG_LEVEL';
411 --
412 rlm_message_sv.get_msg_text(
413 x_message_name => x_cum_record.msg_name,
414 x_text => x_cum_record.msg_data);
415 --
416 RAISE E_UNEXPECTED;
417 --
418 END IF;
419 --
420 IF (l_debug <> -1) THEN
421 rlm_core_sv.dlog(C_DEBUG, 'cust_record_year', x_cum_key_record.cust_record_year);
422 rlm_core_sv.dlog(C_DEBUG, '');
423 rlm_core_sv.dlog(C_DEBUG, 'ATTRIBUTES ACTUALLY USED TO FIND/CREATE THE KEY:');
424 rlm_core_sv.dlog(C_DEBUG, '------------------------------------------------');
425 rlm_core_sv.dlog(C_DEBUG, 'p_ship_from_org_id', p_ship_from_org_id);
426 rlm_core_sv.dlog(C_DEBUG, 'p_ship_to_address_id', p_ship_to_address_id);
427 rlm_core_sv.dlog(C_DEBUG, 'p_intrmd_ship_to_address_id', p_intrmd_ship_to_address_id);
428 rlm_core_sv.dlog(C_DEBUG, 'p_bill_to_address_id', p_bill_to_address_id);
429 rlm_core_sv.dlog(C_DEBUG, 'p_customer_item_id', p_customer_item_id);
430 rlm_core_sv.dlog(C_DEBUG, 'p_purchase_order_number', p_purchase_order_number);
431 rlm_core_sv.dlog(C_DEBUG, 'p_cust_record_year', p_cust_record_year);
432 rlm_core_sv.dlog(C_DEBUG, 'p_cum_start_date', p_cum_start_date);
433 END IF;
434 --
435 --Find the cum key id using the CUM RULES
436 --
437 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS'THEN
438 --
439 SELECT cum_key_id,
440 cum_qty,
441 cum_qty_to_be_accumulated,
442 cum_qty_after_cutoff,
443 last_cum_qty_update_date,
444 cust_uom_code
445 INTO x_cum_record.cum_key_id,
446 x_cum_record.cum_qty,
447 x_cum_record.cum_qty_to_be_accumulated,
448 x_cum_record.cum_qty_after_cutoff,
449 x_cum_record.last_cum_qty_update_date,
450 x_cum_record.cust_uom_code
451 FROM RLM_CUST_ITEM_CUM_KEYS
452 WHERE NVL(ship_from_org_id,0) = NVL(p_ship_from_org_id,0)
453 AND NVL(ship_to_address_id,0) = NVL(p_ship_to_address_id,0)
454 AND NVL(intrmd_ship_to_id,0) = NVL(p_intrmd_ship_to_address_id,0)
455 AND NVL(bill_to_address_id,0) = NVL(p_bill_to_address_id,0)
456 AND NVL(customer_item_id,0) = NVL(p_customer_item_id,0)
457 AND NVL(purchase_order_number,' ') = NVL(p_purchase_order_number, ' ')
458 AND NVL(cust_record_year, ' ') = NVL(p_cust_record_year, ' ')
459 AND NVL(TRUNC(cum_start_date), sysdate)
460 = NVL(TRUNC(p_cum_start_date), sysdate)
461 AND NVL(inactive_flag,'N') = 'N';
462 --truncation for bug 1667299
463 --
464 ELSE
465 --
466 SELECT cum_key_id,
467 cum_qty,
468 cum_qty_to_be_accumulated,
469 cum_qty_after_cutoff,
470 last_cum_qty_update_date,
471 cust_uom_code
472 INTO x_cum_record.cum_key_id,
473 x_cum_record.cum_qty,
474 x_cum_record.cum_qty_to_be_accumulated,
475 x_cum_record.cum_qty_after_cutoff,
476 x_cum_record.last_cum_qty_update_date,
477 x_cum_record.cust_uom_code
478 FROM RLM_CUST_ITEM_CUM_KEYS
479 WHERE ship_from_org_id IS NULL
480 AND NVL(ship_to_address_id, 0) = NVL(p_ship_to_address_id,0)
481 AND NVL(intrmd_ship_to_id, 0) = NVL(p_intrmd_ship_to_address_id,0)
482 AND NVL(bill_to_address_id, 0) = NVL(p_bill_to_address_id,0)
483 AND NVL(customer_item_id, 0) = NVL(p_customer_item_id,0)
484 AND NVL(purchase_order_number,' ') = NVL(p_purchase_order_number, ' ')
485 AND NVL(cust_record_year, ' ') = NVL(p_cust_record_year, ' ')
486 AND NVL(TRUNC(cum_start_date), sysdate)
487 = NVL(TRUNC(p_cum_start_date), sysdate)
488 AND NVL(inactive_flag,'N') = 'N';
489 --truncation for bug 1667299
490 --
491 END IF;
492 --
493 x_cum_record.cum_start_date := p_cum_start_date;
494 x_cum_record.record_return_status := TRUE;
495 x_cum_record.cum_key_created_flag := FALSE;
496 x_cum_record.shipment_rule_code := v_rlm_setup_terms_record.cum_shipment_rule_code;
497
498 IF x_cum_record.cum_qty IS NULL THEN
499 x_cum_record.cum_qty := 0;
500 END IF;
501
502 IF x_cum_record.cum_qty_to_be_accumulated IS NULL THEN
503 x_cum_record.cum_qty_to_be_accumulated := 0;
504 END IF;
505
506 IF x_cum_record.cum_qty_after_cutoff IS NULL THEN
507 x_cum_record.cum_qty_after_cutoff := 0;
508 END IF;
509 --
510 /* DEBUGGING - OUTPUT Values */
511 IF (l_debug <> -1) THEN
512 rlm_core_sv.dlog(C_DEBUG, '');
513 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES:');
514 rlm_core_sv.dlog(C_DEBUG, '---------------------------');
515 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', x_cum_record.cum_key_id);
516 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_record.cum_start_date);
517 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', x_cum_record.shipped_quantity);
518 rlm_core_sv.dlog(C_DEBUG, 'actual_shipment_date', x_cum_record.actual_shipment_date);
519 rlm_core_sv.dlog(C_DEBUG, 'cum_key_created_flag', x_cum_record.cum_key_created_flag);
520 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
521 rlm_core_sv.dlog(C_DEBUG, 'as_of_date_cum_qty', x_cum_record.as_of_date_cum_qty);
522 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
523 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
524 rlm_core_sv.dlog(C_DEBUG, 'last_cum_qty_update_date', x_cum_record.last_cum_qty_update_date);
525 rlm_core_sv.dlog(C_DEBUG, 'cust_uom_code', x_cum_record.cust_uom_code);
526 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', x_cum_record.shipment_rule_code);
527 rlm_core_sv.dlog(C_DEBUG, 'use_ship_incl_rule_flag', x_cum_record.use_ship_incl_rule_flag);
528 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
529 rlm_core_sv.dpop(C_DEBUG, 'Cum key record is retrieved successfully');
530 END IF;
531 --
532 EXCEPTION
533 --
534 WHEN TOO_MANY_ROWS THEN
535 --
536 x_cum_record.msg_name := 'RLM_CUM_TOO_MANY_ROWS';
537 --
538 rlm_message_sv.get_msg_text(
539 x_message_name => x_cum_record.msg_name,
540 x_text => x_cum_record.msg_data);
541 --
542 x_cum_record.record_return_status := FALSE;
543 --
544 IF (l_debug <> -1) THEN
545 rlm_core_sv.dlog(C_DEBUG, 'msg_data', x_cum_record.msg_data);
546 rlm_core_sv.dpop(C_DEBUG, 'TOO_MANY_ROWS');
547 END IF;
548 --
549 WHEN NO_DATA_FOUND THEN
550 --
551 IF (l_debug <> -1) THEN
552 rlm_core_sv.dlog(C_DEBUG, 'No cum key id is found');
553 rlm_core_sv.dlog(C_DEBUG, 'disable_create_cum_key_flag',v_rlm_setup_terms_record.disable_create_cum_key_flag);
554 rlm_core_sv.dlog(C_DEBUG, 'v_orgId ', v_orgId);
555 END IF;
556 --
557 --IF x_cum_key_record.create_cum_key_flag = 'Y' THEN
558 IF (nvl(v_rlm_setup_terms_record.disable_create_cum_key_flag,'N') = 'N'
559 AND x_cum_key_record.create_cum_key_flag = 'Y' OR (g_manual_cum)) -- BugFix #4147544
560 THEN
561
562 --------------------------------------------------------------------+
563 /* Insert a new cum key record if the record does not exist yet and
564 if the calling progam sets the create cum key flag to 'Y' */
565
566 --
567 BEGIN
568 --
569 x_cum_record.cum_qty := 0;
570 x_cum_record.cum_qty_to_be_accumulated := 0;
571 x_cum_record.cum_qty_after_cutoff := 0;
572 --
573 INSERT INTO rlm_cust_item_cum_keys_all(
574 cum_key_id,
575 cum_qty,
576 cum_qty_to_be_accumulated,
577 cum_qty_after_cutoff,
578 customer_item_id,
579 ship_to_address_id,
580 bill_to_address_id,
581 intrmd_ship_to_id,
582 ship_from_org_id,
583 cum_start_date,
584 cust_record_year,
585 purchase_order_number,
586 last_cum_qty_update_date,
587 last_updated_by,
588 creation_date,
589 created_by,
590 last_update_date,
591 cust_uom_code,
592 org_id)
593 VALUES(
594 rlm_cust_item_cum_keys_s.nextval,
595 x_cum_record.cum_qty,
596 x_cum_record.cum_qty_to_be_accumulated,
597 x_cum_record.cum_qty_after_cutoff,
598 p_customer_item_id,
599 p_ship_to_address_id,
600 p_bill_to_address_id,
601 p_intrmd_ship_to_address_id,
602 p_ship_from_org_id,
603 p_cum_start_date,
604 p_cust_record_year,
605 p_purchase_order_number,
606 nvl(rlm_dp_sv.g_dsp_start_time,sysdate), --sysdate, --Bugfix 10053830
607 fnd_global.user_id,
608 sysdate,
609 fnd_global.user_id,
610 sysdate,
611 x_cum_record.cust_uom_code,
612 v_OrgId);
613 --
614 SELECT rlm_cust_item_cum_keys_s.currval
615 INTO x_cum_record.cum_key_id
616 FROM DUAL;
617 --
618 x_cum_record.cum_start_date := p_cum_start_date;
619 x_cum_record.cum_key_created_flag := TRUE;
620 x_cum_record.record_return_status := TRUE;
621 --x_cum_record.last_cum_qty_update_date := SYSDATE; --Bugfix 10053830
622 x_cum_record.last_cum_qty_update_date := nvl(rlm_dp_sv.g_dsp_start_time,sysdate); --Bugfix 10053830
623 --
624 x_cum_record.msg_name := 'RLM_CUM_KEY_ID_CREATED';
625 --
626 rlm_message_sv.get_msg_text(
627 x_message_name => x_cum_record.msg_name,
628 x_text => x_cum_record.msg_data);
629 --
630 --DEBUGGING - Output Values
631 IF (l_debug <> -1) THEN
632 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE NEWLY INSERTED RECORD VALUES');
633 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', x_cum_record.cum_key_id);
634 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_record.cum_start_date);
635 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', x_cum_record.shipped_quantity);
636 rlm_core_sv.dlog(C_DEBUG, 'actual_ship_date', x_cum_record.actual_shipment_date);
637 rlm_core_sv.dlog(C_DEBUG, 'cum_key_created', x_cum_record.cum_key_created_flag);
638 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
639 rlm_core_sv.dlog(C_DEBUG, 'cust_uom_code', x_cum_record.cust_uom_code);
640 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
641 rlm_core_sv.dpop(C_DEBUG, x_cum_record.msg_data);
642 END IF;
643 --
644 EXCEPTION
645 --
646 WHEN OTHERS THEN
647 --
648 x_cum_record.msg_name := 'RLM_CUM_KEY_NOT_CREATED';
649 --
650 rlm_message_sv.get_msg_text(
651 x_message_name => x_cum_record.msg_name,
652 x_text => x_cum_record.msg_data,
653 x_token1 => 'SQLERRM',
654 x_value1 => SQLERRM);
655 --
656 x_cum_record.record_return_status := FALSE;
657 --
658 IF (l_debug <> -1) THEN
659 rlm_core_sv.dlog(C_DEBUG, x_cum_record.msg_data);
660 rlm_core_sv.dpop(C_DEBUG, SQLERRM);
661 END IF;
662 --
663 END;
664 ----------------------------------------------------------------+
665
666 ELSE
667 -- If create_cum_key_flag is 'N', set record return status to TRUE
668 --
669 x_cum_record.cum_key_id := NULL; -- Bug 4667349
670 x_cum_record.record_return_status := TRUE;
671 --
672 IF (l_debug <> -1) THEN
673 rlm_core_sv.dpop(C_DEBUG, 'CUM Key Id is not found, and not created as create_cum_key_flag is set to N');
674 END IF;
675 --
676 END IF;
677 --
678 WHEN E_UNEXPECTED THEN
679 --
680 x_cum_record.record_return_status := FALSE;
681 --
682 IF (l_debug <> -1) THEN
683 rlm_core_sv.dlog(C_DEBUG,'msg_data',x_cum_record.msg_data);
684 rlm_core_sv.dlog(C_DEBUG,'record_return_status',x_cum_record.record_return_status);
685 rlm_core_sv.dpop(C_DEBUG,'E_UNEXPECTED');
686 END IF;
687 --
688 WHEN OTHERS THEN
689 --
690 -- RLM_CUM_SQLERR
691 --
692 x_cum_record.record_return_status := FALSE;
693 --DEBUGGING - OUTPUT Values
694 IF (l_debug <> -1) THEN
695 rlm_core_sv.dlog(C_DEBUG, '');
696 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES:');
697 rlm_core_sv.dlog(C_DEBUG, '---------------------------');
698 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', x_cum_record.cum_key_id);
699 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_record.cum_start_date);
700 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', x_cum_record.shipped_quantity);
701 rlm_core_sv.dlog(C_DEBUG, 'actual_ship_date', x_cum_record.actual_shipment_date);
702 rlm_core_sv.dlog(C_DEBUG, 'cum_key_created', x_cum_record.cum_key_created_flag);
703 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
704 rlm_core_sv.dlog(C_DEBUG, 'cust_uom_code', x_cum_record.cust_uom_code);
705 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
706 rlm_core_sv.dpop(C_DEBUG, SQLERRM);
707 END IF;
708 --
709 END CalculateCumKey;
710 --
711 /*============================================================================
712
713 PROCEDURE NAME: CalculateCumKeyClient
714
715 =============================================================================*/
716
717 PROCEDURE CalculateCumKeyClient (
718 -- Parameter definition was changed TCA obsolescence project.
719 x_customer_id IN HZ_CUST_ACCOUNTS.CUST_ACCOUNT_ID%TYPE,
720 x_customer_item_id IN RLM_CUST_ITEM_CUM_KEYS.CUSTOMER_ITEM_ID%TYPE,
721 x_ship_from_org_id IN RLM_CUST_ITEM_CUM_KEYS.SHIP_FROM_ORG_ID%TYPE,
722 x_intrmd_ship_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.INTRMD_SHIP_TO_ID%TYPE,
723 x_ship_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.SHIP_TO_ADDRESS_ID%TYPE,
724 x_bill_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.BILL_TO_ADDRESS_ID%TYPE,
725 x_purchase_order_number IN RLM_CUST_ITEM_CUM_KEYS.PURCHASE_ORDER_NUMBER%TYPE,
726 x_cust_record_year IN RLM_CUST_ITEM_CUM_KEYS.CUST_RECORD_YEAR%TYPE,
727 x_create_cum_key_flag IN VARCHAR2,
728 x_msg_data IN OUT NOCOPY VARCHAR2,
729 x_record_return_status IN OUT NOCOPY BOOLEAN,
730 x_cum_key_id IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_KEY_ID%TYPE,
731 x_cum_start_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_START_DATE%TYPE,
732 x_shipped_quantity IN OUT NOCOPY OE_ORDER_LINES.SHIPPED_QUANTITY%TYPE,
733 x_actual_shipment_date IN OUT NOCOPY OE_ORDER_LINES.ACTUAL_SHIPMENT_DATE%TYPE,
734 x_cum_key_created_flag IN OUT NOCOPY BOOLEAN,
735 x_cum_qty IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY%TYPE,
736 x_as_of_date_cum_qty IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY%TYPE,
737 x_cum_qty_to_be_accumulated IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY_TO_BE_ACCUMULATED%TYPE,
738 x_cum_qty_after_cutoff IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY_AFTER_CUTOFF%TYPE,
739 x_last_cum_qty_update_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_CUM_QTY_UPDATE_DATE%TYPE,
740 x_cust_uom_code IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUST_UOM_CODE%TYPE,
741 x_use_ship_incl_rule_flag IN OUT NOCOPY VARCHAR2,
742 x_shipment_rule_code IN OUT NOCOPY RLM_CUST_SHIPTO_TERMS.CUM_SHIPMENT_RULE_CODE%TYPE,
743 x_yesterday_time_cutoff IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_UPDATE_DATE%TYPE,
744 x_last_update_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_UPDATE_DATE%TYPE,
745 x_as_of_date_time IN OUT NOCOPY OE_ORDER_LINES.ACTUAL_SHIPMENT_DATE%TYPE)
746 --
747 IS
748 --
749 x_cum_key_record cum_key_attrib_rec_type;
750 x_cum_record cum_rec_type;
751 --
752 BEGIN
753 --
754 IF (l_debug <> -1) THEN
755 rlm_core_sv.start_debug;
756 rlm_core_sv.dpush(C_SDEBUG, 'CalculateCumKeyClient');
757 END IF;
758 --
759 x_cum_key_record.customer_id := x_customer_id;
760 x_cum_key_record.customer_item_id := x_customer_item_id;
761
762 x_cum_key_record.ship_from_org_id := x_ship_from_org_id;
763 x_cum_key_record.intrmd_ship_to_address_id := x_intrmd_ship_to_address_id;
764 x_cum_key_record.ship_to_address_id := x_ship_to_address_id;
765 x_cum_key_record.bill_to_address_id := x_bill_to_address_id;
766 x_cum_key_record.purchase_order_number := x_purchase_order_number;
767 x_cum_key_record.cust_record_year:= x_cust_record_year;
768 x_cum_key_record.cum_start_date := x_cum_start_date;
769 x_cum_key_record.create_cum_key_flag := x_create_cum_key_flag;
770 x_cum_key_record.create_cum_key_flag := 'Y';
771 x_cum_record.msg_data := x_msg_data;
772 x_cum_record.record_return_status := x_record_return_status;
773 x_cum_record.cum_key_id := x_cum_key_id;
774 x_cum_record.cum_start_date := x_cum_start_date;
775 x_cum_record.shipped_quantity := x_shipped_quantity;
776 --
777 IF x_actual_shipment_date IS NOT NULL THEN
778 --
779 x_cum_record.actual_shipment_date := x_actual_shipment_date;
780 --
781 ELSE
782 --
783 --Bugfix 10053830 Start
784 /*SELECT SYSDATE
785 INTO x_cum_record.actual_shipment_date
786 FROM DUAL;*/
787 x_cum_record.actual_shipment_date := nvl(rlm_dp_sv.g_dsp_start_time,sysdate);
788 --Bugfix 10053830 End
789 --
790 END IF;
791 --
792 x_cum_record.cum_key_created_flag := x_cum_key_created_flag;
793 x_cum_record.cum_qty:= x_cum_qty;
794 x_cum_record.as_of_date_cum_qty := x_as_of_date_cum_qty;
795 x_cum_record.cum_qty_to_be_accumulated := x_cum_qty_to_be_accumulated;
796 x_cum_record.cum_qty_after_cutoff := x_cum_qty_after_cutoff;
797 x_cum_record.last_cum_qty_update_date:= x_last_cum_qty_update_date;
798 x_cum_record.cust_uom_code := x_cust_uom_code;
799 x_cum_record.use_ship_incl_rule_flag := x_use_ship_incl_rule_flag;
800 x_cum_record.shipment_rule_code := x_shipment_rule_code;
801 x_cum_record.yesterday_time_cutoff := x_yesterday_time_cutoff;
802 x_cum_record.last_update_date := x_last_update_date;
803 x_cum_record.as_of_date_time := x_as_of_date_time;
804 --
805 -- Call calculate cum key api passing cum key records and cum records
806 --
807 g_manual_cum := TRUE; -- BugFix #4147544
808 --
809 RLM_TPA_SV.CalculateCumKey (x_cum_key_record => x_cum_key_record,
810 x_cum_record => x_cum_record);
811 x_msg_data := x_cum_record.msg_data;
812 x_record_return_status := x_cum_record.record_return_status;
813 x_cum_key_id := x_cum_record.cum_key_id;
814 x_cum_start_date := x_cum_record.cum_start_date;
815 x_shipped_quantity := x_cum_record.shipped_quantity;
816 x_actual_shipment_date := x_cum_record.actual_shipment_date;
817 x_cum_key_created_flag := x_cum_record.cum_key_created_flag;
818 x_cum_qty := x_cum_record.cum_qty;
819 x_as_of_date_cum_qty := x_cum_record.as_of_date_cum_qty;
820 x_cum_qty_to_be_accumulated := x_cum_record.cum_qty_to_be_accumulated;
821 x_cum_qty_after_cutoff := x_cum_record.cum_qty_after_cutoff;
822 x_last_cum_qty_update_date := x_cum_record.last_cum_qty_update_date;
823 x_cust_uom_code := x_cum_record.cust_uom_code;
824 x_use_ship_incl_rule_flag := x_cum_record.use_ship_incl_rule_flag;
825 x_shipment_rule_code := x_cum_record.shipment_rule_code;
826 x_yesterday_time_cutoff := x_cum_record.yesterday_time_cutoff;
827 x_last_update_date := x_cum_record.last_update_date;
828 x_as_of_date_time := x_cum_record.as_of_date_time;
829 --
830 g_manual_cum := FALSE; -- BugFix #4147544
831 --
832 IF (l_debug <> -1) THEN
833 rlm_core_sv.stop_debug;
834 END IF;
835 --
836 EXCEPTION
837 --
838 WHEN OTHERS THEN
839 --
840 IF (l_debug <> -1) THEN
841 rlm_core_sv.dpop(C_DEBUG, SQLERRM);
842 rlm_core_sv.stop_debug;
843 END IF;
844 --
845 END CalculateCumKeyClient;
846 --
847
848 /*============================================================================
849
850 PROCEDURE NAME: CalculateSupplierCum
851
852 =============================================================================*/
853
854 PROCEDURE CalculateSupplierCum (
855 x_new_ship_count IN RLM_CUM_SV.t_new_ship_count := RLM_CUM_SV.g_miss_new_ship_count,
856 x_cum_key_record IN RLM_CUM_SV.cum_key_attrib_rec_type,
857 x_cum_record IN OUT NOCOPY RLM_CUM_SV.cum_rec_type)
858 IS
859 --
860 E_UNEXPECTED EXCEPTION;
861 v_terms_level VARCHAR2(15) DEFAULT NULL;
862 v_terms_level2 VARCHAR2(15) DEFAULT NULL;
863 v_setup_terms_msg VARCHAR2(2000);
864 v_return_status BOOLEAN DEFAULT FALSE;
865 rlm_setup_record rlm_setup_terms_sv.setup_terms_rec_typ;
866 v_cutoff_date DATE;
867 v_ship_to_org_id NUMBER;
868 v_bill_to_org_id NUMBER;
869 adj_qty NUMBER DEFAULT 0;
870 v_ship_from_org_name VARCHAR2(250);
871 v_customer_name VARCHAR2(360);
872 v_ship_to_location VARCHAR2(250);
873 v_customer_item_number VARCHAR2(250);
874 --
875 BEGIN
876 --
877 /* DEBUGGING - INPUT Values */
878 IF (l_debug <> -1) THEN
879 rlm_core_sv.dpush(C_SDEBUG, 'CalculateSupplierCum');
880 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE INPUT VALUES');
881 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id', x_cum_key_record.ship_from_org_id);
882 rlm_core_sv.dlog(C_DEBUG, 'ship_to_address_id', x_cum_key_record.ship_to_address_id);
883 rlm_core_sv.dlog(C_DEBUG, 'inventory_item_id', x_cum_key_record.inventory_item_id);
884 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
885 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
886 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
887 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', x_cum_record.shipped_quantity);
888 rlm_core_sv.dlog(C_DEBUG, 'actual_shipment_date', x_cum_record.actual_shipment_date);
889 rlm_core_sv.dlog(C_DEBUG, 'use_ship_incl_rule_flag', x_cum_record.use_ship_incl_rule_flag);
890 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
891 END IF;
892 --
893 IF x_cum_record.record_return_status = FALSE THEN
894 --
895 x_cum_record.msg_name := 'RLM_CUM_INVALID_RECORD';
896 --
897 rlm_message_sv.get_msg_text(
898 x_message_name => x_cum_record.msg_name,
899 x_text => x_cum_record.msg_data);
900 --
901 RAISE E_UNEXPECTED;
902 --
903 END IF;
904 --
905 --
906 IF x_cum_record.use_ship_incl_rule_flag = 'N' THEN
907
908 /* CUM calculation will be done using as_of_date_time being
909 the cutoff date. This as_of_date_time is not necessarily
910 the cum_shipment_rule_code cutoff date. The as_of_date_time
911 could be any value between the cum_start_date and today */
912 --
913 IF (l_debug <> -1) THEN
914 rlm_core_sv.dlog(C_DEBUG, 'Cum calculation is done using as_of_date_time');
915 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', x_cum_record.cum_key_id);
916 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_record.cum_start_date);
917 rlm_core_sv.dlog(C_DEBUG, 'as_of_date_time', x_cum_record.as_of_date_time);
918 END IF;
919 --
920 SELECT NVL((SUM(shipped_quantity)), 0)
921 INTO x_cum_record.as_of_date_cum_qty
922 FROM OE_ORDER_LINES
923 WHERE veh_cus_item_cum_key_id = x_cum_record.cum_key_id
924 AND actual_shipment_date >= x_cum_record.cum_start_date
925 AND actual_shipment_date <= x_cum_record.as_of_date_time
926 AND source_document_type_id = 5
927 AND open_flag = 'N'
928 AND shipped_quantity IS NOT NULL
929 AND inventory_item_id = x_cum_key_record.inventory_item_id;
930 --
931 SELECT NVL(SUM(transaction_qty), 0)
932 INTO adj_qty
933 FROM rlm_cust_item_cum_adj
934 WHERE cum_key_id = x_cum_record.cum_key_id
935 AND transaction_date_time >= x_cum_record.cum_start_date
936 AND transaction_date_time <= x_cum_record.as_of_date_time;
937 --
938 x_cum_record.as_of_date_cum_qty := x_cum_record.as_of_date_cum_qty + adj_qty;
939 --
940 IF (l_debug <> -1) THEN
941 rlm_core_sv.dlog(C_DEBUG, 'as_of_date_cum_qty', x_cum_record.as_of_date_cum_qty);
942 END IF;
943 --
944 ELSIF x_cum_record.use_ship_incl_rule_flag = 'Y' THEN
945
946 /* Get cum_shipment_rule_code and cum_yesterd_time_cutoff */
947 --
948 RLM_TPA_SV.get_setup_terms(
949 x_ship_from_org_id => x_cum_key_record.ship_from_org_id,
950 x_customer_id => x_cum_key_record.customer_id,
951 x_ship_to_address_id => x_cum_key_record.ship_to_address_id,
952 x_customer_item_id => x_cum_key_record.customer_item_id,
953 x_terms_definition_level => v_terms_level,
954 x_terms_rec => rlm_setup_record,
955 x_return_message => v_setup_terms_msg,
956 x_return_status => v_return_status);
957 --
958 IF v_return_status = FALSE THEN
959 --
960 v_ship_from_org_name := RLM_CORE_SV.get_ship_from(x_cum_key_record.ship_from_org_id);
961 v_customer_name := RLM_CORE_SV.get_customer_name(x_cum_key_record.customer_id);
962 v_ship_to_location := RLM_CORE_SV.get_ship_to(x_cum_key_record.ship_to_address_id);
963 v_customer_item_number := RLM_CORE_SV.get_item_number(x_cum_key_record.customer_item_id);
964 --
965 x_cum_record.msg_name := 'RLM_CUM_SETUP_TERMS_REQUIRED';
966 --
967 rlm_message_sv.get_msg_text(
968 x_message_name => x_cum_record.msg_name,
969 x_text => x_cum_record.msg_data,
970 x_token1 => 'SF',
971 x_value1 => v_ship_from_org_name,
972 x_token2 => 'CUST',
973 x_value2 => v_customer_name,
974 x_token3 => 'ST',
975 x_value3 => v_ship_to_location,
976 x_token4 => 'CI',
977 x_value4 => v_customer_item_number);
978 --
979 RAISE E_UNEXPECTED;
980 --
981 END IF;
982 --
983 --
984 IF rlm_setup_record.cum_shipment_rule_code IS NOT NULL THEN
985 --
986 x_cum_record.shipment_rule_code := rlm_setup_record.cum_shipment_rule_code;
987 --
988 ELSE
989 --
990 -- RLM_CUM_NO_SHIP_RULE
991 -- This message will not go to the end user
992 x_cum_record.msg_data := 'Cum shipment rule code is not found. Proceed with "As of Current Shipment" rule code';
993 IF (l_debug <> -1) THEN
994 rlm_core_sv.dlog(C_DEBUG, x_cum_record.msg_data);
995 END IF;
996 --
997 END IF;
998 --
999 IF x_cum_record.shipment_rule_code <> 'AS_OF_YESTERDAY' THEN
1000 --
1001 IF x_cum_record.shipment_rule_code = 'AS_OF_CURRENT' THEN
1002 --
1003 IF x_cum_record.as_of_date_time IS NULL THEN
1004 --
1005 x_cum_record.cum_qty := NVL(x_cum_record.cum_qty,0) + NVL(x_cum_record.cum_qty_to_be_accumulated,0) + NVL(x_cum_record.shipped_quantity,0);
1006 --
1007 x_cum_record.cum_qty_to_be_accumulated := 0;
1008 --
1009 ELSE
1010 --
1011 v_cutoff_date := x_cum_record.as_of_date_time;
1012 --
1013 END IF;
1014 --
1015 ELSIF x_cum_record.shipment_rule_code = 'AS_OF_PRIOR' THEN
1016 --
1017 IF x_cum_record.as_of_date_time IS NULL THEN
1018 --
1019 IF x_new_ship_count(x_cum_record.cum_key_id) = 1 THEN
1020 --
1021 x_cum_record.cum_qty := NVL(x_cum_record.cum_qty,0) + NVL(x_cum_record.cum_qty_to_be_accumulated,0);
1022 --
1023 x_cum_record.cum_qty_to_be_accumulated := 0;
1024 --
1025 END IF;
1026 --
1027 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.cum_qty_to_be_accumulated,0) + NVL(x_cum_record.shipped_quantity,0);
1028 --
1029 ELSE
1030 --
1031 -- Get the last shipment date before the as_of_date_time
1032 --
1033 BEGIN
1034 --
1035 -- TODO: Verify this logic again
1036 --
1037 SELECT MAX(actual_shipment_date)
1038 INTO v_cutoff_date
1039 FROM oe_order_lines
1040 WHERE veh_cus_item_cum_key_id = x_cum_record.cum_key_id
1041 AND source_document_type_id = 5
1042 AND open_flag = 'N'
1043 AND shipped_quantity IS NOT NULL
1044 AND actual_shipment_date < x_cum_record.as_of_date_time
1045 AND inventory_item_id = x_cum_key_record.inventory_item_id;
1046 --
1047 EXCEPTION
1048 --
1049 WHEN NO_DATA_FOUND THEN
1050 --
1051 IF (l_debug <> -1) THEN
1052 rlm_core_sv.dlog(C_DEBUG, 'No data found');
1053 END IF;
1054 --
1055 END;
1056 --
1057 END IF;
1058 --
1059 ELSE
1060 --
1061 x_cum_record.msg_name := 'RLM_CUM_UNKNOWN_SHIP_RULE';
1062 --
1063 rlm_message_sv.get_msg_text(
1064 x_message_name => x_cum_record.msg_name,
1065 x_text => x_cum_record.msg_data);
1066 --
1067 RAISE E_UNEXPECTED;
1068 --
1069 END IF;
1070 --
1071 ELSE
1072 --
1073 -- 'AS_OF_YESTERDAY'
1074 --
1075 IF x_cum_record.as_of_date_time IS NULL THEN
1076 --
1077 --SELECT TO_DATE(TO_CHAR(SYSDATE-1, 'DD/MM/YYYY') --Bugfix 10053830
1078 SELECT TO_DATE(TO_CHAR(nvl(rlm_dp_sv.g_dsp_start_time,sysdate)-1, 'DD/MM/YYYY') --Bugfix 10053830
1079 ||
1080 DECODE(SIGN(rlm_setup_record.cum_yesterd_time_cutoff/1000-1),
1081 -1, '0'||to_char(rlm_setup_record.cum_yesterd_time_cutoff),
1082 to_char(rlm_setup_record.cum_yesterd_time_cutoff)),
1083 'DD/MM/YYYY HH24MI')
1084 INTO x_cum_record.yesterday_time_cutoff
1085 FROM DUAL;
1086 --
1087 IF x_cum_key_record.called_by_reset_cum = 'N' THEN
1088 --
1089 /* Calculate supplier_cum based on all shipments dated
1090 since CUM start date excluding the shipments since yesterday
1091 cutoff time. */
1092 --
1093 --IF (SYSDATE-1) < (x_cum_record.yesterday_time_cutoff) THEN --Bugfix 10053830
1094 IF (nvl(rlm_dp_sv.g_dsp_start_time,sysdate)-1) < (x_cum_record.yesterday_time_cutoff) THEN --Bugfix 10053830
1095 --
1096 --IF TRUNC(x_cum_record.last_cum_qty_update_date) < TRUNC(SYSDATE) THEN --Bugfix 10053830
1097 IF TRUNC(x_cum_record.last_cum_qty_update_date) < TRUNC(nvl(rlm_dp_sv.g_dsp_start_time,sysdate)) THEN --Bugfix 10053830
1098 --
1099 x_cum_record.cum_qty := NVL(x_cum_record.cum_qty,0) + NVL(x_cum_record.cum_qty_to_be_accumulated,0);
1100 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.shipped_quantity,0) + NVL(x_cum_record.cum_qty_after_cutoff,0);
1101 x_cum_record.cum_qty_after_cutoff := 0;
1102 --
1103 ELSE
1104 --
1105 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.cum_qty_to_be_accumulated,0) + NVL(x_cum_record.shipped_quantity,0);
1106 --
1107 END IF;
1108 --
1109 ELSE
1110 --
1111 --IF TRUNC(x_cum_record.last_cum_qty_update_date) < TRUNC(SYSDATE) THEN --Bugfix 10053830
1112 IF TRUNC(x_cum_record.last_cum_qty_update_date) < TRUNC(nvl(rlm_dp_sv.g_dsp_start_time,sysdate)) THEN --Bugfix 10053830
1113 --
1114 x_cum_record.cum_qty := NVL(x_cum_record.cum_qty,0) + NVL(x_cum_record.cum_qty_to_be_accumulated,0);
1115 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.cum_qty_after_cutoff,0);
1116 x_cum_record.cum_qty_after_cutoff := 0;
1117 --
1118 END IF;
1119 --
1120 x_cum_record.cum_qty_after_cutoff := NVL(x_cum_record.shipped_quantity,0) + NVL(x_cum_record.cum_qty_after_cutoff,0);
1121 --
1122 END IF;
1123 --
1124 ELSE
1125 --
1126 IF x_cum_record.actual_shipment_date < x_cum_record.yesterday_time_cutoff THEN
1127 --
1128 x_cum_record.cum_qty := NVL(x_cum_record.cum_qty,0) + NVL(x_cum_record.shipped_quantity,0);
1129 ELSE
1130 --
1131 --IF TRUNC(x_cum_record.actual_shipment_date) < TRUNC(SYSDATE) THEN --Bugfix 10053830
1132 IF TRUNC(x_cum_record.actual_shipment_date) < TRUNC(nvl(rlm_dp_sv.g_dsp_start_time,sysdate)) THEN --Bugfix 10053830
1133 --
1134 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.cum_qty_to_be_accumulated,0) + NVL(x_cum_record.shipped_quantity,0);
1135 --
1136 ELSE
1137 --
1138 IF x_cum_record.actual_shipment_date < (x_cum_record.yesterday_time_cutoff + 1) THEN
1139 --
1140 x_cum_record.cum_qty_to_be_accumulated := NVL(x_cum_record.cum_qty_to_be_accumulated,0) + NVL(x_cum_record.shipped_quantity,0);
1141 --
1142 ELSE
1143 --
1144 x_cum_record.cum_qty_after_cutoff := NVL(x_cum_record.cum_qty_after_cutoff,0) + NVL(x_cum_record.shipped_quantity,0);
1145 --
1146 END IF;
1147 --
1148 END IF;
1149 --
1150 END IF;
1151 --
1152 END IF;
1153 --
1154 ELSE
1155 --
1156 SELECT TO_DATE(TO_CHAR(x_cum_record.as_of_date_time, 'DD/MM/YYYY')
1157 ||
1158 DECODE(SIGN(rlm_setup_record.cum_yesterd_time_cutoff/1000-1),
1159 -1, '0'||to_char(rlm_setup_record.cum_yesterd_time_cutoff),
1160 to_char(rlm_setup_record.cum_yesterd_time_cutoff)),
1161 'DD/MM/YYYY HH24MI')
1162 INTO x_cum_record.yesterday_time_cutoff
1163 FROM DUAL;
1164 --
1165 v_cutoff_date := x_cum_record.yesterday_time_cutoff;
1166 --
1167 END IF;
1168 --
1169 END IF;
1170 --
1171 --
1172 IF x_cum_record.as_of_date_time IS NOT NULL THEN
1173 --
1174 IF x_cum_record.as_of_date_time <> x_cum_record.last_cum_qty_update_date THEN
1175 --
1176 BEGIN
1177 --
1178 SELECT NVL(SUM(shipped_quantity), 0)
1179 INTO x_cum_record.as_of_date_cum_qty
1180 FROM OE_ORDER_LINES
1181 WHERE veh_cus_item_cum_key_id = x_cum_record.cum_key_id
1182 AND actual_shipment_date >= x_cum_record.cum_start_date
1183 AND actual_shipment_date <= v_cutoff_date
1184 AND source_document_type_id = 5
1185 AND open_flag = 'N'
1186 AND shipped_quantity IS NOT NULL
1187 AND inventory_item_id = x_cum_key_record.inventory_item_id;
1188 --
1189 SELECT NVL(SUM(transaction_qty), 0)
1190 INTO adj_qty
1191 FROM rlm_cust_item_cum_adj
1192 WHERE cum_key_id = x_cum_record.cum_key_id
1193 AND transaction_date_time >= x_cum_record.cum_start_date
1194 AND transaction_date_time <= v_cutoff_date;
1195 --
1196 x_cum_record.as_of_date_cum_qty := x_cum_record.as_of_date_cum_qty + adj_qty;
1197 --
1198 EXCEPTION
1199 --
1200 WHEN NO_DATA_FOUND THEN
1201 --
1202 x_cum_record.msg_name := 'RLM_CUM_NO_AOD_SHIPMENT';
1203 --
1204 rlm_message_sv.get_msg_text(
1205 x_message_name => x_cum_record.msg_name,
1206 x_text => x_cum_record.msg_data,
1207 x_token1 => 'CSD',
1208 x_value1 => TO_CHAR(x_cum_record.cum_start_date),
1209 x_token2 => 'CTD',
1210 x_value2 => TO_CHAR(v_cutoff_date));
1211 --
1212 IF (l_debug <> -1) THEN
1213 rlm_core_sv.dlog(C_DEBUG, 'RLM_CUM_NO_AOD_SHIPMENT -- as_of_date_time not null');
1214 END IF;
1215 --
1216 END;
1217 --
1218 ELSE
1219 --
1220 /* There is no intransit shipment. The previously stored quantity is the same */
1221 --
1222 x_cum_record.as_of_date_cum_qty := x_cum_record.cum_qty;
1223 --
1224 END IF;
1225 --
1226 END IF;
1227 --
1228 END IF;
1229 --
1230 x_cum_record.record_return_status := TRUE;
1231 --
1232 /* DEBUGGING - OUTPUT Values */
1233 IF (l_debug <> -1) THEN
1234 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES');
1235 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
1236 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
1237 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
1238 rlm_core_sv.dlog(C_DEBUG, 'as_of_date_cum_qty', x_cum_record.as_of_date_cum_qty);
1239 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', x_cum_record.shipment_rule_code);
1240 rlm_core_sv.dlog(C_DEBUG, 'yesterday_time_cutoff', x_cum_record.yesterday_time_cutoff);
1241 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
1242 rlm_core_sv.dpop(C_DEBUG, 'Terminate successfully');
1243 END IF;
1244 --
1245 EXCEPTION
1246 --
1247 WHEN E_UNEXPECTED THEN
1248 --
1249 x_cum_record.record_return_status := FALSE;
1250 --
1251 /* DEBUGGING - OUTPUT Values */
1252 IF (l_debug <> -1) THEN
1253 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES');
1254 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
1255 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
1256 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
1257 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', x_cum_record.shipment_rule_code);
1258 rlm_core_sv.dlog(C_DEBUG, 'yesterday_time_cutoff', x_cum_record.yesterday_time_cutoff);
1259 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
1260 rlm_core_sv.dpop(C_DEBUG, x_cum_record.msg_data);
1261 END IF;
1262 --
1263 WHEN NO_DATA_FOUND THEN
1264 --
1265 x_cum_record.record_return_status := FALSE;
1266 --
1267 /* DEBUGGING - OUTPUT Values */
1268 IF (l_debug <> -1) THEN
1269 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES');
1270 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
1271 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
1272 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
1273 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', x_cum_record.shipment_rule_code);
1274 rlm_core_sv.dlog(C_DEBUG, 'yesterday_time_cutoff', x_cum_record.yesterday_time_cutoff);
1275 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
1276 rlm_core_sv.dpop(C_DEBUG, 'No record found using the set of input values provided');
1277 END IF;
1278 --
1279 WHEN OTHERS THEN
1280 --
1281 x_cum_record.record_return_status := FALSE;
1282 --
1283 /* DEBUGGING - OUTPUT Values */
1284 IF (l_debug <> -1) THEN
1285 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES');
1286 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
1287 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', x_cum_record.cum_qty_to_be_accumulated);
1288 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', x_cum_record.cum_qty_after_cutoff);
1289 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', x_cum_record.shipment_rule_code);
1290 rlm_core_sv.dlog(C_DEBUG, 'yesterday_time_cutoff', x_cum_record.yesterday_time_cutoff);
1291 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', x_cum_record.record_return_status);
1292 -- RLM_CUM_SQLERR
1293 rlm_core_sv.dpop(C_DEBUG, SQLERRM);
1294 END IF;
1295 --
1296 END CalculateSupplierCum;
1297
1298 /*============================================================================
1299
1300 PROCEDURE NAME: CalculateSupplierCumClient
1301
1302 =============================================================================*/
1303
1304 PROCEDURE CalculateSupplierCumClient (
1305 -- Parameter definition was changed TCA obsolescence project.
1306 x_customer_id IN HZ_CUST_ACCOUNTS.CUST_ACCOUNT_ID%TYPE,
1307 x_customer_item_id IN RLM_CUST_ITEM_CUM_KEYS.CUSTOMER_ITEM_ID%TYPE,
1308 x_inventory_item_id IN OE_ORDER_LINES.INVENTORY_ITEM_ID%TYPE,
1309 x_ship_from_org_id IN RLM_CUST_ITEM_CUM_KEYS.SHIP_FROM_ORG_ID%TYPE,
1310 x_intrmd_ship_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.INTRMD_SHIP_TO_ID%TYPE,
1311 x_ship_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.SHIP_TO_ADDRESS_ID%TYPE,
1312 x_bill_to_address_id IN RLM_CUST_ITEM_CUM_KEYS.BILL_TO_ADDRESS_ID%TYPE,
1313 x_purchase_order_number IN RLM_CUST_ITEM_CUM_KEYS.PURCHASE_ORDER_NUMBER%TYPE,
1314 x_cust_record_year IN RLM_CUST_ITEM_CUM_KEYS.CUST_RECORD_YEAR%TYPE,
1315 x_create_cum_key_flag IN VARCHAR2,
1316 x_msg_data IN OUT NOCOPY VARCHAR2,
1317 x_record_return_status IN OUT NOCOPY BOOLEAN,
1318 x_cum_key_id IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_KEY_ID%TYPE,
1319 x_cum_start_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_START_DATE%TYPE,
1320 x_shipped_quantity IN OUT NOCOPY OE_ORDER_LINES.SHIPPED_QUANTITY%TYPE,
1321 x_actual_shipment_date IN OUT NOCOPY OE_ORDER_LINES.ACTUAL_SHIPMENT_DATE%TYPE,
1322 x_cum_key_created_flag IN OUT NOCOPY BOOLEAN,
1323 x_cum_qty IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY%TYPE,
1324 x_as_of_date_cum_qty IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY%TYPE,
1325 x_cum_qty_to_be_accumulated IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY_TO_BE_ACCUMULATED%TYPE,
1326 x_cum_qty_after_cutoff IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUM_QTY_AFTER_CUTOFF%TYPE,
1327 x_last_cum_qty_update_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_CUM_QTY_UPDATE_DATE%TYPE,
1328 x_cust_uom_code IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.CUST_UOM_CODE%TYPE,
1329 x_use_ship_incl_rule_flag IN OUT NOCOPY VARCHAR2,
1330 x_shipment_rule_code IN OUT NOCOPY RLM_CUST_SHIPTO_TERMS.CUM_SHIPMENT_RULE_CODE%TYPE,
1331 x_yesterday_time_cutoff IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_UPDATE_DATE%TYPE,
1332 x_last_update_date IN OUT NOCOPY RLM_CUST_ITEM_CUM_KEYS.LAST_UPDATE_DATE%TYPE,
1333 x_as_of_date_time IN OUT NOCOPY OE_ORDER_LINES.ACTUAL_SHIPMENT_DATE%TYPE)
1334
1335 IS
1336 --
1337 x_cum_key_record cum_key_attrib_rec_type;
1338 x_cum_record cum_rec_type;
1339 --
1340 BEGIN
1341 --
1342 IF (l_debug <> -1) THEN
1343 rlm_core_sv.start_debug;
1344 rlm_core_sv.dpush(C_SDEBUG, 'CalculateSupplierCumClient');
1345 END IF;
1346 --
1347 x_cum_key_record.customer_id := x_customer_id;
1348 x_cum_key_record.customer_item_id := x_customer_item_id;
1349 x_cum_key_record.inventory_item_id := x_inventory_item_id;
1350 x_cum_key_record.ship_from_org_id := x_ship_from_org_id;
1351 x_cum_key_record.intrmd_ship_to_address_id := x_intrmd_ship_to_address_id;
1352 x_cum_key_record.ship_to_address_id := x_ship_to_address_id;
1353 x_cum_key_record.bill_to_address_id := x_bill_to_address_id;
1354 x_cum_key_record.purchase_order_number := x_purchase_order_number;
1355 x_cum_key_record.cust_record_year:= x_cust_record_year;
1356 x_cum_key_record.create_cum_key_flag := x_create_cum_key_flag;
1357 x_cum_record.msg_data := x_msg_data;
1358 x_cum_record.record_return_status := x_record_return_status;
1359 x_cum_record.cum_key_id := x_cum_key_id;
1360 x_cum_record.cum_start_date := x_cum_start_date;
1361 x_cum_record.shipped_quantity := x_shipped_quantity;
1362 x_cum_record.actual_shipment_date := x_actual_shipment_date;
1363 x_cum_record.cum_key_created_flag := x_cum_key_created_flag;
1364 x_cum_record.cum_qty:= x_cum_qty;
1365 x_cum_record.as_of_date_cum_qty := x_as_of_date_cum_qty;
1366 x_cum_record.cum_qty_to_be_accumulated := x_cum_qty_to_be_accumulated;
1367 x_cum_record.cum_qty_after_cutoff := x_cum_qty_after_cutoff;
1368 x_cum_record.last_cum_qty_update_date:= x_last_cum_qty_update_date;
1369 x_cum_record.cust_uom_code := x_cust_uom_code;
1370 x_cum_record.use_ship_incl_rule_flag := x_use_ship_incl_rule_flag;
1371 x_cum_record.shipment_rule_code := x_shipment_rule_code;
1372 x_cum_record.yesterday_time_cutoff := x_yesterday_time_cutoff;
1373 x_cum_record.last_update_date := x_last_update_date;
1374 x_cum_record.as_of_date_time := x_as_of_date_time;
1375 --
1376 -- Call calculate cum key api passing cum key records and cum records
1377 RLM_TPA_SV.CalculateSupplierCum (x_cum_key_record => x_cum_key_record,
1378 x_cum_record => x_cum_record);
1379 --
1380 x_msg_data := x_cum_record.msg_data;
1381 x_record_return_status := x_cum_record.record_return_status;
1382 x_cum_key_id := x_cum_record.cum_key_id;
1383 x_cum_start_date := x_cum_record.cum_start_date;
1384 x_shipped_quantity := x_cum_record.shipped_quantity;
1385 x_actual_shipment_date := x_cum_record.actual_shipment_date;
1386 x_cum_key_created_flag := x_cum_record.cum_key_created_flag;
1387 x_cum_qty := x_cum_record.cum_qty;
1388 x_as_of_date_cum_qty := x_cum_record.as_of_date_cum_qty;
1389 x_cum_qty_to_be_accumulated := x_cum_record.cum_qty_to_be_accumulated;
1390 x_cum_qty_after_cutoff := x_cum_record.cum_qty_after_cutoff;
1391 x_last_cum_qty_update_date := x_cum_record.last_cum_qty_update_date;
1392 x_cust_uom_code := x_cum_record.cust_uom_code;
1393 x_use_ship_incl_rule_flag := x_cum_record.use_ship_incl_rule_flag;
1394 x_shipment_rule_code := x_cum_record.shipment_rule_code;
1395 x_yesterday_time_cutoff := x_cum_record.yesterday_time_cutoff;
1396 x_last_update_date := x_cum_record.last_update_date;
1397 x_as_of_date_time := x_cum_record.as_of_date_time;
1398 --
1399 IF (l_debug <> -1) THEN
1400 rlm_core_sv.dpop(C_SDEBUG, 'Completed successfully');
1401 rlm_core_sv.stop_debug;
1402 END IF;
1403 --
1404 EXCEPTION
1405 --
1406 WHEN OTHERS THEN
1407 --
1408 IF (l_debug <> -1) THEN
1409 rlm_core_sv.dpop(C_DEBUG,SQLERRM);
1410 rlm_core_sv.stop_debug;
1411 END IF;
1412 --
1413 END CalculateSupplierCumClient;
1414
1415
1416 /*============================================================================
1417
1418 PROCEDURE NAME: UpdateCumKey
1419
1420 =============================================================================*/
1421
1422 PROCEDURE UpdateCumKey (
1423 x_trip_stop_id IN NUMBER,
1424 x_return_status OUT NOCOPY BOOLEAN)
1425 IS
1426 --
1427 --Local Variables
1428 --
1429 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
1430 v_cum_key_record cum_key_attrib_rec_type;
1431 v_cum_record cum_rec_type;
1432 v_delivery_id NUMBER;
1433 v_header_id NUMBER;
1434 v_line_id NUMBER;
1435 v_schedule_header_id NUMBER;
1436 v_schedule_line_id NUMBER;
1437 v_terms_level VARCHAR2(80) DEFAULT NULL;
1438 v_terms_level2 VARCHAR2(80) DEFAULT NULL;
1439 v_setup_terms_msg VARCHAR2(4000);
1440 v_setup_terms_status BOOLEAN;
1441 v_veh_cus_item_cum_key_id NUMBER;
1442 v_ship_to_site_use_id NUMBER DEFAULT NULL;
1443 v_intrmd_ship_to_site_use_id NUMBER DEFAULT NULL;
1444 v_bill_to_site_use_id NUMBER DEFAULT NULL;
1445 v_level VARCHAR2(80);
1446 counter NUMBER DEFAULT 0;
1447 v_new_ship_count t_new_ship_count;
1448 v_msg_text VARCHAR2(4000);
1449 v_upd_indicator BOOLEAN DEFAULT FALSE;
1450 v_tmp_cust_record_year VARCHAR2(240);
1451 v_tmp_return_message VARCHAR2(4000);
1452 v_tmp_return_status BOOLEAN;
1453 v_oe_header t_oe_header;
1454 v_oe_header_id NUMBER;
1455 v_org_id NUMBER;
1456 hdr_count NUMBER DEFAULT 0;
1457 v_loop_count NUMBER;
1458 k NUMBER;
1459 --
1460 --Used by process_order api
1461 x_oe_api_version NUMBER DEFAULT 1;
1462 l_return_status VARCHAR2(1);
1463 x_msg_count NUMBER;
1464 x_msg_data VARCHAR2(4000);
1465 --
1466
1467 --Used for UOM conversion: Bug 4439006
1468 v_Primary_UOM_Code wsh_delivery_details.requested_quantity_uom%TYPE;
1469 v_shipped_qty NUMBER;
1470
1471 --Exception variables declaration
1472 e_general_error EXCEPTION;
1473 e_no_shipment_line EXCEPTION;
1474 e_null_mandatory EXCEPTION;
1475 e_do_not_update EXCEPTION;
1476 e_cum_start_date EXCEPTION;
1477 e_no_cum_key EXCEPTION;
1478 --
1479 --Cursor to populate t_oe_header
1480 --
1481 CURSOR c_oe_header IS
1482 SELECT DISTINCT oelines.header_id, oelines.org_id
1483 FROM WSH_DELIVERY_LEGS wleg,
1484 WSH_DELIVERY_ASSIGNMENTS_V wdass,
1485 WSH_DELIVERY_DETAILS wdel,
1486 OE_ORDER_LINES_ALL oelines
1487 WHERE wleg.pick_up_stop_id = x_trip_stop_id
1488 AND wdass.delivery_id = wleg.delivery_id
1489 AND wdel.delivery_detail_id = wdass.delivery_detail_id
1490 AND oelines.shipped_quantity IS NOT NULL
1491 AND oelines.line_id = wdel.source_line_id
1492 AND wdel.container_flag = 'N' -- 4301944
1493 AND oelines.header_id = wdel.source_header_id -- 4301944
1494 AND oelines.source_document_type_id = 5;
1495 --
1496 --Cursor to hold oe_order_lines rows of data
1497 --
1498 CURSOR c_oe_lines IS
1499 SELECT oelines.line_id,
1500 wleg.delivery_id,
1501 oelines.header_id,
1502 sum(wdel.shipped_quantity),
1503 oelines.actual_shipment_date,
1504 oelines.ordered_item_id,
1505 oelines.inventory_item_id,
1506 oelines.ship_to_org_id,
1507 oelines.intmed_ship_to_org_id,
1508 oelines.ship_from_org_id,
1509 oelines.cust_po_number,
1510 oelines.industry_attribute1,
1511 oelines.invoice_to_org_id,
1512 oelines.actual_shipment_date,
1513 wdel.requested_quantity_uom, -- Bug 4439006
1514 oelines.order_quantity_uom,
1515 oelines.veh_cus_item_cum_key_id,
1516 oelines.source_document_id,
1517 oelines.source_document_line_id,
1518 oelines.org_id
1519 FROM WSH_DELIVERY_LEGS wleg,
1520 WSH_DELIVERY_ASSIGNMENTS_V wdass,
1521 WSH_DELIVERY_DETAILS wdel,
1522 OE_ORDER_LINES_ALL oelines
1523 WHERE wleg.pick_up_stop_id = x_trip_stop_id
1524 AND wdass.delivery_id = wleg.delivery_id
1525 AND wdel.delivery_detail_id = wdass.delivery_detail_id
1526 AND oelines.header_id+0 = v_oe_header_id --Bugfix 14827544
1527 AND oelines.shipped_quantity IS NOT NULL
1528 AND oelines.line_id = wdel.source_line_id
1529 AND wdel.container_flag = 'N' -- 4301944
1530 AND oelines.header_id = wdel.source_header_id -- 4301944
1531 AND oelines.source_document_type_id = 5
1532 group by oelines.line_id,
1533 wleg.delivery_id,
1534 oelines.header_id,
1535 oelines.actual_shipment_date,
1536 oelines.ordered_item_id,
1537 oelines.inventory_item_id,
1538 oelines.ship_to_org_id,
1539 oelines.intmed_ship_to_org_id,
1540 oelines.ship_from_org_id,
1541 oelines.cust_po_number,
1542 oelines.industry_attribute1,
1543 oelines.invoice_to_org_id,
1544 oelines.actual_shipment_date,
1545 wdel.requested_quantity_uom, -- Bug 4439006
1546 oelines.order_quantity_uom,
1547 oelines.veh_cus_item_cum_key_id,
1548 oelines.source_document_id,
1549 oelines.source_document_line_id,
1550 oeLines.org_id;
1551 --
1552 l_oe_line_tbl_out oe_order_pub.line_tbl_type;
1553 --
1554 BEGIN
1555 --
1556 IF (l_debug <> -1) THEN
1557 rlm_core_sv.start_debug;
1558 rlm_core_sv.dpush(C_SDEBUG, 'UpdateCumKey');
1559 END IF;
1560 --
1561 savepoint updatecumkey; --bug 3719088
1562
1563 -- Check for mandatory input
1564 --
1565 IF x_trip_stop_id IS NULL THEN
1566 --
1567 RAISE e_null_mandatory;
1568 --
1569 END IF;
1570 --
1571 -- Find out how many oe headers assigned to the trip stop
1572 --
1573 OPEN c_oe_header;
1574 --
1575 LOOP
1576 --
1577 FETCH c_oe_header INTO v_oe_header(hdr_count).header_id, v_oe_header(hdr_count).org_id;
1578 --
1579 EXIT WHEN c_oe_header%NOTFOUND;
1580 --
1581 hdr_count := hdr_count + 1;
1582 --
1583 IF (l_debug <> -1) THEN
1584 rlm_core_sv.dlog(C_DEBUG, 'Inside c_oe_header Loop');
1585 END IF;
1586 --
1587 END LOOP;
1588 --
1589 CLOSE c_oe_header;
1590 --
1591 IF (l_debug <> -1) THEN
1592 rlm_core_sv.dlog(C_DEBUG, 'Number of oe headers to update: ', hdr_count);
1593 END IF;
1594 --
1595 --
1596 IF hdr_count = 0 THEN
1597 --
1598 RAISE e_no_shipment_line;
1599 --
1600 END IF;
1601 --
1602 ----------------------------------------------------------+
1603 FOR v_loop_count IN 0 .. (hdr_count-1) LOOP
1604 --
1605 -- LOOP to fetch distinct header ids
1606 --
1607 IF (l_debug <> -1) THEN
1608 rlm_core_sv.dlog(C_DEBUG, 'v_loop_count', v_loop_count);
1609 rlm_core_sv.dlog(C_DEBUG, 'Inside v_loop_count Loop');
1610 END IF;
1611 --
1612 --Reset counter
1613 counter := 0;
1614 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
1615 --
1616 --Get the header_id for each loop iteration
1617 --
1618 v_oe_header_id := v_oe_header(v_loop_count).header_id;
1619 v_org_id := v_oe_header(v_loop_count).org_id;
1620 --
1621 IF (l_debug <> -1) THEN
1622 rlm_core_sv.dlog(C_DEBUG, 'v_oe_header_id', v_oe_header_id);
1623 rlm_core_sv.dlog(C_DEBUG, 'v_org_id', v_org_id);
1624 END IF;
1625 --
1626 MO_GLOBAL.set_policy_context(p_access_mode => 'S',
1627 p_org_id => v_org_id);
1628 --
1629 /* For the supplied delivery detail id, find all shipment lines and
1630 attributes needed to calculate cum key */
1631 --
1632 ---------------+
1633 OPEN c_oe_lines;
1634 --
1635 LOOP --LOOP to fetch OE Order Lines
1636 --DEBUGGING
1637 --
1638 IF (l_debug <> -1) THEN
1639 rlm_core_sv.dlog(C_DEBUG, 'Inside c_oe_lines Loop');
1640 END IF;
1641 --
1642 v_msg_text := NULL;
1643 --
1644 -- Reset loop variables so as to not retain values from prior fetch
1645 --
1646 v_line_id := NULL;
1647 v_delivery_id := NULL;
1648 v_header_id := NULL;
1649 v_cum_record.shipped_quantity := NULL;
1650 v_cum_record.actual_shipment_date := NULL;
1651 v_cum_key_record.customer_item_id := NULL;
1652 v_cum_key_record.inventory_item_id := NULL;
1653 v_ship_to_site_use_id := NULL;
1654 v_intrmd_ship_to_site_use_id := NULL;
1655 v_cum_key_record.ship_from_org_id := NULL;
1656 v_cum_key_record.purchase_order_number := NULL;
1657 v_cum_key_record.cust_record_year := NULL;
1658 v_bill_to_site_use_id := NULL;
1659 v_cum_record.as_of_date_time := NULL;
1660 v_Primary_UOM_Code := NULL; -- Bug 4439006
1661 v_cum_record.cust_uom_code := NULL;
1662 v_veh_cus_item_cum_key_id := NULL;
1663 v_schedule_header_id := NULL;
1664 v_schedule_line_id := NULL;
1665 v_org_id := NULL;
1666 --
1667 FETCH c_oe_lines INTO v_line_id,
1668 v_delivery_id,
1669 v_header_id,
1670 v_cum_record.shipped_quantity,
1671 v_cum_record.actual_shipment_date,
1672 v_cum_key_record.customer_item_id,
1673 v_cum_key_record.inventory_item_id,
1674 v_ship_to_site_use_id,
1675 v_intrmd_ship_to_site_use_id,
1676 v_cum_key_record.ship_from_org_id,
1677 v_cum_key_record.purchase_order_number,
1678 v_cum_key_record.cust_record_year,
1679 v_bill_to_site_use_id,
1680 v_cum_record.as_of_date_time,
1681 v_Primary_UOM_Code, -- Bug 4439006
1682 v_cum_record.cust_uom_code,
1683 v_veh_cus_item_cum_key_id,
1684 v_schedule_header_id,
1685 v_schedule_line_id,
1686 v_org_id;
1687 --
1688 EXIT WHEN c_oe_lines%NOTFOUND;
1689 --
1690 v_level := 'SHIP_TO_ADDRESS_ID';
1691 --
1692 -- Find the ship_to_address_id
1693 --
1694 IF v_ship_to_site_use_id IS NOT NULL THEN
1695 --
1696 -- Following query is changed as per TCA obsolescence project.
1697 SELECT CUST_ACCT_SITE_ID
1698 INTO v_cum_key_record.ship_to_address_id
1699 FROM HZ_CUST_SITE_USES
1700 WHERE site_use_id = v_ship_to_site_use_id
1701 AND site_use_code = 'SHIP_TO';
1702 --
1703 ELSE
1704 --
1705 v_cum_key_record.ship_to_address_id := NULL;
1706 --
1707 END IF;
1708 --
1709 v_level := 'INTRMD_SHIP_TO_ADDRESS_ID';
1710 --
1711 -- Find the intrmd_ship_to_address_id
1712 --
1713 IF v_intrmd_ship_to_site_use_id IS NOT NULL THEN
1714 --
1715 -- Following query is changed as per TCA obsolescence project.
1716 SELECT CUST_ACCT_SITE_ID
1717 INTO v_cum_key_record.intrmd_ship_to_address_id
1718 FROM HZ_CUST_SITE_USES
1719 WHERE site_use_id = v_intrmd_ship_to_site_use_id
1720 AND site_use_code = 'SHIP_TO';
1721 --
1722 ELSE
1723 --
1724 v_cum_key_record.intrmd_ship_to_address_id := NULL;
1725 --
1726 END IF;
1727 --
1728 v_level := 'BILL_TO_ADDRESS_ID';
1729 --
1730 -- Find the bill_to_address_id
1731 --
1732 IF v_bill_to_site_use_id IS NOT NULL THEN
1733 --
1734 -- Following query is changed as per TCA obsolescence project.
1735 SELECT CUST_ACCT_SITE_ID
1736 INTO v_cum_key_record.bill_to_address_id
1737 FROM HZ_CUST_SITE_USES
1738 WHERE site_use_id = v_bill_to_site_use_id
1739 AND site_use_code = 'BILL_TO';
1740 --
1741 ELSE
1742 --
1743 v_cum_key_record.bill_to_address_id := NULL;
1744 --
1745 END IF;
1746 --
1747 --DEBUGGING - INPUT Values
1748 IF (l_debug <> -1) THEN
1749 rlm_core_sv.dlog(C_DEBUG, '');
1750 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE INPUT VALUES:');
1751 rlm_core_sv.dlog(C_DEBUG, '--------------------------');
1752 rlm_core_sv.dlog(C_DEBUG, 'x_trip_stop_id', x_trip_stop_id);
1753 rlm_core_sv.dlog(C_DEBUG, 'v_delivery_id', v_delivery_id);
1754 rlm_core_sv.dlog(C_DEBUG, 'v_line_id', v_line_id);
1755 rlm_core_sv.dlog(C_DEBUG, 'ship_to_address_id', v_cum_key_record.ship_to_address_id);
1756 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id', v_cum_key_record.ship_from_org_id);
1757 rlm_core_sv.dlog(C_DEBUG, 'bill_to_address_id', v_cum_key_record.bill_to_address_id);
1758 rlm_core_sv.dlog(C_DEBUG, 'intrmd_ship_to_address_id', v_cum_key_record.intrmd_ship_to_address_id);
1759 rlm_core_sv.dlog(C_DEBUG, 'customer_item_id', v_cum_key_record.customer_item_id);
1760 rlm_core_sv.dlog(C_DEBUG, 'purchase_order_number', v_cum_key_record.purchase_order_number);
1761 rlm_core_sv.dlog(C_DEBUG, 'cust_record_year', v_cum_key_record.cust_record_year);
1762 rlm_core_sv.dlog(C_DEBUG, 'create_cum_key', v_cum_key_record.create_cum_key_flag);
1763 rlm_core_sv.dlog(C_DEBUG, 'actual_shipment_date', v_cum_record.actual_shipment_date);
1764 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', v_cum_record.shipped_quantity);
1765 END IF;
1766 --
1767 -- User friendly message
1768 -- TODO: Make the message more user friendly
1769 --
1770 rlm_message_sv.get_msg_text(
1771 x_message_name => 'RLM_TRIP_DEL_INFO',
1772 x_text => v_msg_text,
1773 x_token1 => 'TRIP_STOP',
1774 x_value1 => x_trip_stop_id,
1775 x_token2 => 'DELIVERY',
1776 x_value2 => v_delivery_id,
1777 x_token3 => 'OE_LINE',
1778 x_value3 => v_line_id,
1779 x_token4 => 'SHIP_DATE',
1780 x_value4 => v_cum_record.actual_shipment_date,
1781 x_token5 => 'SHIP_QTY',
1782 x_value5 => v_cum_record.shipped_quantity);
1783 --
1784 fnd_file.put_line(fnd_file.log, v_msg_text);
1785 --
1786 --Find customer_id, as it is a required input parameter for rlm_setup_terms
1787 --
1788 v_level := 'CUSTOMER_ID';
1789 --
1790 -- Following query is changed as per TCA obsolescence project.
1791 /* SELECT DISTINCT ACCT_SITE.CUST_ACCOUNT_ID
1792 INTO v_cum_key_record.customer_id
1793 FROM HZ_CUST_ACCT_SITES ACCT_SITE
1794 WHERE ACCT_SITE.CUST_ACCT_SITE_ID = v_cum_key_record.ship_to_address_id;
1795 */
1796 -- CR changes
1797 SELECT DISTINCT sold_to_org_id
1798 INTO v_cum_key_record.customer_id
1799 FROM oe_order_headers_all oeh
1800 WHERE oeh.header_id = v_oe_header_id;
1801
1802 --
1803 --DEBUGGING
1804 --
1805 IF (l_debug <> -1) THEN
1806 rlm_core_sv.dlog(C_DEBUG, 'customer_id', v_cum_key_record.customer_id);
1807 END IF;
1808 --
1809 --Get the CUM_CONTROL_CODE defined at CUSTOMER or ADDRESS level
1810 --
1811 RLM_TPA_SV.get_setup_terms(
1812 x_ship_from_org_id => v_cum_key_record.ship_from_org_id,
1813 x_customer_id => v_cum_key_record.customer_id,
1814 x_ship_to_address_id => v_cum_key_record.ship_to_address_id,
1815 x_customer_item_id => v_cum_key_record.customer_item_id,
1816 x_terms_definition_level => v_terms_level,
1817 x_terms_rec => v_rlm_setup_terms_record,
1818 x_return_message => v_setup_terms_msg,
1819 x_return_status => v_setup_terms_status);
1820 --
1821 --DEBUGGING
1822 IF (l_debug <> -1) THEN
1823 rlm_core_sv.dlog(C_DEBUG, 'Setup terms x_return_status', v_setup_terms_status);
1824 rlm_core_sv.dlog(C_DEBUG, 'Terms level', v_terms_level);
1825 rlm_core_sv.dlog(C_DEBUG, 'cum_control_code', v_rlm_setup_terms_record.cum_control_code);
1826 rlm_core_sv.dlog(C_DEBUG, 'ship_to_address_id', v_cum_key_record.ship_to_address_id);
1827 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id', v_cum_key_record.ship_from_org_id);
1828 rlm_core_sv.dlog(C_DEBUG, 'customer_id', v_cum_key_record.customer_id);
1829 rlm_core_sv.dlog(C_DEBUG, 'customer_item_id', v_cum_key_record.customer_item_id);
1830 rlm_core_sv.dlog(C_DEBUG, 'calc_cum_flag', v_rlm_setup_terms_record.calc_cum_flag);
1831 END IF;
1832 --
1833 -- User friendly message
1834 --
1835 rlm_message_sv.get_msg_text(
1836 x_message_name => 'RLM_TRIP_CTRLCD',
1837 x_text => v_msg_text,
1838 x_token1 => 'CUM_CONTROL_CODE',
1839 x_value1 => v_rlm_setup_terms_record.cum_control_code);
1840 --
1841 fnd_file.put_line(fnd_file.log, v_msg_text);
1842 --
1843 --Continue only if cum_control_code is found and not set to NO_CUM
1844 --
1845 IF v_setup_terms_status = TRUE AND
1846 v_rlm_setup_terms_record.cum_control_code <> 'NO_CUM' THEN
1847 --
1848 IF (v_terms_level = 'CUSTOMER_ITEM' AND
1849 v_rlm_setup_terms_record.calc_cum_flag = 'Y')
1850 OR v_terms_level <> 'CUSTOMER_ITEM' THEN
1851 --
1852 --DEBUGGING
1853 --
1854 IF (l_debug <> -1) THEN
1855 rlm_core_sv.dlog(C_DEBUG, 'Setup terms x_return_status at item level', v_setup_terms_status);
1856 END IF;
1857 --
1858 --Find the cum start date
1859 --
1860 GetCumStartDate(i_schedule_header_id => v_schedule_header_id,
1861 i_schedule_line_id => v_schedule_line_id,
1862 o_cum_start_date => v_cum_key_record.cum_start_date,
1863 o_cust_record_year => v_tmp_cust_record_year,
1864 o_return_message => v_tmp_return_message,
1865 o_return_status => v_tmp_return_status);
1866 --
1867 IF v_tmp_return_status = FALSE THEN
1868 --
1869 RAISE e_cum_start_date;
1870 --
1871 END IF;
1872 --
1873 IF (l_debug <> -1) THEN
1874 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', v_cum_key_record.cum_start_date);
1875 END IF;
1876 --
1877 /* Call calculate_cum_key procedure to search for the cum
1878 key id, and the cum quantity stored in the database as
1879 of the time of shipment */
1880 --
1881 RLM_TPA_SV.CalculateCumKey(
1882 x_cum_key_record => v_cum_key_record,
1883 x_cum_record => v_cum_record);
1884 --
1885 IF v_cum_record.record_return_status <> FALSE THEN
1886 --
1887 -- User friendly message
1888 --
1889 rlm_message_sv.get_msg_text(
1890 x_message_name => 'RLM_TRIP_CUM_KEY_ID',
1891 x_text => v_msg_text,
1892 x_token1 => 'CUM_KEY_ID',
1893 x_value1 => v_cum_record.cum_key_id);
1894 --
1895 fnd_file.put_line(fnd_file.log, v_msg_text);
1896 --
1897 ELSE
1898 --
1899 RAISE e_general_error;
1900 --
1901 END IF;
1902
1903 --
1904 IF(v_cum_record.cum_key_id IS NULL) THEN
1905 --
1906 raise e_no_cum_key;
1907 --
1908 END IF;
1909
1910 --Check if this delivery line has actually been updated
1911 --
1912 /* Initialize v_new_ship_count. This variable is used to keep track of the
1913 shipment lines that have the same cum_key_id and
1914 shipment_rule_code = 'AS_OF_PRIOR' */
1915 ------------------------------------------------------------+
1916 BEGIN
1917 --
1918 SELECT v_new_ship_count(v_cum_record.cum_key_id) + 1
1919 INTO v_new_ship_count(v_cum_record.cum_key_id)
1920 FROM DUAL;
1921 --
1922 EXCEPTION
1923 --
1924 WHEN NO_DATA_FOUND THEN
1925 --
1926 v_new_ship_count(v_cum_record.cum_key_id) := 0;
1927 --
1928 SELECT v_new_ship_count(v_cum_record.cum_key_id) + 1
1929 INTO v_new_ship_count(v_cum_record.cum_key_id)
1930 FROM DUAL;
1931 --
1932 END;
1933 ------------------------------------------------------------+
1934 --
1935 IF NVL(v_veh_cus_item_cum_key_id,0) <> v_cum_record.cum_key_id THEN
1936 --
1937 /* Need to set this to 'Y' since we're going to include the
1938 current shipment into the supplier CUM calculation */
1939 v_cum_record.use_ship_incl_rule_flag := 'Y';
1940 v_cum_record.as_of_date_time := NULL;
1941
1942 /* Bug 4439006: Start
1943 While ship confirming, shipped qty is specified in Primary Uom,
1944 where as the Uom attached with the CUM Key can be different.
1945 The Cum key should be updated with qty specified in Cum key uom. */
1946 --
1947 IF (l_debug <> -1) THEN
1948 rlm_core_sv.dlog(C_DEBUG, 'inventory_item_id', v_cum_key_record.inventory_item_id);
1949 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id', v_cum_key_record.ship_from_org_id);
1950 END IF;
1951 --
1952 v_shipped_qty := v_cum_record.shipped_quantity;
1953 --
1954 IF (v_cum_record.cust_uom_code <> v_Primary_UOM_Code) THEN
1955 RLM_FORECAST_SV.Convert_UOM (v_Primary_UOM_Code,
1956 v_cum_record.cust_uom_code,
1957 v_cum_record.shipped_quantity,
1958 v_cum_key_record.inventory_item_id,
1959 v_cum_key_record.ship_from_org_id);
1960 --
1961 IF (l_debug <> -1) THEN
1962 rlm_core_sv.dlog(C_DEBUG, 'Primary Uom', v_Primary_UOM_Code);
1963 rlm_core_sv.dlog(C_DEBUG, 'Cum Key Uom', v_cum_record.cust_uom_code);
1964 rlm_core_sv.dlog(C_DEBUG, 'Shipd Qty.-Before Conversion to CUM Uom', v_shipped_qty);
1965 rlm_core_sv.dlog(C_DEBUG, 'Shipd Qty.-After Conversion -CUM Uom', v_cum_record.shipped_quantity);
1966 rlm_core_sv.dlog(C_DEBUG, 'Primary Uom and Cum Key Uom differ: Calling Convert_UOM');
1967 END IF;
1968 --
1969 END IF;
1970 /* Bug 4439006: End */
1971 --
1972 /* Call calculate_supplier_cum procedure to calculate the
1973 total supplier cum by summing the current line shipped
1974 quantity and the stored quantity */
1975 --
1976 RLM_TPA_SV.CalculateSupplierCum(
1977 x_new_ship_count => v_new_ship_count,
1978 x_cum_key_record => v_cum_key_record,
1979 x_cum_record => v_cum_record);
1980 --
1981 -- Bug 4439006
1982 v_cum_record.shipped_quantity := v_shipped_qty;
1983
1984 --DEBUGGING - OUTPUT Values
1985 IF (l_debug <> -1) THEN
1986 rlm_core_sv.dlog(C_DEBUG, '');
1987 rlm_core_sv.dlog(C_DEBUG, 'HERE ARE THE OUTPUT VALUES:');
1988 rlm_core_sv.dlog(C_DEBUG, '---------------------------');
1989 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', v_cum_record.cum_key_id);
1990 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', v_cum_record.cum_start_date);
1991 rlm_core_sv.dlog(C_DEBUG, 'shipped_quantity', v_cum_record.shipped_quantity);
1992 rlm_core_sv.dlog(C_DEBUG, 'actual_shipment_date', v_cum_record.actual_shipment_date);
1993 rlm_core_sv.dlog(C_DEBUG, 'cum_key_created_flag', v_cum_record.cum_key_created_flag);
1994 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', v_cum_record.cum_qty);
1995 rlm_core_sv.dlog(C_DEBUG, 'as_of_date_cum_qty', v_cum_record.as_of_date_cum_qty);
1996 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_to_be_accumulated', v_cum_record.cum_qty_to_be_accumulated);
1997 rlm_core_sv.dlog(C_DEBUG, 'cum_qty_after_cutoff', v_cum_record.cum_qty_after_cutoff);
1998 rlm_core_sv.dlog(C_DEBUG, 'last_cum_qty_update_date', v_cum_record.last_cum_qty_update_date);
1999 rlm_core_sv.dlog(C_DEBUG, 'cust_uom_code', v_cum_record.cust_uom_code);
2000 rlm_core_sv.dlog(C_DEBUG, 'Primary_uom_code', v_Primary_UOM_Code);
2001 rlm_core_sv.dlog(C_DEBUG, 'use_ship_incl_rule_flag', v_cum_record.use_ship_incl_rule_flag);
2002 rlm_core_sv.dlog(C_DEBUG, 'shipment_rule_code', v_cum_record.shipment_rule_code);
2003 rlm_core_sv.dlog(C_DEBUG, 'record_return_status', v_cum_record.record_return_status);
2004 END IF;
2005 --
2006 --Bug 3688778 jckwok : Need to Lock the Cum Key
2007 --
2008 IF (LockCumKey(v_cum_record.cum_key_id) AND
2009 v_cum_record.record_return_status = TRUE) THEN
2010
2011 /* Update the CUM related quantity in
2012 RLM_CUS_ITEM_CUM_KEY_ALL table */
2013 --
2014 UPDATE RLM_CUST_ITEM_CUM_KEYS_ALL
2015 SET cum_qty = v_cum_record.cum_qty,
2016 cum_qty_to_be_accumulated = v_cum_record.cum_qty_to_be_accumulated,
2017 cum_qty_after_cutoff = v_cum_record.cum_qty_after_cutoff,
2018 --last_cum_qty_update_date = sysdate, --Bugfix 10053830
2019 last_cum_qty_update_date = nvl(rlm_dp_sv.g_dsp_start_time,sysdate), --Bugfix 10053830
2020 last_update_login = fnd_global.login_id,
2021 last_update_date = sysdate,
2022 last_updated_by = fnd_global.user_id
2023 WHERE cum_key_id = v_cum_record.cum_key_id;
2024 --
2025 v_upd_indicator := TRUE;
2026 --
2027 /* Populate g_oe_line_tbl data structure with the
2028 calculated cum_key_id so it can be used when
2029 oe_order_grp.process order api to update
2030 oe_order_lines table */
2031 --
2032 counter := counter + 1;
2033 -- Bug# 1466909
2034 g_oe_line_tbl(counter) := OE_Order_PUB.G_MISS_LINE_REC;
2035 g_oe_line_tbl(counter).header_id := v_header_id;
2036 g_oe_line_tbl(counter).line_id := v_line_id;
2037 g_oe_line_tbl(counter).operation := oe_globals.G_OPR_UPDATE;
2038 g_oe_line_tbl(counter).veh_cus_item_cum_key_id := v_cum_record.cum_key_id;
2039 g_oe_line_tbl(counter).industry_attribute7 := TO_CHAR(v_cum_record.cum_qty);
2040 g_oe_line_tbl(counter).industry_attribute8 := v_cum_record.cust_uom_code;
2041 g_oe_line_tbl(counter).org_id := v_org_id;
2042 --
2043 --DEBUGGING
2044 IF (l_debug <> -1) THEN
2045 rlm_core_sv.dlog(C_DEBUG, 'counter', counter);
2046 rlm_core_sv.dlog(C_DEBUG, 'g_oe_line_tbl(counter).header_id',
2047 g_oe_line_tbl(counter).header_id);
2048 rlm_core_sv.dlog(C_DEBUG, 'g_oe_line_tbl(counter).line_id',
2049 g_oe_line_tbl(counter).line_id);
2050 rlm_core_sv.dlog(C_DEBUG,'g_oe_line_tbl(counter).veh_cus_item_cum_key_id',
2051 g_oe_line_tbl(counter).veh_cus_item_cum_key_id);
2052 rlm_core_sv.dlog(C_DEBUG, 'g_oe_line_tbl(counter).industry_attribute7',
2053 g_oe_line_tbl(counter).industry_attribute7);
2054 rlm_core_sv.dlog(C_DEBUG, 'g_oe_line_tbl(counter).industry_attribute8',
2055 g_oe_line_tbl(counter).industry_attribute8);
2056 rlm_core_sv.dlog(C_DEBUG, 'g_oe_line_tbl(counter).org_id',
2057 g_oe_line_tbl(counter).org_id);
2058 END IF;
2059 --
2060 ELSE
2061 --
2062 RAISE e_general_error;
2063 --
2064 END IF; -- record_return_status = TRUE
2065 --
2066 ELSE
2067 --
2068 x_return_status := TRUE;
2069 --
2070 v_msg_text := 'RLM_TRIP_NO_UPDATE';
2071 --
2072 IF (l_debug <> -1) THEN
2073 rlm_core_sv.dlog(C_SDEBUG, v_msg_text);
2074 END IF;
2075 --
2076 -- User friendly message
2077 --
2078 rlm_message_sv.get_msg_text(
2079 x_message_name => 'RLM_TRIP_NO_UPDATE',
2080 x_text => v_msg_text);
2081 --
2082 fnd_file.put_line(fnd_file.log, v_msg_text);
2083 --
2084 -- Pls do not remove the line below
2085 --
2086 v_msg_text := 'RLM_TRIP_NO_UPDATE';
2087
2088 END IF; -- cum key id
2089 --
2090 ELSE
2091 --
2092 x_return_status := TRUE;
2093 --
2094 END IF; -- v_calc_cum_flag = 'Y'
2095 --
2096 ELSE
2097 --
2098 x_return_status := TRUE;
2099 --
2100 -- RLM_TRIP_NO_SETUP
2101 --
2102 IF (l_debug <> -1) THEN
2103 rlm_core_sv.dlog(C_SDEBUG, 'RLM_TRIP_NO_SETUP');
2104 END IF;
2105 --
2106 -- User friendly message
2107 --
2108 rlm_message_sv.get_msg_text(
2109 x_message_name => 'RLM_TRIP_NO_SETUP',
2110 x_text => v_msg_text);
2111 --
2112 fnd_file.put_line(fnd_file.log, v_msg_text);
2113 --
2114 END IF; -- v_cum_control_code <> 'NO_CUM'
2115 --
2116 END LOOP; -- END LOOP to fetch OE Order Lines
2117 --
2118 CLOSE c_oe_lines;
2119 ----------------+
2120 --
2121 IF (l_debug <> -1) THEN
2122 rlm_core_sv.dlog(C_DEBUG, 'v_msg_text', v_msg_text);
2123 rlm_core_sv.dlog(C_DEBUG, 'v_upd_indicator', v_upd_indicator);
2124 END IF;
2125 --
2126 IF v_upd_indicator = TRUE THEN
2127 --
2128 -----------------------------------------------------------------------+
2129 BEGIN
2130 /* Call OE_Order_GRP.Process_Order procedure to update OE_ORDER_LINES
2131 table by passing the g_oe_line_tbl structure that has been prepared
2132 inside the loop above */
2133 --
2134 --Pass only g_oe_line_tbl. The rest uses default values
2135 --
2136 OE_Order_GRP.Process_order(
2137 p_api_version_number => x_oe_api_version,
2138 p_init_msg_list => FND_API.G_TRUE,
2139 p_return_values => FND_API.G_FALSE,
2140 --p_commit => FND_API.G_FALSE,
2141 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
2142 x_return_status => l_return_status,
2143 x_msg_count => x_msg_count,
2144 x_msg_data => x_msg_data,
2145 ------------------------------------------
2146 p_line_tbl => g_oe_line_tbl,
2147 ------------------------------------------
2148 x_header_rec => g_oe_header_out_rec,
2149 x_header_val_rec => g_oe_header_val_out_rec,
2150 x_Header_Adj_tbl => g_oe_Header_Adj_out_tbl,
2151 x_Header_Adj_val_tbl => g_oe_Header_Adj_val_out_tbl,
2152 x_Header_price_Att_tbl => g_Header_price_Att_out_tbl,
2153 x_Header_Adj_Att_tbl => g_Header_Adj_Att_out_tbl,
2154 x_Header_Adj_Assoc_tbl => g_Header_Adj_Assoc_out_tbl,
2155 x_Header_Scredit_tbl => g_oe_Header_Scredit_out_tbl,
2156 x_Header_Scredit_val_tbl => g_oe_Hdr_Scdt_val_out_tbl,
2157 x_line_tbl => l_oe_line_tbl_out,
2158 x_line_val_tbl => g_oe_line_val_out_tbl,
2159 x_Line_Adj_tbl => g_oe_line_Adj_out_tbl,
2160 x_Line_Adj_val_tbl => g_oe_line_Adj_val_out_tbl,
2161 x_Line_price_Att_tbl => g_Line_price_Att_out_tbl,
2162 x_Line_Adj_Att_tbl => g_Line_Adj_Att_out_tbl,
2163 x_Line_Adj_Assoc_tbl => g_Line_Adj_Assoc_out_tbl,
2164 x_Line_Scredit_tbl => g_oe_line_scredit_out_tbl,
2165 x_Line_Scredit_val_tbl => g_oe_line_scredit_val_out_tbl,
2166 x_Lot_Serial_tbl => g_oe_lot_serial_out_tbl,
2167 x_Lot_Serial_val_tbl => g_oe_lot_serial_val_out_tbl,
2168 x_Action_Request_tbl => g_oe_Action_Request_out_Tbl);
2169 --
2170 --Handle the exceptions caused by the OE call
2171 --
2172 IF (l_debug <> -1) THEN
2173 rlm_core_sv.dlog(C_SDEBUG, 'Input tbl count', g_oe_line_tbl.LAST);
2174 rlm_core_sv.dlog(C_SDEBUG, 'Output tbl count', l_oe_line_tbl_out.LAST);
2175 END IF;
2176 --
2177 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
2178 --
2179 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2180 --
2181 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
2182 --
2183 RAISE FND_API.G_EXC_ERROR;
2184 --
2185 ELSE
2186 --
2187 x_return_status := TRUE;
2188 --
2189 --DEBUGGING
2190 IF (l_debug <> -1) THEN
2191 rlm_core_sv.dlog(C_SDEBUG,'l_return_status', l_return_status);
2192 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2193 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_count', x_msg_count);
2194 rlm_core_sv.dlog(C_SDEBUG, 'Process Order is completed succesfully');
2195 END IF;
2196 --
2197 END IF;
2198 --
2199 EXCEPTION
2200 --
2201 WHEN FND_API.G_EXC_ERROR THEN
2202 --
2203 --Get message count and data
2204 --
2205 OE_MSG_PUB.Count_And_Get(
2206 p_count => x_msg_count,
2207 p_data => x_msg_data);
2208 --
2209 x_return_status := FALSE;
2210 --
2211 ROLLBACK to updatecumkey;
2212 --
2213 -- DEBUGGING
2214 IF (l_debug <> -1) THEN
2215 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_ERROR');
2216 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status', l_return_status);
2217 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2218 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_count', x_msg_count);
2219 rlm_core_sv.dlog(C_SDEBUG, 'Main x_msg_data', x_msg_data);
2220 END IF;
2221 --
2222 IF x_msg_count > 0 THEN
2223 --
2224 FOR k in 1 .. x_msg_count LOOP
2225 --
2226 x_msg_data := oe_msg_pub.get( p_msg_index => k,
2227 p_encoded => 'F');
2228 --
2229 fnd_file.put_line(fnd_file.log, x_msg_data);
2230 --
2231 IF (l_debug <> -1) THEN
2232 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2233 END IF;
2234 --
2235 END LOOP;
2236 --
2237 END IF;
2238 --
2239 IF (l_debug <> -1) THEN
2240 rlm_core_sv.dpop(C_SDEBUG, 'Process Order Error');
2241 END IF;
2242 --
2243 --
2244 -- User friendly message
2245 --
2246 rlm_message_sv.get_msg_text(
2247 x_message_name => 'RLM_CUM_PROCESS_ORDER',
2248 x_text => v_msg_text);
2249 --
2250 fnd_file.put_line(fnd_file.log, v_msg_text);
2251 --
2252 IF (l_debug <> -1) THEN
2253 rlm_core_sv.stop_debug;
2254 END IF;
2255 --
2256 RAISE e_general_error;
2257 --
2258 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2259 --
2260 -- Get message count and data
2261 --
2262 OE_MSG_PUB.Count_And_Get(
2263 p_count => x_msg_count,
2264 p_data => x_msg_data);
2265 --
2266 v_msg_text := x_msg_data;
2267 --
2268 x_return_status := FALSE;
2269 --
2270 ROLLBACK to updatecumkey;
2271 --
2272 -- DEBUGGING
2273 IF (l_debug <> -1) THEN
2274 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_UNEXPECTED_ERROR');
2275 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2276 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status', l_return_status);
2277 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2278 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_count', x_msg_count);
2279 rlm_core_sv.dlog(C_SDEBUG, 'Main x_msg_data', x_msg_data);
2280 END IF;
2281 --
2282 IF x_msg_count > 0 THEN
2283 --
2284 FOR k in 1 .. x_msg_count LOOP
2285 --
2286 x_msg_data := oe_msg_pub.get( p_msg_index => k,
2287 p_encoded => 'F');
2288 --
2289 fnd_file.put_line(fnd_file.log, x_msg_data);
2290 --
2291 IF (l_debug <> -1) THEN
2292 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2293 END IF;
2294 --
2295 END LOOP;
2296 --
2297 END IF;
2298 --
2299 IF (l_debug <> -1) THEN
2300 rlm_core_sv.dpop(C_SDEBUG, 'Process Order Error');
2301 END IF;
2302 --
2303 --
2304 -- User friendly message
2305 --
2306 rlm_message_sv.get_msg_text(
2307 x_message_name => 'RLM_CUM_PROCESS_ORDER',
2308 x_text => v_msg_text);
2309 --
2310 fnd_file.put_line(fnd_file.log, v_msg_text);
2311 --
2312 IF (l_debug <> -1) THEN
2313 rlm_core_sv.stop_debug;
2314 END IF;
2315 --
2316 RAISE e_general_error;
2317 --
2318 WHEN OTHERS THEN
2319 --
2320 -- Get message count and data
2321 --
2322 OE_MSG_PUB.Count_And_Get(
2323 p_count => x_msg_count,
2324 p_data => x_msg_data);
2325 --
2326 v_msg_text := x_msg_data;
2327 --
2328 x_return_status := FALSE;
2329 --
2330 ROLLBACK to updatecumkey;
2331 --
2332 -- DEBUGGING
2333 IF (l_debug <> -1) THEN
2334 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_UNEXPECTED_ERROR');
2335 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2336 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status', l_return_status);
2337 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2338 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_count', x_msg_count);
2339 END IF;
2340 --
2341 FOR k in 1 .. x_msg_count LOOP
2342 --
2343 x_msg_data := oe_msg_pub.get( p_msg_index => k,
2344 p_encoded => 'F');
2345 --
2346 fnd_file.put_line(fnd_file.log, x_msg_data);
2347 --
2348 IF (l_debug <> -1) THEN
2349 rlm_core_sv.dlog(C_SDEBUG, 'x_msg_data', x_msg_data);
2350 END IF;
2351 --
2352 END LOOP;
2353 --
2354 IF (l_debug <> -1) THEN
2355 rlm_core_sv.dpop(C_SDEBUG, 'Process Order Error. When Others');
2356 END IF;
2357 --
2358 --
2359 -- User friendly message
2360 --
2361 rlm_message_sv.get_msg_text(
2362 x_message_name => 'RLM_CUM_PROCESS_ORDER',
2363 x_text => v_msg_text);
2364 --
2365 fnd_file.put_line(fnd_file.log, v_msg_text);
2366 --
2367 IF (l_debug <> -1) THEN
2368 rlm_core_sv.stop_debug;
2369 END IF;
2370 --
2371 END;
2372 --------------------------------------------------------------------------------+
2373 END IF;
2374 --
2375 END LOOP; -- END LOOP to fetch distinct header ids
2376 --
2377 --DEBUGGING
2378 IF (l_debug <> -1) THEN
2379 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2380 rlm_core_sv.dpop(C_DEBUG, 'Completed successfully');
2381 END IF;
2382 --
2383 --User friendly message
2384 --
2385 rlm_message_sv.get_msg_text(
2386 x_message_name => 'RLM_CUM_SUCCESS',
2387 x_text => v_msg_text);
2388 --
2389 fnd_file.put_line(fnd_file.log, v_msg_text);
2390 --
2391 IF (l_debug <> -1) THEN
2392 rlm_core_sv.stop_debug;
2393 END IF;
2394 --
2395 EXCEPTION
2396 --
2397 WHEN NO_DATA_FOUND THEN
2398 --
2399 IF v_level = 'SHIP_TO_ADDRESS_ID' THEN
2400 --
2401 v_msg_text := 'No ship_to_address_id is associated with the ship_to_org_id';
2402 --
2403 ELSIF v_level = 'INTRMD_SHIP_TO_ADDRESS_ID' THEN
2404 --
2405 v_msg_text := 'No intrmd_ship_to_address_id is associated with the intmed_ship_to_org_id';
2406 --
2407 ELSIF v_level = 'CUSTOMER_ID' THEN
2408 --
2409 v_msg_text := 'No customer_id is associated with the address_id';
2410 --
2411 ELSIF v_level = 'BILL_TO_ADDRESS_ID' THEN
2412 --
2413 v_msg_text := 'No bill_to_address_id is associated with the bill_to_org_id';
2414 --
2415 END IF;
2416 --
2417 ROLLBACK to updatecumkey;
2418 --
2419 x_return_status := FALSE;
2420 --
2421 IF (l_debug <> -1) THEN
2422 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2423 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: NO_DATA_FOUND');
2424 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2425 rlm_core_sv.stop_debug;
2426 END IF;
2427 --
2428 -- User-friendly message
2429 --
2430 IF v_level <> 'CUSTOMER_ID' THEN
2431 --
2432 rlm_message_sv.get_msg_text(
2433 x_message_name => 'RLM_NO_ID_FOR_ORG',
2434 x_text => v_msg_text);
2435 --
2436 ELSE
2437 --
2438 rlm_message_sv.get_msg_text(
2439 x_message_name => 'RLM_NO_CUST_FOR_ADDRESS',
2440 x_text => v_msg_text);
2441 --
2442 END IF;
2443 --
2444 fnd_file.put_line(fnd_file.log, v_msg_text);
2445 --
2446 WHEN e_no_shipment_line THEN
2447 ----------------------------------------------------+
2448 DECLARE
2449 --
2450 v_hr_location_code hr_locations.location_code%TYPE;
2451 --
2452 BEGIN
2453 --
2454 ROLLBACK to updatecumkey;
2455 --
2456 x_return_status := TRUE;
2457 --
2458 IF (l_debug <> -1) THEN
2459 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2460 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: e_no_shipment_line');
2461 END IF;
2462 --
2463 SELECT location_code
2464 INTO v_hr_location_code
2465 FROM hr_locations hr, wsh_trip_stops tstop
2466 WHERE tstop.stop_id = x_trip_stop_id
2467 AND hr.location_id = tstop.stop_location_id;
2468 --
2469 rlm_message_sv.get_msg_text(
2470 x_message_name => 'RLM_NO_SHIPMENT_LINE',
2471 x_text => v_msg_text,
2472 x_token1 => 'TRIP_STOP',
2473 x_value1 => v_hr_location_code);
2474 --
2475 IF (l_debug <> -1) THEN
2476 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2477 END IF;
2478 --
2479 -- Bug 1306894: Shipping requests the removal of this
2480 -- misleading message for non-RLM customers
2481 --
2482 -- fnd_file.put_line(fnd_file.log, v_msg_text);
2483 --
2484 IF (l_debug <> -1) THEN
2485 rlm_core_sv.stop_debug;
2486 END IF;
2487 --
2488 EXCEPTION
2489 --
2490 WHEN OTHERS THEN
2491 --
2492 rlm_message_sv.get_msg_text(
2493 x_message_name => 'RLM_NO_SHIPMENT_LINE',
2494 x_text => v_msg_text,
2495 x_token1 => 'TRIP_STOP',
2496 x_value1 => NULL);
2497 --
2498 IF (l_debug <> -1) THEN
2499 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2500 rlm_core_sv.stop_debug;
2501 END IF;
2502 --
2503 fnd_file.put_line(fnd_file.log, v_msg_text);
2504 --
2505 END;
2506 -----------------------------------------------------------+
2507 WHEN e_null_mandatory THEN
2508 --
2509 ROLLBACK to updatecumkey;
2510 --
2511 x_return_status := FALSE;
2512 --
2513 rlm_message_sv.get_msg_text(
2514 x_message_name => 'RLM_TRIP_STOP_REQUIRED',
2515 x_text => v_msg_text);
2516 --
2517 IF (l_debug <> -1) THEN
2518 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2519 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: e_null_mandatory');
2520 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2521 rlm_core_sv.stop_debug;
2522 END IF;
2523 --
2524 fnd_file.put_line(fnd_file.log, v_msg_text);
2525 --
2526 WHEN e_cum_start_date THEN
2527 --
2528 ROLLBACK to updatecumkey;
2529 --
2530 x_return_status := FALSE;
2531 --
2532 IF (l_debug <> -1) THEN
2533 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2534 END IF;
2535 v_msg_text := v_tmp_return_message;
2536 --
2537 IF (l_debug <> -1) THEN
2538 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: e_cum_start_date');
2539 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2540 rlm_core_sv.stop_debug;
2541 END IF;
2542 --
2543 fnd_file.put_line(fnd_file.log, v_msg_text);
2544 --
2545 WHEN e_no_cum_key THEN
2546 ROLLBACK to updatecumkey;
2547 rlm_message_sv.get_msg_text(
2548 x_message_name => 'RLM_NO_CUM_DISABLE_CUM_KEY',
2549 x_text => v_msg_text);
2550 --
2551 x_return_status := FALSE;
2552 --
2553 IF (l_debug <> -1) THEN
2554 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2555 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: e_no_cum_key');
2556 rlm_core_sv.dpop(C_SDEBUG);
2557 rlm_core_sv.stop_debug;
2558 END IF;
2559 fnd_file.put_line(fnd_file.log, v_msg_text);
2560
2561 WHEN e_general_error THEN
2562 --
2563 ROLLBACK to updatecumkey;
2564 --
2565 x_return_status := FALSE;
2566 --
2567 WHEN OTHERS THEN
2568 --
2569 ROLLBACK to updatecumkey;
2570 --
2571 x_return_status := FALSE;
2572 --
2573 v_msg_text := SQLERRM;
2574 --
2575 IF (l_debug <> -1) THEN
2576 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
2577 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: OTHERS');
2578 rlm_core_sv.dpop(C_SDEBUG, v_msg_text);
2579 rlm_core_sv.stop_debug;
2580 END IF;
2581 --
2582 fnd_file.put_line(fnd_file.log, v_msg_text);
2583 --
2584 END UpdateCumKey;
2585
2586 /*============================================================================
2587
2588 PROCEDURE NAME: UpdateCumKeyClient
2589
2590 =============================================================================*/
2591
2592 PROCEDURE UpdateCumKeyClient (
2593 errbuf OUT NOCOPY VARCHAR2,
2594 retcode OUT NOCOPY NUMBER,
2595 x_trip_stop_id IN NUMBER)
2596 IS
2597 --
2598 v_return_status BOOLEAN;
2599 --
2600 BEGIN
2601 --
2602 IF (l_debug <> -1) THEN
2603 rlm_core_sv.start_debug;
2604 END IF;
2605 --
2606 RLM_TPA_SV.UpdateCumKey( x_trip_stop_id,
2607 v_return_status);
2608 --
2609 IF (l_debug <> -1) THEN
2610 rlm_core_sv.stop_debug;
2611 END IF;
2612 --
2613 END UpdateCumKeyClient;
2614
2615 /*============================================================================
2616
2617 PROCEDURE NAME: ResetCumClient
2618
2619 =============================================================================*/
2620
2621 PROCEDURE ResetCumClient (
2622 errbuf OUT NOCOPY VARCHAR2,
2623 retcode OUT NOCOPY NUMBER,
2624 p_org_id IN NUMBER,
2625 x_ship_from_org_id IN NUMBER,
2626 x_customer_id IN NUMBER,
2627 x_ship_to_org_id IN NUMBER,
2628 x_intrmd_ship_to_org_id IN NUMBER,
2629 x_bill_to_org_id IN NUMBER,
2630 x_customer_item_id IN NUMBER,
2631 x_transaction_start_date IN VARCHAR2,
2632 x_transaction_end_date IN VARCHAR2)
2633 IS
2634 --
2635 v_return_status BOOLEAN;
2636 v_transaction_start_date DATE;
2637 v_transaction_end_date DATE;
2638 --
2639 --
2640 BEGIN
2641 --
2642 IF (l_debug <> -1) THEN
2643 rlm_core_sv.start_debug;
2644 END IF;
2645 --
2646 --4316744: Commented out the following code.
2647
2648 /* v_transaction_start_date := to_date(x_transaction_start_date, 'YYYY/MM/DD HH24:MI:SS');
2649 v_transaction_end_date := to_date(x_transaction_end_date, 'YYYY/MM/DD HH24:MI:SS');*/
2650 --
2651 --4316744: Timezone uptake in RLM.
2652 v_transaction_start_date := FND_DATE.canonical_to_date(x_transaction_start_date);
2653 v_transaction_end_date := FND_DATE.canonical_to_date(x_transaction_end_date);
2654
2655 ResetCum(
2656 p_org_id,
2657 x_ship_from_org_id,
2658 x_customer_id,
2659 x_ship_to_org_id,
2660 x_intrmd_ship_to_org_id,
2661 x_bill_to_org_id,
2662 x_customer_item_id,
2663 v_transaction_start_date,
2664 v_transaction_end_date,
2665 v_return_status);
2666 --
2667 IF (l_debug <> -1) THEN
2668 rlm_core_sv.stop_debug;
2669 END IF;
2670 --
2671 END ResetCumClient;
2672
2673
2674 /*=============================================================================
2675 FUNCTION NAME: GetCumControl
2676
2677 DESCRIPTION: This procedure will be called by Demand Status
2678 Inquiry Report, to get the CUM Control Code
2679 based on the setup made in the RLM Setup Terms Form.
2680
2681 PARAMETERS: x_ship_from_org_id IN NUMBER
2682 x_customer_id IN NUMBER,
2683 x_ship_to_address_id IN NUMBER,
2684 x_customer_item_id IN NUMBER
2685
2686
2687 ============================================================================*/
2688 FUNCTION GetCumControl(
2689 i_ship_from_org_id IN NUMBER,
2690 i_customer_id IN NUMBER,
2691 i_ship_to_address_id IN NUMBER,
2692 i_customer_item_id IN NUMBER
2693 )
2694 RETURN VARCHAR2 IS
2695
2696 v_temp VARCHAR2(10);
2697 v_terms_level VARCHAR2(25);
2698 v_setup_terms_msg VARCHAR2(2000);
2699 v_return_status BOOLEAN;
2700 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
2701
2702 BEGIN
2703
2704 v_terms_level := 'CUSTOMER_ITEM';
2705 RLM_TPA_SV.get_setup_terms(
2706 x_ship_from_org_id => i_ship_from_org_id,
2707 x_customer_id => i_customer_id,
2708 x_ship_to_address_id => i_ship_to_address_id,
2709 x_customer_item_id => i_customer_item_id,
2710 x_terms_definition_level => v_terms_level,
2711 x_terms_rec => v_rlm_setup_terms_record,
2712 x_return_message => v_setup_terms_msg,
2713 x_return_status => v_return_status);
2714
2715 return v_rlm_setup_terms_record.cum_control_code;
2716
2717 END GetCumControl;
2718
2719 /*=============================================================================
2720 FUNCTION NAME: get_cum_control
2721
2722 DESCRIPTION: This procedure will be called by Demand Status
2723 Inquiry Report, to get the CUM Control Code
2724 based on the setup made in the RLM Setup Terms Form.
2725
2726 PARAMETERS: x_ship_from_org_id IN NUMBER
2727 x_customer_id IN NUMBER,
2728 x_ship_to_address_id IN NUMBER,
2729 x_customer_item_id IN NUMBER
2730
2731
2732 ============================================================================*/
2733 FUNCTION get_cum_control(
2734 i_ship_from_org_id IN NUMBER,
2735 i_customer_id IN NUMBER,
2736 i_ship_to_address_id IN NUMBER,
2737 i_customer_item_id IN NUMBER
2738 )
2739 RETURN VARCHAR2 IS
2740
2741 v_temp VARCHAR2(10);
2742 v_terms_level VARCHAR2(25);
2743 v_setup_terms_msg VARCHAR2(2000);
2744 v_return_status BOOLEAN;
2745 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
2746
2747 BEGIN
2748
2749 -- v_terms_level := 'CUSTOMER';
2750 -- v_terms_level := 'ADDRESS';
2751 v_terms_level := 'CUSTOMER_ITEM';
2752 RLM_TPA_SV.get_setup_terms(
2753 x_ship_from_org_id => i_ship_from_org_id,
2754 x_customer_id => i_customer_id,
2755 x_ship_to_address_id => i_ship_to_address_id,
2756 x_customer_item_id => i_customer_item_id,
2757 x_terms_definition_level => v_terms_level,
2758 x_terms_rec => v_rlm_setup_terms_record,
2759 x_return_message => v_setup_terms_msg,
2760 x_return_status => v_return_status);
2761
2762 return v_rlm_setup_terms_record.cum_control_code;
2763
2764 END get_cum_control;
2765
2766 /*=============================================================================
2767 PROCEDURE NAME: GetCumManagement
2768
2769 DESCRIPTION: This procedure will be called by Release Workbench
2770 to get the CUM Control Code and CUM Org Level Code
2771 based on the setup made in the RLM Setup Terms Form.
2772
2773 PARAMETERS: x_ship_from_org_id IN NUMBER
2774 x_customer_id IN NUMBER,
2775 x_ship_to_address_id IN NUMBER,
2776 x_customer_item_id IN NUMBER,
2777 o_cum_control_code IN VARCHAR2,
2778 o_cum_org_level_code IN VARCHAR2
2779
2780
2781 ============================================================================*/
2782 PROCEDURE GetCumManagement(
2783 i_ship_from_org_id IN NUMBER,
2784 i_ship_to_address_id IN NUMBER,
2785 i_customer_item_id IN NUMBER,
2786 o_cum_control_code OUT NOCOPY VARCHAR2,
2787 o_cum_org_level_code OUT NOCOPY VARCHAR2
2788 )
2789 IS
2790 v_temp VARCHAR2(10);
2791 v_terms_level VARCHAR2(25);
2792 v_setup_terms_msg VARCHAR2(2000);
2793 v_return_status BOOLEAN;
2794 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
2795 v_customer_id NUMBER;
2796
2797 BEGIN
2798 --
2799 IF (l_debug <> -1) THEN
2800 rlm_core_sv.start_debug;
2801 rlm_core_sv.dpush(C_SDEBUG, 'GetCumManagement');
2802 END IF;
2803 --
2804
2805 /* Find customer_id, as it is a required input parameter for
2806 rlm_setup_terms */
2807 -- Following query is changed as per TCA obsolescence project.
2808 SELECT DISTINCT ACCT_SITE.CUST_ACCOUNT_ID
2809 INTO v_customer_id
2810 FROM HZ_CUST_ACCT_SITES ACCT_SITE
2811 WHERE ACCT_SITE.CUST_ACCT_SITE_ID = i_ship_to_address_id;
2812
2813 RLM_TPA_SV.get_setup_terms(
2814 x_ship_from_org_id => i_ship_from_org_id,
2815 x_customer_id => v_customer_id,
2816 x_ship_to_address_id => i_ship_to_address_id,
2817 x_customer_item_id => i_customer_item_id,
2818 x_terms_definition_level => v_terms_level,
2819 x_terms_rec => v_rlm_setup_terms_record,
2820 x_return_message => v_setup_terms_msg,
2821 x_return_status => v_return_status);
2822
2823 o_cum_control_code := v_rlm_setup_terms_record.cum_control_code;
2824 o_cum_org_level_code := v_rlm_setup_terms_record.cum_org_level_code;
2825 --
2826 IF (l_debug <> -1) THEN
2827 rlm_core_sv.dpop('Completed successfully');
2828 rlm_core_sv.stop_debug;
2829 END IF;
2830 --
2831 EXCEPTION
2832 WHEN NO_DATA_FOUND THEN
2833 --
2834 IF (l_debug <> -1) THEN
2835 rlm_core_sv.dpop('no data found');
2836 END IF;
2837 --
2838 WHEN OTHERS THEN
2839 --
2840 IF (l_debug <> -1) THEN
2841 rlm_core_sv.dpop('when others');
2842 END IF;
2843
2844 END GetCumManagement;
2845
2846 /*=============================================================================
2847 PROCEDURE NAME: GetCumStartDate
2848
2849 DESCRIPTION: This procedure will be called by CalculateCumKey to
2850 to get the CUM current start date and CUM current
2851 record year from the schedule
2852
2853 PARAMETERS: i_schedule_header_id IN NUMBER
2854 i_schedule_line_id IN NUMBER
2855 o_cum_start_date OUT NOCOPY DATE
2856 o_cust_record_year OUT NOCOPY VARCHAR2
2857 o_return_message OUT NOCOPY VARCHAR2
2858 o_return_status OUT NOCOPY BOOLEAN
2859
2860 ============================================================================*/
2861
2862 PROCEDURE GetCumStartDate(
2863 i_schedule_header_id IN NUMBER,
2864 i_schedule_line_id IN NUMBER,
2865 o_cum_start_date OUT NOCOPY DATE,
2866 o_cust_record_year OUT NOCOPY VARCHAR2,
2867 o_return_message OUT NOCOPY VARCHAR2,
2868 o_return_status OUT NOCOPY BOOLEAN
2869 )
2870 IS
2871 v_ship_from_org_id NUMBER;
2872 v_ship_to_address_id NUMBER;
2873 v_customer_item_id NUMBER;
2874 v_customer_id NUMBER;
2875 v_terms_level VARCHAR2(20) DEFAULT NULL;
2876 v_rlm_setup_terms_record rlm_setup_terms_sv.setup_terms_rec_typ;
2877 v_setup_terms_msg VARCHAR2(2000);
2878 v_setup_terms_status BOOLEAN;
2879 v_cust_po_number VARCHAR2(50); --Bugfix 7007638
2880 v_industry_attribute1 VARCHAR2(150); --Bugfix 7007638
2881
2882
2883 BEGIN
2884 --
2885 IF (l_debug <> -1) THEN
2886 rlm_core_sv.dpush(C_SDEBUG, 'GetCumStartDate');
2887 rlm_core_sv.dlog(C_DEBUG, 'i_schedule_header_id', i_schedule_header_id);
2888 rlm_core_sv.dlog(C_DEBUG, 'i_schedule_line_id', i_schedule_line_id);
2889 END IF;
2890 --
2891 SELECT line.ship_from_org_id,
2892 line.ship_to_address_id,
2893 line.customer_item_id,
2894 header.customer_id,
2895 line.cust_po_number, --Bugfix 7007638
2896 line.industry_attribute1 --Bugfix 7007638
2897 INTO v_ship_from_org_id,
2898 v_ship_to_address_id,
2899 v_customer_item_id,
2900 v_customer_id,
2901 v_cust_po_number, --Bugfix 7007638
2902 v_industry_attribute1 --Bugfix 7007638
2903 FROM rlm_schedule_lines_all line,
2904 rlm_schedule_headers header
2905 WHERE line.header_id = i_schedule_header_id
2906 AND line.line_id = i_schedule_line_id
2907 AND line.header_id = header.header_id;
2908 --
2909 IF (l_debug <> -1) THEN
2910 rlm_core_sv.dlog(C_DEBUG, 'v_ship_from_org_id', v_ship_from_org_id);
2911 rlm_core_sv.dlog(C_DEBUG, 'v_ship_to_address_id', v_ship_to_address_id);
2912 rlm_core_sv.dlog(C_DEBUG, 'v_customer_item_id', v_customer_item_id);
2913 rlm_core_sv.dlog(C_DEBUG, 'customer_id', v_customer_id);
2914 END IF;
2915 --
2916 BEGIN
2917 --
2918 SELECT start_date_time, industry_attribute1
2919 INTO o_cum_start_date, o_cust_record_year
2920 FROM rlm_schedule_lines
2921 WHERE header_id = i_schedule_header_id
2922 AND ship_from_org_id = v_ship_from_org_id
2923 AND ship_to_address_id = v_ship_to_address_id
2924 AND customer_item_id = v_customer_item_id
2925 AND NVL(cust_po_number,' ') = NVL(v_cust_po_number,' ') --Bugfix 7007638
2926 AND NVL(industry_attribute1,' ') = NVL(v_industry_attribute1,' ') --Bugfix 7007638
2927 AND item_detail_type = '4'
2928 AND item_detail_subtype = 'CUM';
2929 --
2930 EXCEPTION
2931 --
2932 WHEN NO_DATA_FOUND THEN
2933 --
2934 -- see if there are setup terms set for CUM management
2935 --
2936 RLM_TPA_SV.get_setup_terms(
2937 x_ship_from_org_id => v_ship_from_org_id,
2938 x_customer_id => v_customer_id,
2939 x_ship_to_address_id => v_ship_to_address_id,
2940 x_customer_item_id => v_customer_item_id,
2941 x_terms_definition_level => v_terms_level,
2942 x_terms_rec => v_rlm_setup_terms_record,
2943 x_return_message => v_setup_terms_msg,
2944 x_return_status => v_setup_terms_status);
2945 --
2946 IF (l_debug <> -1) THEN
2947 rlm_core_sv.dlog(C_DEBUG, 'cum_control_code',
2948 v_rlm_setup_terms_record.cum_control_code);
2949 rlm_core_sv.dlog(C_DEBUG, 'v_setup_terms_status',
2950 v_setup_terms_status);
2951 END IF;
2952 --
2953 IF (v_setup_terms_status = FALSE)
2954 OR (NVL(v_rlm_setup_terms_record.cum_control_code,'NO_CUM') NOT IN
2955 ('CUM_BY_DATE_ONLY','CUM_BY_DATE_RECORD_YEAR','CUM_BY_DATE_PO'))
2956 THEN
2957 --
2958 RAISE NO_DATA_FOUND;
2959 --
2960 END IF;
2961 --
2962 --This is indicating that CalculateCumKey should get the latest Key
2963 o_cum_start_date := rlm_manage_demand_sv.k_DNULL;
2964 --
2965 END;
2966
2967 rlm_message_sv.get_msg_text(
2968 x_message_name => 'RLM_CUM_SUCCESS',
2969 x_text => o_return_message);
2970
2971 o_return_status := TRUE;
2972 --
2973 IF (l_debug <> -1) THEN
2974 rlm_core_sv.dlog(C_DEBUG, 'o_cum_start_date', o_cum_start_date);
2975 rlm_core_sv.dlog(C_DEBUG, 'o_cust_record_year', o_cust_record_year);
2976 rlm_core_sv.dlog(C_DEBUG, 'o_return_status', o_return_status);
2977 rlm_core_sv.dpop('Completed successfully');
2978 END IF;
2979 --
2980 EXCEPTION
2981 WHEN NO_DATA_FOUND THEN
2982 o_return_status := FALSE;
2983 rlm_message_sv.get_msg_text(
2984 x_message_name => 'RLM_CUM_CSD_NOT_FOUND',
2985 x_text => o_return_message);
2986 --
2987 IF (l_debug <> -1) THEN
2988 --
2989 rlm_core_sv.dlog(C_DEBUG, 'o_cum_start_date', o_cum_start_date);
2990 rlm_core_sv.dlog(C_DEBUG, 'o_cust_record_year', o_cust_record_year);
2991 rlm_core_sv.dlog(C_DEBUG, 'o_return_message', o_return_message);
2992 rlm_core_sv.dlog(C_DEBUG, 'o_return_status', o_return_status);
2993 rlm_core_sv.dpop(C_DEBUG);
2994 --
2995 END IF;
2996
2997 WHEN OTHERS THEN
2998 o_return_status := FALSE;
2999 o_return_message := SQLERRM;
3000 --
3001 IF (l_debug <> -1) THEN
3002 rlm_core_sv.dlog(C_DEBUG, 'o_cum_start_date', o_cum_start_date);
3003 rlm_core_sv.dlog(C_DEBUG, 'o_cust_record_year', o_cust_record_year);
3004 rlm_core_sv.dlog(C_DEBUG, 'o_return_message', o_return_message);
3005 rlm_core_sv.dlog(C_DEBUG, 'o_return_status', o_return_status);
3006 rlm_core_sv.dpop(C_DEBUG);
3007 END IF;
3008
3009 END GetCumStartDate;
3010
3011 /*=============================================================================
3012 PROCEDURE NAME: GetTPContext
3013
3014 DESCRIPTION: This procedure returns the tpcontext using CUM Key
3015 Record
3016
3017 PARAMETERS: x_cum_key_record IN RLM_CUM_SV.cum_key_attrib_rec_type
3018 x_customer_number OUT NOCOPY VARCHAR2
3019 x_ship_to_ece_locn_code OUT NOCOPY VARCHAR2
3020 x_bill_to_ece_locn_code OUT NOCOPY VARCHAR2
3021 x_inter_ship_to_ece_locn_code OUT NOCOPY VARCHAR2
3022 x_tp_group_code OUT NOCOPY VARCHAR2
3023
3024 ============================================================================*/
3025 PROCEDURE GetTPContext(
3026 x_cum_key_record IN RLM_CUM_SV.cum_key_attrib_rec_type,
3027 x_customer_number OUT NOCOPY VARCHAR2,
3028 x_ship_to_ece_locn_code OUT NOCOPY VARCHAR2,
3029 x_bill_to_ece_locn_code OUT NOCOPY VARCHAR2,
3030 x_inter_ship_to_ece_locn_code OUT NOCOPY VARCHAR2,
3031 x_tp_group_code OUT NOCOPY VARCHAR2)
3032 IS
3033 v_level VARCHAR2(50) := 'NONE';
3034 BEGIN
3035 --
3036 IF (l_debug <> -1) THEN
3037 rlm_core_sv.dpush(C_DEBUG, 'GetTPContext');
3038 END IF;
3039 --
3040 IF x_cum_key_record.customer_id IS NOT NULL THEN
3041
3042 IF x_cum_key_record.ship_to_address_id IS NOT NULL THEN
3043 v_level := 'SHIP_TO_ECE_LOCN_CODE';
3044 -- Following query is changed as per TCA obsolescence project.
3045 SELECT acct_site.ece_tp_location_code,
3046 c.tp_group_code
3047 INTO x_ship_to_ece_locn_code,
3048 x_tp_group_code
3049 FROM HZ_CUST_ACCT_SITES ACCT_SITE,
3050 ece_tp_headers b,
3051 ece_tp_group c
3052 WHERE ACCT_SITE.CUST_ACCOUNT_ID = x_cum_key_record.customer_id
3053 AND ACCT_SITE.CUST_ACCT_SITE_ID = x_cum_key_record.ship_to_address_id
3054 AND b.tp_header_id = acct_site.tp_header_id
3055 AND c.tp_group_id = b.tp_group_id;
3056 END IF;
3057
3058 IF x_cum_key_record.bill_to_address_id IS NOT NULL THEN
3059 v_level := 'BILL_TO_ECE_LOCN_CODE';
3060 -- Following query is changed as per TCA obsolescence project.
3061 SELECT acct_site.ece_tp_location_code
3062 INTO x_bill_to_ece_locn_code
3063 FROM HZ_CUST_ACCT_SITES ACCT_SITE
3064 WHERE ACCT_SITE.CUST_ACCT_SITE_ID = x_cum_key_record.bill_to_address_id
3065 AND ACCT_SITE.CUST_ACCOUNT_ID = x_cum_key_record.customer_id;
3066 END IF;
3067
3068 IF x_cum_key_record.intrmd_ship_to_address_id IS NOT NULL THEN
3069 v_level := 'INTER_SHIP_TO_ECE_LOCN_CODE';
3070 -- Following query is changed as per TCA obsolescence project.
3071 SELECT acct_site.ece_tp_location_code
3072 INTO x_inter_ship_to_ece_locn_code
3073 FROM HZ_CUST_ACCT_SITES ACCT_SITE
3074 WHERE ACCT_SITE.CUST_ACCT_SITE_ID = x_cum_key_record.intrmd_ship_to_address_id
3075 AND ACCT_SITE.CUST_ACCOUNT_ID = x_cum_key_record.customer_id;
3076 END IF;
3077
3078 IF x_cum_key_record.customer_id IS NOT NULL THEN
3079 v_level := 'CUSTOMER_NUMBER';
3080 -- Following query is changed as per TCA obsolescence project.
3081 SELECT CUST_ACCT.ACCOUNT_NUMBER
3082 INTO x_customer_number
3083 FROM HZ_CUST_ACCOUNTS CUST_ACCT
3084 WHERE CUST_ACCT.CUST_ACCOUNT_ID = x_cum_key_record.customer_id;
3085 END IF;
3086
3087 END IF;
3088 --
3089 IF (l_debug <> -1) THEN
3090 rlm_core_sv.dlog(C_DEBUG, 'customer_number', x_customer_number);
3091 rlm_core_sv.dlog(C_DEBUG,'x_ship_to_ece_locn_code', x_ship_to_ece_locn_code);
3092 rlm_core_sv.dlog(C_DEBUG, 'x_bill_to_ece_locn_code', x_bill_to_ece_locn_code);
3093 rlm_core_sv.dlog(C_DEBUG, 'x_inter_ship_to_ece_locn_code', x_inter_ship_to_ece_locn_code);
3094 rlm_core_sv.dlog(C_DEBUG, 'x_tp_group_code',x_tp_group_code);
3095 rlm_core_sv.dpop(C_DEBUG, 'Successful');
3096 END IF;
3097 --
3098 EXCEPTION
3099 WHEN NO_DATA_FOUND THEN
3100 IF v_level = 'SHIP_TO_ECE_LOCN_CODE' THEN
3101 --
3102 IF (l_debug <> -1) THEN
3103 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Ship-To Address ID',
3104 x_cum_key_record.ship_to_address_id);
3105 END IF;
3106 --
3107 x_ship_to_ece_locn_code := NULL;
3108 --
3109 ELSIF v_level = 'BILL_TO_ECE_LOCN_CODE' THEN
3110 --
3111 IF (l_debug <> -1) THEN
3112 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Bill-To Address ID',
3113 x_cum_key_record.bill_to_address_id);
3114 END IF;
3115 --
3116 x_bill_to_ece_locn_code := NULL;
3117 --
3118 ELSIF v_level = 'INTER_SHIP_TO_ECE_LOCN_CODE' THEN
3119 --
3120 IF (l_debug <> -1) THEN
3121 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Intermediate Ship-To Address ID',
3122 x_cum_key_record.intrmd_ship_to_address_id);
3123 END IF;
3124 --
3125 x_inter_ship_to_ece_locn_code := NULL;
3126 --
3127 ELSIF v_level = 'CUSTOMER_NUMBER' THEN
3128 --
3129 IF (l_debug <> -1) THEN
3130 rlm_core_sv.dlog(C_DEBUG, 'No Customer Number Found for Customer ID ',
3131 x_cum_key_record.customer_id);
3132 END IF;
3133 --
3134 x_customer_number := NULL;
3135 --
3136 END IF;
3137 --
3138 IF (l_debug <> -1) THEN
3139 rlm_core_sv.dpop(C_DEBUG);
3140 END IF;
3141 --
3142 WHEN OTHERS THEN
3143 --
3144 IF (l_debug <> -1) THEN
3145 rlm_core_sv.dlog(C_SDEBUG, 'Level: ', v_level);
3146 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: '||SUBSTR(SQLERRM,1,200));
3147 rlm_core_sv.dpop(C_DEBUG);
3148 END IF;
3149 --
3150 RAISE;
3151
3152 END GetTPContext;
3153
3154 /*=============================================================================
3155 PROCEDURE NAME: GetTPContext2
3156
3157 DESCRIPTION: This procedure returns the tpcontext using Trip Stop ID
3158
3159 PARAMETERS: x_trip_stop_id IN NUMBER
3160 x_customer_number OUT NOCOPY VARCHAR2
3161 x_ship_to_ece_locn_code OUT NOCOPY VARCHAR2
3162 x_bill_to_ece_locn_code OUT NOCOPY VARCHAR2
3163 x_inter_ship_to_ece_locn_code OUT NOCOPY VARCHAR2
3164 x_tp_group_code OUT NOCOPY VARCHAR2
3165
3166 ============================================================================*/
3167 PROCEDURE GetTPContext2(
3168 x_trip_stop_id IN NUMBER,
3169 x_customer_number OUT NOCOPY VARCHAR2,
3170 x_ship_to_ece_locn_code OUT NOCOPY VARCHAR2,
3171 x_bill_to_ece_locn_code OUT NOCOPY VARCHAR2,
3172 x_inter_ship_to_ece_locn_code OUT NOCOPY VARCHAR2,
3173 x_tp_group_code OUT NOCOPY VARCHAR2)
3174 IS
3175 CURSOR c_oe_lines IS
3176 SELECT oelines.sold_to_org_id,
3177 oelines.ship_to_org_id,
3178 oelines.intmed_ship_to_org_id,
3179 oelines.invoice_to_org_id
3180 FROM WSH_DELIVERY_LEGS wleg,
3181 WSH_DELIVERY_ASSIGNMENTS_V wdass,
3182 WSH_DELIVERY_DETAILS wdel,
3183 OE_ORDER_LINES oelines
3184 WHERE wleg.pick_up_stop_id = x_trip_stop_id
3185 AND wdass.delivery_id = wleg.delivery_id
3186 AND wdel.delivery_detail_id = wdass.delivery_detail_id
3187 AND oelines.shipped_quantity IS NOT NULL
3188 AND oelines.line_id = wdel.source_line_id
3189 AND wdel.container_flag = 'N' -- 4301944
3190 AND oelines.header_id = wdel.source_header_id -- 4301944
3191 AND oelines.source_document_type_id = 5;
3192
3193 v_customer_id NUMBER;
3194 v_ship_to_org_id NUMBER;
3195 v_ship_to_address_id NUMBER;
3196 v_bill_to_org_id NUMBER;
3197 v_bill_to_address_id NUMBER;
3198 v_intmed_ship_to_org_id NUMBER;
3199 v_intrmd_ship_to_address_id NUMBER;
3200 v_level VARCHAR2(50) := 'NONE';
3201 e_no_delivery_lines EXCEPTION;
3202 BEGIN
3203 --
3204 IF (l_debug <> -1) THEN
3205 rlm_core_sv.dpush(C_DEBUG, 'GetTPContext2');
3206 END IF;
3207 --
3208 OPEN c_oe_lines;
3209 FETCH c_oe_lines
3210 INTO v_customer_id,
3211 v_ship_to_org_id,
3212 v_intmed_ship_to_org_id,
3213 v_bill_to_org_id;
3214 CLOSE c_oe_lines;
3215
3216 IF c_oe_lines%NOTFOUND THEN
3217 RAISE e_no_delivery_lines;
3218 END IF;
3219
3220 IF v_customer_id IS NOT NULL THEN
3221 v_level := 'CUSTOMER_NUMBER';
3222 -- Following query is changed as per TCA obsolescence project.
3223 SELECT CUST_ACCT.ACCOUNT_NUMBER
3224 INTO x_customer_number
3225 FROM HZ_CUST_ACCOUNTS CUST_ACCT
3226 WHERE CUST_ACCT.CUST_ACCOUNT_ID = v_customer_id;
3227 END IF;
3228
3229 IF v_ship_to_org_id IS NOT NULL THEN
3230 v_level := 'SHIP_TO_ADDRESS_ID';
3231 -- Following query is changed as per TCA obsolescence project.
3232 SELECT CUST_ACCT_SITE_ID
3233 INTO v_ship_to_address_id
3234 FROM HZ_CUST_SITE_USES
3235 WHERE site_use_id = v_ship_to_org_id
3236 AND site_use_code = 'SHIP_TO';
3237
3238 IF v_ship_to_address_id IS NOT NULL THEN
3239 v_level := 'SHIP_TO_ECE_LOCN_CODE';
3240 -- Following query is changed as per TCA obsolescence project.
3241 SELECT acct_site.ece_tp_location_code,
3242 c.tp_group_code
3243 INTO x_ship_to_ece_locn_code,
3244 x_tp_group_code
3245 FROM HZ_CUST_ACCT_SITES ACCT_SITE,
3246 ece_tp_headers b,
3247 ece_tp_group c
3248 WHERE ACCT_SITE.CUST_ACCOUNT_ID = v_customer_id
3249 AND ACCT_SITE.CUST_ACCT_SITE_ID = v_ship_to_address_id
3250 AND b.tp_header_id = acct_site.tp_header_id
3251 AND c.tp_group_id = b.tp_group_id;
3252 END IF;
3253 END IF;
3254
3255 IF v_bill_to_org_id IS NOT NULL THEN
3256 v_level := 'BILL_TO_ADDRESS_ID';
3257 -- Following query is changed as per TCA obsolescence project.
3258 SELECT CUST_ACCT_SITE_ID
3259 INTO v_bill_to_address_id
3260 FROM HZ_CUST_SITE_USES
3261 WHERE site_use_id = v_bill_to_org_id
3262 AND site_use_code = 'BILL_TO';
3263
3264 IF v_bill_to_address_id IS NOT NULL THEN
3265 v_level := 'BILL_TO_ECE_LOCN_CODE';
3266 -- Following query is changed as per TCA obsolescence project.
3267 SELECT ACCT_SITE.ece_tp_location_code
3268 INTO x_bill_to_ece_locn_code
3269 FROM HZ_CUST_ACCT_SITES ACCT_SITE
3270 WHERE ACCT_SITE.CUST_ACCOUNT_ID = v_customer_id
3271 AND ACCT_SITE.CUST_ACCT_SITE_ID = v_bill_to_address_id;
3272
3273 END IF;
3274
3275 END IF;
3276
3277 IF v_intmed_ship_to_org_id IS NOT NULL THEN
3278 v_level := 'INTRMD_SHIP_TO_ADDRESS_ID';
3279 -- Following query is changed as per TCA obsolescence project.
3280 SELECT CUST_ACCT_SITE_ID
3281 INTO v_intrmd_ship_to_address_id
3282 FROM HZ_CUST_SITE_USES
3283 WHERE site_use_id = v_intmed_ship_to_org_id
3284 AND site_use_code = 'SHIP_TO';
3285
3286 IF v_intrmd_ship_to_address_id IS NOT NULL THEN
3287 v_level := 'INTER_SHIP_TO_ECE_LOCN_CODE';
3288 -- Following query is changed as per TCA obsolescence project.
3289 SELECT ACCT_SITE.ece_tp_location_code
3290 INTO x_inter_ship_to_ece_locn_code
3291 FROM HZ_CUST_ACCT_SITES ACCT_SITE
3292 WHERE ACCT_SITE.CUST_ACCOUNT_ID = v_customer_id
3293 AND ACCT_SITE.CUST_ACCT_SITE_ID = v_intrmd_ship_to_address_id;
3294 END IF;
3295 END IF;
3296 --
3297 IF (l_debug <> -1) THEN
3298 rlm_core_sv.dlog(C_DEBUG, 'customer_number', x_customer_number);
3299 rlm_core_sv.dlog(C_DEBUG,'x_ship_to_ece_locn_code', x_ship_to_ece_locn_code);
3300 rlm_core_sv.dlog(C_DEBUG, 'x_bill_to_ece_locn_code', x_bill_to_ece_locn_code);
3301 rlm_core_sv.dlog(C_DEBUG, 'x_inter_ship_to_ece_locn_code', x_inter_ship_to_ece_locn_code);
3302 rlm_core_sv.dlog(C_DEBUG, 'x_tp_group_code',x_tp_group_code);
3303 rlm_core_sv.dpop(C_DEBUG, 'Successful');
3304 END IF;
3305 --
3306 EXCEPTION
3307 WHEN NO_DATA_FOUND THEN
3308 --
3309 IF v_level = 'SHIP_TO_ECE_LOCN_CODE' THEN
3310 --
3311 IF (l_debug <> -1) THEN
3312 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Ship-To Address ID', v_ship_to_address_id);
3313 END IF;
3314 --
3315 x_ship_to_ece_locn_code := NULL;
3316 --
3317 ELSIF v_level = 'BILL_TO_ECE_LOCN_CODE' THEN
3318 --
3319 IF (l_debug <> -1) THEN
3320 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Bill-To Address ID', v_bill_to_address_id);
3321 END IF;
3322 --
3323 x_bill_to_ece_locn_code := NULL;
3324 --
3325 ELSIF v_level = 'INTER_SHIP_TO_ECE_LOCN_CODE' THEN
3326 --
3327 IF (l_debug <> -1) THEN
3328 rlm_core_sv.dlog(C_DEBUG, 'No Location Code Found for Intermediate Ship-To Address ID',
3329 v_intrmd_ship_to_address_id);
3330 END IF;
3331 --
3332 x_inter_ship_to_ece_locn_code := NULL;
3333 --
3334 ELSIF v_level = 'CUSTOMER_NUMBER' THEN
3335 --
3336 IF (l_debug <> -1) THEN
3337 rlm_core_sv.dlog(C_DEBUG, 'No Customer Number Found for Customer ID ', v_customer_id);
3338 END IF;
3339 --
3340 x_customer_number := NULL;
3341 --
3342 ELSIF v_level = 'SHIP_TO_ADDRESS_ID' THEN
3343 --
3344 IF (l_debug <> -1) THEN
3345 rlm_core_sv.dlog(C_DEBUG, 'No Address ID Found for Ship-To Org ID ', v_ship_to_org_id);
3346 END IF;
3347 --
3348 ELSIF v_level = 'INTRMD_SHIP_TO_ADDRESS_ID' THEN
3349 --
3350 IF (l_debug <> -1) THEN
3351 rlm_core_sv.dlog(C_DEBUG, 'No Address ID Found for Intermediate Ship-To Org ID ',
3352 v_intmed_ship_to_org_id);
3353 END IF;
3354 --
3355 ELSIF v_level = 'BILL_TO_ADDRESS_ID' THEN
3356 --
3357 IF (l_debug <> -1) THEN
3358 rlm_core_sv.dlog(C_DEBUG, 'No Address ID Found for Bill-To Org ID ', v_bill_to_org_id);
3359 END IF;
3360 --
3361 END IF;
3362 --
3363 IF (l_debug <> -1) THEN
3364 rlm_core_sv.dpop(C_DEBUG);
3365 END IF;
3366 --
3367 WHEN e_no_delivery_lines THEN
3368 --
3369 IF (l_debug <> -1) THEN
3370 rlm_core_sv.dlog(C_DEBUG, 'No delivery line is associated with Trip Stop ID ', x_trip_stop_id);
3371 END IF;
3372 --
3373 WHEN OTHERS THEN
3374 --
3375 IF (l_debug <> -1) THEN
3376 rlm_core_sv.dlog(C_SDEBUG, 'Level: ', v_level);
3377 rlm_core_sv.dlog(C_SDEBUG, 'EXCEPTION: '||SUBSTR(SQLERRM,1,200));
3378 rlm_core_sv.dpop(C_DEBUG);
3379 END IF;
3380 --
3381 RAISE;
3382
3383 END GetTPContext2;
3384
3385 -- The procedure GetNameForId is removed as it was commented out.
3386
3387
3388 /*============================================================================
3389
3390 PROCEDURE NAME: ResetCum
3391
3392 Flow: Get the setupterms based on the parameters passed, then call GetCums
3393 which will return 3 tables. One table is the new cums created to reset the
3394 old ones, the other table is the old cums and the third table is used to
3395 relate the first and second table. For each cum in the old table, call
3396 SetSupplierCum which calls CalculateSupplierCum for all the shipments
3397 for the given Cum Key. It populates oe global tables and it calculates
3398 the cum qty .
3399 Then call the process_order once for each header_id. If process_order
3400 completes without error then call UpdateOldKey to recalculate the old
3401 cums which have been reset.
3402
3403 =============================================================================*/
3404
3405 PROCEDURE ResetCum (
3406 p_org_id IN NUMBER,
3407 x_ship_from_org_id IN NUMBER,
3408 x_customer_id IN NUMBER,
3409 x_ship_to_org_id IN NUMBER,
3410 x_intrmd_ship_to_org_id IN NUMBER,
3411 x_bill_to_org_id IN NUMBER,
3412 x_customer_item_id IN NUMBER,
3413 x_transaction_start_date IN DATE,
3414 x_transaction_end_date IN DATE,
3415 x_return_status OUT NOCOPY BOOLEAN)
3416 IS
3417 --
3418 v_rlm_setup_terms_rec rlm_setup_terms_sv.setup_terms_rec_typ;
3419 v_index NUMBER;
3420 v_index2 NUMBER;
3421 v_index3 NUMBER;
3422 v_num NUMBER;
3423 v_start_num NUMBER DEFAULT 0;
3424 v_end_num NUMBER DEFAULT 0;
3425 v_cum_key_record cum_key_attrib_rec_type;
3426 v_old_cum_counter RLM_CUM_SV.t_new_ship_count;
3427 p_ship_from_org_id NUMBER DEFAULT NULL;
3428 p_ship_to_org_id NUMBER DEFAULT NULL;
3429 p_intmed_ship_to_org_id NUMBER DEFAULT NULL;
3430 p_bill_to_org_id NUMBER DEFAULT NULL;
3431 p_cum_key_id NUMBER DEFAULT NULL;
3432 v_ship_to_address_id NUMBER;
3433 v_bill_to_address_id NUMBER;
3434 v_intrmd_ship_to_address_id NUMBER;
3435 v_terms_level VARCHAR2(25) DEFAULT NULL;
3436 v_setup_terms_msg VARCHAR2(5000);
3437 v_setup_terms_status BOOLEAN;
3438 v_level VARCHAR2(60);
3439 counter NUMBER DEFAULT 1;
3440 counter2 NUMBER DEFAULT 0;
3441 v_reset_counter NUMBER DEFAULT 0;
3442 error_count NUMBER DEFAULT 0;
3443 v_trail1 VARCHAR2(5000);
3444 v_trail2 VARCHAR2(5000);
3445 v_trail3 VARCHAR2(5000);
3446 v_trail4 VARCHAR2(5000);
3447 v_trail5 VARCHAR2(5000);
3448 v_trail6 VARCHAR2(5000);
3449 --v_old_cum_table t_old_cum;
3450 v_old_cum_records RLM_CUM_SV.t_cums;
3451 v_tmp_old_table t_old_cum;
3452 ----
3453 ---- Used by Process Order API
3454 --
3455 x_oe_api_version NUMBER DEFAULT 1;
3456 l_return_status VARCHAR2(1);
3457 v_return_status BOOLEAN;
3458 v_return_stat NUMBER DEFAULT 0 ;
3459 v_msg_data VARCHAR2(2000);
3460 v_adjustment_ids t_new_ship_count;
3461 v_adjustment_date DATE DEFAULT NULL;
3462 v_header_id NUMBER;
3463 v_cum_records RLM_CUM_SV.t_cums;
3464 v_msg_count NUMBER;
3465 adj_qty NUMBER DEFAULT 0;
3466 l_file_val VARCHAR2(80);
3467 v_om_dbg_dir VARCHAR2(80);
3468 v_end_date_time date DEFAULT NULL;
3469 tmp_char VARCHAR2(50);
3470 v_shipLineCounter NUMBER;
3471 --
3472 e_NoCum EXCEPTION;
3473 e_NoShipment EXCEPTION;
3474 v_visited BOOLEAN;
3475 --
3476 l_oe_line_tbl_out oe_order_pub.line_tbl_type;
3477 --
3478 BEGIN
3479 --
3480 IF (l_debug <> -1) THEN
3481 rlm_core_sv.dpush(C_SDEBUG, 'ResetCum');
3482 END IF;
3483 --
3484 x_return_status := TRUE;
3485 --
3486 MO_GLOBAL.set_policy_context(p_access_mode => 'S',
3487 p_org_id => p_org_id);
3488 --
3489 IF (l_debug <> -1) THEN
3490 rlm_core_sv.dlog(C_SDEBUG, 'p_org_id',p_org_id);
3491 rlm_core_sv.dlog(C_SDEBUG, 'x_ship_from_org_id',x_ship_from_org_id);
3492 rlm_core_sv.dlog(C_SDEBUG, 'x_customer_id',x_customer_id);
3493 rlm_core_sv.dlog(C_SDEBUG, 'x_customer_item_id',x_customer_item_id);
3494 rlm_core_sv.dlog(C_SDEBUG, 'x_transaction_start_date',
3495 x_transaction_start_date);
3496 END IF;
3497 --
3498 -- add time stamp
3499 --
3500 --4316744: Commented out the following code.
3501 /*IF x_transaction_end_date IS NOT NULL THEN
3502 tmp_char := to_char(x_transaction_end_date ,'DD-MM-YYYY') || ' 23:59:59';
3503 v_end_date_time := to_date(tmp_char,'DD-MM-YYYY HH24:MI:SS');
3504 END IF;*/
3505 --
3506 --4316744: Timezone uptake in RLM.
3507 IF x_transaction_end_date IS NOT NULL THEN
3508 v_end_date_time := x_transaction_end_date;
3509 END IF;
3510
3511 IF (l_debug <> -1) THEN
3512 rlm_core_sv.dlog(C_SDEBUG, 'v_end_date_time',
3513 v_end_date_time);
3514 END IF;
3515 --
3516 -- Start logging the ResetCum trail into the fnd log file here!
3517 --
3518 fnd_file.put_line(fnd_file.log, 'User Input Parameters: ');
3519 fnd_file.put_line(fnd_file.log, 'Operating Unit: ' ||p_org_id);
3520 fnd_file.put_line(fnd_file.log, 'Ship-From Organization ID: ' ||x_ship_from_org_id);
3521 fnd_file.put_line(fnd_file.log, 'Ship-To Organization ID: ' ||x_ship_to_org_id);
3522 fnd_file.put_line(fnd_file.log, 'Intermediate Ship-To Organization ID: ' ||x_intrmd_ship_to_org_id);
3523 fnd_file.put_line(fnd_file.log, 'Bill-To Organization ID: ' ||x_bill_to_org_id);
3524 fnd_file.put_line(fnd_file.log, 'Customer Item ID: ' ||x_customer_item_id);
3525 fnd_file.put_line(fnd_file.log, 'Transaction Start Date: ' ||x_transaction_start_date);
3526 fnd_file.put_line(fnd_file.log, 'Transaction End Date: ' ||NVL(v_end_date_time, SYSDATE));
3527 fnd_file.put_line(fnd_file.log, ' ');
3528 --
3529 -- v_level is used to keep track of where in the program flow the exception occurs
3530 -- Find the ship_to_address_id
3531 --
3532 v_level := 'SHIP_TO_ADDRESS_ID';
3533 --
3534 IF (l_debug <> -1) THEN
3535 rlm_core_sv.dlog(C_SDEBUG, 'x_ship_to_org_id',x_ship_to_org_id);
3536 END IF;
3537 --
3538 --IF x_ship_to_org_id IS NOT NULL THEN
3539 --
3540 -- Following query is changed as per TCA obsolescence project.
3541 SELECT CUST_ACCT_SITE_ID
3542 INTO v_ship_to_address_id
3543 FROM HZ_CUST_SITE_USES
3544 WHERE site_use_id = x_ship_to_org_id
3545 AND site_use_code = 'SHIP_TO';
3546
3547 -- Find the intrmd_ship_to_address_id
3548 --
3549 v_level := 'INTRMD_SHIP_TO_ADDRESS_ID';
3550 --
3551 IF (l_debug <> -1) THEN
3552 rlm_core_sv.dlog(C_SDEBUG,'x_intrmd_ship_to_org_id',x_intrmd_ship_to_org_id);
3553 END IF;
3554 --
3555 IF x_intrmd_ship_to_org_id IS NOT NULL THEN
3556 --
3557 -- Following query is changed as per TCA obsolescence project.
3558 SELECT CUST_ACCT_SITE_ID
3559 INTO v_intrmd_ship_to_address_id
3560 FROM HZ_CUST_SITE_USES
3561 WHERE site_use_id = x_intrmd_ship_to_org_id
3562 AND site_use_code = 'SHIP_TO';
3563 --
3564 ELSE
3565 --
3566 -- There is no intermediate ship-to address id associated with that int shipto org id
3567 --
3568 v_intrmd_ship_to_address_id := NULL;
3569 END IF;
3570 --
3571 IF (l_debug <> -1) THEN
3572 rlm_core_sv.dlog(C_SDEBUG,'v_intrmd_ship_to_address_id',
3573 v_intrmd_ship_to_address_id);
3574 END IF;
3575 --
3576 -- Find the bill_to_address_id
3577 --
3578 v_level := 'BILL_TO_ADDRESS_ID';
3579 --
3580 IF (l_debug <> -1) THEN
3581 rlm_core_sv.dlog(C_SDEBUG,'x_bill_to_org_id',x_bill_to_org_id);
3582 END IF;
3583 --
3584 IF x_bill_to_org_id IS NOT NULL THEN
3585 --
3586 -- Following query is changed as per TCA obsolescence project.
3587 SELECT CUST_ACCT_SITE_ID
3588 INTO v_bill_to_address_id
3589 FROM HZ_CUST_SITE_USES
3590 WHERE site_use_id = x_bill_to_org_id
3591 AND site_use_code = 'BILL_TO';
3592 --
3593 ELSE
3594 --
3595 -- There is no bill-to address id associated with that bill-to org id
3596 --
3597 v_bill_to_address_id := NULL;
3598 --
3599 END IF;
3600 --
3601 IF (l_debug <> -1) THEN
3602 rlm_core_sv.dlog(C_SDEBUG,'v_bill_to_address_id',v_bill_to_address_id);
3603 END IF;
3604 --
3605 -- Get the setup terms at the appropriate/lowest level so that
3606 --
3607 RLM_TPA_SV.get_setup_terms(
3608 x_ship_from_org_id => x_ship_from_org_id,
3609 x_customer_id => x_customer_id,
3610 x_ship_to_address_id => v_ship_to_address_id,
3611 x_customer_item_id => x_customer_item_id,
3612 x_terms_definition_level => v_terms_level,
3613 x_terms_rec => v_rlm_setup_terms_rec,
3614 x_return_message => v_setup_terms_msg,
3615 x_return_status => v_setup_terms_status);
3616 --
3617 -- Continue only if the records return status is TRUE
3618 -- Continue only if the cum control code is NO_CUM
3619 --
3620 IF v_setup_terms_status = TRUE THEN --{
3621 --
3622 IF (nvl(v_rlm_setup_terms_rec.cum_control_code,'NO_CUM') <> 'NO_CUM'
3623 AND v_rlm_setup_terms_rec.cum_control_code <> 'CUM_BY_PO_ONLY') THEN
3624 --{
3625 IF (v_terms_level = 'CUSTOMER_ITEM'
3626 AND v_rlm_setup_terms_rec.calc_cum_flag = 'Y')
3627 OR v_terms_level <> 'CUSTOMER_ITEM' THEN --{
3628 --
3629 -- Determine the select criteria based on the cum org level code
3630 --
3631 --
3632 IF v_rlm_setup_terms_rec.cum_org_level_code = 'BILL_TO_SHIP_FROM'
3633 THEN
3634 --
3635 p_ship_from_org_id := x_ship_from_org_id;
3636 p_bill_to_org_id := x_bill_to_org_id;
3637 --
3638 ELSIF v_rlm_setup_terms_rec.cum_org_level_code =
3639 'SHIP_TO_SHIP_FROM'
3640 THEN
3641 --
3642 p_ship_from_org_id := x_ship_from_org_id;
3643 p_ship_to_org_id := x_ship_to_org_id;
3644 --
3645 ELSIF v_rlm_setup_terms_rec.cum_org_level_code =
3646 'INTRMD_SHIP_TO_SHIP_FROM'
3647 THEN
3648 --
3649 p_ship_from_org_id := x_ship_from_org_id;
3650 p_intmed_ship_to_org_id := x_ship_to_org_id;
3651 --
3652 ELSIF v_rlm_setup_terms_rec.cum_org_level_code =
3653 'SHIP_TO_ALL_SHIP_FROMS'
3654 THEN
3655 --
3656 p_ship_to_org_id := x_ship_to_org_id;
3657 --
3658 END IF;
3659 --
3660 IF (l_debug <> -1) THEN
3661 rlm_core_sv.dlog(C_SDEBUG, 'The criteria used to select the shipment ' ||'lines');
3662 rlm_core_sv.dlog(C_SDEBUG, 'p_ship_from_org_id', p_ship_from_org_id);
3663 rlm_core_sv.dlog(C_SDEBUG, 'p_ship_to_org_id', p_ship_to_org_id);
3664 rlm_core_sv.dlog(C_SDEBUG, 'p_intmed_ship_to_org_id',
3665 p_intmed_ship_to_org_id);
3666 rlm_core_sv.dlog(C_SDEBUG, 'p_bill_to_org_id', p_bill_to_org_id);
3667 rlm_core_sv.dlog(C_SDEBUG, 'x_customer_item_id', x_customer_item_id);
3668 rlm_core_sv.dlog(C_SDEBUG, 'x_transaction_start_date',
3669 x_transaction_start_date);
3670 rlm_core_sv.dlog(C_SDEBUG, 'v_end_date_time',
3671 v_end_date_time);
3672 END IF;
3673 --
3674 fnd_file.put_line(fnd_file.log, 'p_ship_from_org_id: '
3675 ||p_ship_from_org_id);
3676 fnd_file.put_line(fnd_file.log, 'p_ship_to_org_id: '
3677 ||p_ship_to_org_id);
3678 fnd_file.put_line(fnd_file.log, 'p_intmed_ship_to_org_id: '
3679 ||p_intmed_ship_to_org_id);
3680 fnd_file.put_line(fnd_file.log, 'p_bill_to_org_id: '
3681 ||p_bill_to_org_id);
3682 fnd_file.put_line(fnd_file.log, ' ');
3683 fnd_file.put_line(fnd_file.log,
3684 'Loop to find all qualified shipment lines ');
3685 fnd_file.put_line(fnd_file.log, ' ');
3686 --
3687 --
3688
3689 v_cum_key_record.customer_id := x_customer_id;
3690 v_cum_key_record.customer_item_id := x_customer_item_id;
3691 v_cum_key_record.ship_from_org_id := x_ship_from_org_id;
3692 v_cum_key_record.intrmd_ship_to_address_id:=
3693 v_intrmd_ship_to_address_id;
3694 v_cum_key_record.ship_to_address_id := v_ship_to_address_id;
3695 v_cum_key_record.bill_to_address_id := v_bill_to_address_id;
3696
3697
3698 rlm_cum_sv.GetCums(v_rlm_setup_terms_rec
3699 ,v_terms_level
3700 ,v_cum_key_record
3701 ,x_transaction_start_date
3702 ,v_end_date_time
3703 ,p_ship_from_org_id
3704 ,p_ship_to_org_id
3705 ,p_intmed_ship_to_org_id
3706 ,p_bill_to_org_id
3707 ,v_cum_records
3708 ,v_old_cum_records
3709 ,v_old_cum_counter
3710 ,v_return_stat);
3711 --
3712 IF (l_debug <> -1) THEN
3713 rlm_core_sv.dlog(C_DEBUG,'v_return_stat',v_return_stat);
3714 END IF;
3715 --
3716 IF v_return_stat = 0 THEN
3717 --
3718 IF (l_debug <> -1) THEN
3719 rlm_core_sv.dlog(C_DEBUG,'Could not find any CUM to reset');
3720 END IF;
3721 --
3722 raise e_NoCum;
3723 --
3724 END IF;
3725
3726 v_num := v_old_cum_counter.count;
3727 --
3728 IF (l_debug <> -1) THEN
3729 rlm_core_sv.dlog(C_DEBUG,'v_num',v_num);
3730 END IF;
3731 --
3732 IF (l_debug <> -1) THEN
3733 rlm_core_sv.dlog(C_DEBUG,'v_cum_records.count',v_cum_records.count);
3734 rlm_core_sv.dlog(C_DEBUG,'v_old_cum_records.count',
3735 v_old_cum_records.count);
3736 END IF;
3737 --
3738 g_oe_tmp_line_tbl := oe_order_pub.g_miss_line_tbl;
3739 --
3740 FOR v_index IN 1..v_num LOOP --{
3741 --
3742 SAVEPOINT s_reset_counter;
3743 --
3744 --v_reset_counter is used to undo cum_keys processed with error
3745 --
3746 v_reset_counter := counter;
3747 --
3748 IF (l_debug <> -1) THEN
3749 rlm_core_sv.dlog(C_DEBUG,'v_reset_counter',v_reset_counter);
3750 END IF;
3751 --
3752 /* these indexes are used to get the relationships between
3753 v_cum_records, v_old_cum_records, and v_old_cum_counter
3754 */
3755 --
3756 v_start_num := v_end_num + 1;
3757 --
3758 IF (l_debug <> -1) THEN
3759 rlm_core_sv.dlog(C_DEBUG,'v_start_num',v_start_num);
3760 END IF;
3761 --
3762 v_end_num := v_start_num + v_old_cum_counter(v_index) -1 ;
3763 --
3764 IF (l_debug <> -1) THEN
3765 rlm_core_sv.dlog(C_DEBUG,'v_end_num',v_end_num);
3766 END IF;
3767 --
3768 v_index2 := v_end_num;
3769 --
3770 IF (l_debug <> -1) THEN
3771 rlm_core_sv.dlog(C_DEBUG,'v_index2',v_index2);
3772 END IF;
3773 --
3774 /* following are set for CalculateSuplierCum*/
3775 v_cum_records(v_index).cum_qty := 0;
3776 --
3777 v_cum_records(v_index).cum_qty_to_be_accumulated := 0;
3778 v_cum_records(v_index).cum_qty_after_cutoff := 0;
3779 --
3780 -- Set shipment inclusion rule and as of date time
3781 --
3782 v_cum_records(v_index).use_ship_incl_rule_flag := 'Y';
3783 --
3784 v_cum_records(v_index).as_of_date_time := NULL;
3785 --
3786 --set record_return_status to TRUE used in CalculateSuplierCum
3787 --
3788 v_cum_records(v_index).record_return_status := TRUE;
3789 --
3790 v_adjustment_date := NULL;
3791 --
3792 v_tmp_old_table.DELETE;
3793 g_cum_oe_lines.DELETE;
3794 --
3795 v_shipLineCounter := 1;
3796 v_visited := FALSE;
3797
3798 LOOP --{
3799 --
3800 p_cum_key_id := v_old_cum_records(v_index2).cum_key_id;
3801 --
3802
3803 --calculate inventory_item_id from customer_item_id once for the old cum group
3804
3805 IF (v_visited = FALSE) THEN
3806 --
3807 v_old_cum_records(v_index2).inventory_item_id := GetInventoryItemId(v_old_cum_records(v_index2).customer_item_id);
3808
3809 --inventory_item_id populated in v_cum_key_record to improve queries (bug 1893220)
3810
3811 v_cum_key_record.inventory_item_id := v_old_cum_records(v_index2).inventory_item_id;
3812 --
3813 IF (l_debug <> -1) THEN
3814 rlm_core_sv.dlog(C_DEBUG,'customer_item_id',v_old_cum_records(v_index2).customer_item_id);
3815 rlm_core_sv.dlog(C_DEBUG,'inventory_item_id',v_cum_key_record.inventory_item_id);
3816 END IF;
3817
3818 v_visited := TRUE;
3819 --
3820
3821 ELSE
3822
3823 v_old_cum_records(v_index2).inventory_item_id :=v_cum_key_record.inventory_item_id;
3824
3825 END IF;
3826
3827
3828 /* For each new key, put the old one in table v_tmp_old_table
3829 If SetSupplierCum returned false then keep this table so that
3830 we can delete these keys from the table passed to UpdateOldKey
3831 so that these keys won't get processed. If everything goes well
3832 then delete this table
3833 */
3834 v_tmp_old_table(v_index2) := p_cum_key_id;
3835 --
3836 rlm_cum_sv.GetShippLines(
3837 x_cum_key_id => p_cum_key_id,
3838 x_ship_from_org_id => p_ship_from_org_id,
3839 x_ship_to_org_id => p_ship_to_org_id,
3840 x_intmed_ship_to_org_id => p_intmed_ship_to_org_id,
3841 x_bill_to_org_id => p_bill_to_org_id,
3842 x_customer_item_id => x_customer_item_id,
3843 x_inventory_item_id => v_cum_key_record.inventory_item_id,
3844 x_transaction_start_date => x_transaction_start_date,
3845 x_transaction_end_date => v_end_date_time,
3846 x_index => v_shipLineCounter);
3847 --
3848 --set the cum_key_id from adjustment to be the new cum_key_id
3849
3850 UPDATE rlm_cust_item_cum_adj
3851 SET cum_key_id = v_cum_records(v_index).cum_key_id
3852 WHERE cum_key_id = p_cum_key_id
3853 AND transaction_date_time <= nvl(v_end_date_time,sysdate)
3854 AND transaction_date_time >= x_transaction_start_date;
3855 --
3856
3857 v_index2 := v_index2 -1;
3858 --
3859 IF(v_index2 < v_start_num) THEN
3860 --
3861 EXIT;
3862 --
3863 END IF;
3864 --
3865 END LOOP; --}
3866 --
3867 --take care off the shipment for the new cum
3868 p_cum_key_id := v_cum_records(v_index).cum_key_id;
3869 --
3870 --
3871 -- if the end date is smaller than sysdate then we should
3872 --increase it to today's date to calculate the qty for
3873 --new cum correctly.
3874 --
3875 v_end_date_time := SYSDATE;
3876 --
3877 rlm_cum_sv.GetShippLines(
3878 x_cum_key_id => p_cum_key_id,
3879 x_ship_from_org_id => p_ship_from_org_id,
3880 x_ship_to_org_id => p_ship_to_org_id,
3881 x_intmed_ship_to_org_id => p_intmed_ship_to_org_id,
3882 x_bill_to_org_id => p_bill_to_org_id,
3883 x_customer_item_id => x_customer_item_id,
3884 x_inventory_item_id => v_cum_key_record.inventory_item_id,
3885 x_transaction_start_date => NULL,
3886 x_transaction_end_date => v_end_date_time,
3887 x_index => v_shipLineCounter);
3888 --
3889 IF g_cum_oe_lines.COUNT > 0 THEN
3890 --
3891 rlm_cum_sv.quicksort(g_cum_oe_lines.FIRST,
3892 g_cum_oe_lines.LAST,
3893 C_cum_oe_lines);
3894 --
3895 END IF;
3896 --
3897 -- Need to set called_by_reset_cum to 'Y'
3898 v_cum_key_record.called_by_reset_cum := 'Y';
3899 --
3900
3901 rlm_cum_sv.SetSupplierCum(
3902 x_index => v_index,
3903 x_cum_key_record => v_cum_key_record,
3904 x_transaction_start_date => x_transaction_start_date,
3905 x_cum_records => v_cum_records,
3906 x_return_status => v_return_status,
3907 x_counter => counter,
3908 x_adjustment_date => v_adjustment_date);
3909 --
3910 IF (l_debug <> -1) THEN
3911 rlm_core_sv.dlog(C_DEBUG,'v_return_status',v_return_status);
3912 END IF;
3913 --
3914 IF(v_return_status = FALSE)
3915 OR (v_cum_records(v_index).record_return_status = FALSE)
3916 THEN
3917 -- For this Cum clear the OE table and the updates in
3918 -- adjustment table. Also mark the old_table so the procedure
3919 --does not recalculate the cum for them
3920 ROLLBACK TO s_reset_counter;
3921 --
3922 IF counter > v_reset_counter THEN
3923 --
3924 FOR i in v_reset_counter..(counter-1) LOOP
3925 --
3926 g_oe_tmp_line_tbl.DELETE(i);
3927 --
3928 END LOOP;
3929 --
3930 END IF;
3931 --
3932 counter := v_reset_counter;
3933 --
3934 v_index3 := v_tmp_old_table.FIRST;
3935 --
3936 LOOP
3937 --
3938 v_old_cum_records(v_index3).cum_key_id := NULL;
3939 --
3940 EXIT WHEN v_index3 = v_tmp_old_table.LAST;
3941 --
3942 v_index3 := v_tmp_old_table.NEXT(v_index3);
3943 --
3944 END LOOP;
3945 --
3946 v_tmp_old_table.DELETE;
3947 --
3948 ELSE --if there are no problems then update the CUM table
3949 --
3950 -- get all adjustments after the last shipment
3951 IF v_adjustment_date IS NULL THEN
3952 --
3953 SELECT SUM(transaction_qty)
3954 INTO adj_qty
3955 FROM rlm_cust_item_cum_adj
3956 WHERE cum_key_id = v_cum_records(v_index).cum_key_id
3957 AND transaction_date_time <= sysdate;
3958 --
3959 ELSE
3960 --
3961 SELECT SUM(transaction_qty)
3962 INTO adj_qty
3963 FROM rlm_cust_item_cum_adj
3964 WHERE cum_key_id = v_cum_records(v_index).cum_key_id
3965 AND transaction_date_time >= v_adjustment_date
3966 AND transaction_date_time <= sysdate;
3967 --
3968 END IF;
3969 --
3970 IF (l_debug <> -1) THEN
3971 rlm_core_sv.dlog(C_DEBUG,'v_adjustment_date',
3972 v_adjustment_date);
3973 END IF;
3974 --
3975 IF adj_qty IS NULL THEN
3976 --
3977 adj_qty := 0;
3978 --
3979 --
3980 END IF;
3981 --
3982 IF (l_debug <> -1) THEN
3983 rlm_core_sv.dlog(C_DEBUG, 'adj_qty',adj_qty);
3984 rlm_core_sv.dlog(C_DEBUG,'v_index',v_index);
3985 END IF;
3986
3987 v_cum_records(v_index).cum_qty :=
3988 v_cum_records(v_index).cum_qty + adj_qty;
3989 --
3990 UPDATE rlm_cust_item_cum_keys
3991 SET cum_qty = v_cum_records(v_index).cum_qty,
3992 cum_qty_to_be_accumulated =
3993 v_cum_records(v_index).cum_qty_to_be_accumulated,
3994 cum_qty_after_cutoff =
3995 v_cum_records(v_index).cum_qty_after_cutoff,
3996 last_cum_qty_update_date = SYSDATE,
3997 last_update_login = FND_GLOBAL.LOGIN_ID,
3998 last_update_date = SYSDATE,
3999 last_updated_by = FND_GLOBAL.USER_ID
4000 WHERE cum_key_id = v_cum_records(v_index).cum_key_id
4001 AND NVL(inactive_flag,'N') = 'N';
4002 --
4003 IF (l_debug <> -1) THEN
4004 rlm_core_sv.dlog(C_DEBUG,'v_cum_records(v_index).cum_key_id',
4005 v_cum_records(v_index).cum_key_id);
4006 rlm_core_sv.dlog(C_DEBUG,'v_cum_records(v_index).cum_qty',
4007 v_cum_records(v_index).cum_qty);
4008 END IF;
4009 --
4010 END IF;
4011 --
4012 END LOOP; --}
4013 -- group the g_oe_tmp_line_tbl by header_id
4014 IF g_oe_tmp_line_tbl.COUNT = 0 THEN
4015 --
4016 IF (l_debug <> -1) THEN
4017 rlm_core_sv.dlog(C_DEBUG,'There are no order lines to process');
4018 END IF;
4019 --
4020 RAISE e_NoShipment;
4021 --
4022 END IF;
4023 --
4024 rlm_cum_sv.quicksort(g_oe_tmp_line_tbl.FIRST,
4025 g_oe_tmp_line_tbl.LAST,
4026 RLM_CUM_SV.C_line_table_type);
4027 --
4028 v_index3 := g_oe_tmp_line_tbl.FIRST;
4029 --
4030 IF (l_debug <> -1) THEN
4031 rlm_core_sv.dlog(C_DEBUG, 'v_index3',v_index3);
4032 END IF;
4033 --
4034 v_index2 := 1;
4035 --
4036 v_header_id := g_oe_tmp_line_tbl(v_index3).header_id;
4037 --
4038 IF (l_debug <> -1) THEN
4039 rlm_core_sv.dlog(C_DEBUG, 'v_header_id',v_header_id);
4040 END IF;
4041 --
4042 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
4043 --
4044 --g_oe_tmp_line_tbl := oe_order_pub.g_miss_line_tbl;
4045 --
4046 BEGIN --{
4047 --
4048 fnd_profile.get('ECE_OUT_FILE_PATH',v_om_dbg_dir);
4049 --
4050 fnd_profile.put('OE_DEBUG_LOG_DIRECTORY',v_om_dbg_dir);
4051 --
4052 l_file_val := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
4053 --
4054 --oe_Debug_pub.setdebuglevel(5);
4055 --
4056 IF (l_debug <> -1) THEN
4057 rlm_core_sv.dlog(C_DEBUG, 'l_file_val',l_file_val);
4058 END IF;
4059 --
4060 LOOP --{
4061 /* Call OE_Order_GRP.Process_Order procedure to update OE_ORDER_LINES
4062 table by passing the g_oe_line_tbl structure that has been prepared
4063 this loop calls the process_order API once per each header_id,
4064 since the table is sorted by header_id then this loop
4065 calls the process_order once the header_id is changed */
4066 --
4067 IF g_oe_tmp_line_tbl(v_index3).header_id = v_header_id THEN --{
4068 --
4069 g_oe_line_tbl(v_index2) := g_oe_tmp_line_tbl(v_index3);
4070 --
4071 v_index2 := v_index2 + 1;
4072 --
4073 IF v_index3 = g_oe_tmp_line_tbl.LAST THEN --{
4074 -- process order for the last time
4075 OE_Order_GRP.Process_order(
4076 p_api_version_number => x_oe_api_version,
4077 p_init_msg_list => FND_API.G_TRUE,
4078 p_return_values => FND_API.G_FALSE,
4079 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
4080 x_return_status => l_return_status,
4081 x_msg_count => v_msg_count,
4082 x_msg_data => v_msg_data,
4083 ------------------------------------------
4084 p_line_tbl => g_oe_line_tbl,
4085 ------------------------------------------
4086 x_header_rec => g_oe_header_out_rec,
4087 x_header_val_rec => g_oe_header_val_out_rec,
4088 x_Header_Adj_tbl => g_oe_Header_Adj_out_tbl,
4089 x_Header_Adj_val_tbl => g_oe_Header_Adj_val_out_tbl,
4090 x_Header_price_Att_tbl => g_Header_price_Att_out_tbl,
4091 x_Header_Adj_Att_tbl => g_Header_Adj_Att_out_tbl,
4092 x_Header_Adj_Assoc_tbl => g_Header_Adj_Assoc_out_tbl,
4093 x_Header_Scredit_tbl => g_oe_Header_Scredit_out_tbl,
4094 x_Header_Scredit_val_tbl => g_oe_Hdr_Scdt_val_out_tbl,
4095 x_line_tbl => l_oe_line_tbl_out,
4096 x_line_val_tbl => g_oe_line_val_out_tbl,
4097 x_Line_Adj_tbl => g_oe_line_Adj_out_tbl,
4098 x_Line_Adj_val_tbl => g_oe_line_Adj_val_out_tbl,
4099 x_Line_price_Att_tbl => g_Line_price_Att_out_tbl,
4100 x_Line_Adj_Att_tbl => g_Line_Adj_Att_out_tbl,
4101 x_Line_Adj_Assoc_tbl => g_Line_Adj_Assoc_out_tbl,
4102 x_Line_Scredit_tbl => g_oe_line_scredit_out_tbl,
4103 x_Line_Scredit_val_tbl => g_oe_line_scredit_val_out_tbl,
4104 x_Lot_Serial_tbl => g_oe_lot_serial_out_tbl,
4105 x_Lot_Serial_val_tbl => g_oe_lot_serial_val_out_tbl,
4106 x_Action_Request_tbl => g_oe_Action_Request_out_Tbl) ;
4107 --
4108 IF (l_debug <> -1) THEN
4109 rlm_core_sv.dlog(C_DEBUG,'G_FILE',OE_DEBUG_PUB.G_FILE);
4110 rlm_core_sv.dlog(C_DEBUG, 'Input tbl count',
4111 g_oe_line_tbl.LAST);
4112 rlm_core_sv.dlog(C_DEBUG, 'Output tbl count',
4113 l_oe_line_tbl_out.LAST);
4114 END IF;
4115 --
4116 -- Handle the exceptions caused by the OE call
4117 --
4118
4119 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN --{
4120 --
4121 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4122 --}
4123 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN --{
4124 --
4125 RAISE FND_API.G_EXC_ERROR;
4126 --}
4127 ELSE --{
4128 --
4129 counter2 := counter2 + 1;
4130 x_return_status := TRUE;
4131 --
4132 IF (l_debug <> -1) THEN
4133 rlm_core_sv.dlog(C_DEBUG,
4134 'Order line is updated successfully');
4135 END IF;
4136 --
4137 rlm_message_sv.get_msg_text(
4138 x_message_name => 'RLM_CUM_RESET_TRAIL4',
4139 x_text => v_trail4);
4140 --
4141 fnd_file.put_line(fnd_file.output, v_trail1);
4142 fnd_file.put_line(fnd_file.output, v_trail2);
4143 fnd_file.put_line(fnd_file.output, v_trail3);
4144 fnd_file.put_line(fnd_file.output, v_trail4);
4145 --
4146 END IF; --}
4147 EXIT;
4148 --}
4149 --{ if not the last element
4150 ELSE
4151 --
4152 v_index3 := g_oe_tmp_line_tbl.NEXT(v_index3);
4153 --
4154 END IF; --}
4155 --}
4156 --{ if header_id has changed
4157 ELSE
4158 --
4159 v_header_id := g_oe_tmp_line_tbl(v_index3).header_id;
4160 --
4161 v_index2 := 1;
4162 --
4163
4164 OE_Order_GRP.Process_order(
4165 p_api_version_number => x_oe_api_version,
4166 p_init_msg_list => FND_API.G_TRUE,
4167 p_return_values => FND_API.G_FALSE,
4168 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
4169 x_return_status => l_return_status,
4170 x_msg_count => v_msg_count,
4171 x_msg_data => v_msg_data,
4172 ------------------------------------------
4173 p_line_tbl => g_oe_line_tbl,
4174 ------------------------------------------
4175 x_header_rec => g_oe_header_out_rec,
4176 x_header_val_rec => g_oe_header_val_out_rec,
4177 x_Header_Adj_tbl => g_oe_Header_Adj_out_tbl,
4178 x_Header_Adj_val_tbl => g_oe_Header_Adj_val_out_tbl,
4179 x_Header_price_Att_tbl => g_Header_price_Att_out_tbl,
4180 x_Header_Adj_Att_tbl => g_Header_Adj_Att_out_tbl,
4181 x_Header_Adj_Assoc_tbl => g_Header_Adj_Assoc_out_tbl,
4182 x_Header_Scredit_tbl => g_oe_Header_Scredit_out_tbl,
4183 x_Header_Scredit_val_tbl => g_oe_Hdr_Scdt_val_out_tbl,
4184 x_line_tbl => l_oe_line_tbl_out,
4185 x_line_val_tbl => g_oe_line_val_out_tbl,
4186 x_Line_Adj_tbl => g_oe_line_Adj_out_tbl,
4187 x_Line_Adj_val_tbl => g_oe_line_Adj_val_out_tbl,
4188 x_Line_price_Att_tbl => g_Line_price_Att_out_tbl,
4189 x_Line_Adj_Att_tbl => g_Line_Adj_Att_out_tbl,
4190 x_Line_Adj_Assoc_tbl => g_Line_Adj_Assoc_out_tbl,
4191 x_Line_Scredit_tbl => g_oe_line_scredit_out_tbl,
4192 x_Line_Scredit_val_tbl => g_oe_line_scredit_val_out_tbl,
4193 x_Lot_Serial_tbl => g_oe_lot_serial_out_tbl,
4194 x_Lot_Serial_val_tbl => g_oe_lot_serial_val_out_tbl,
4195 x_Action_Request_tbl => g_oe_Action_Request_out_Tbl) ;
4196 --
4197 -- Handle the exceptions caused by the OE call
4198 --
4199 IF (l_debug <> -1) THEN
4200 rlm_core_sv.dlog(C_DEBUG,'G_FILE',OE_DEBUG_PUB.G_FILE);
4201 rlm_core_sv.dlog(C_DEBUG, 'Input tbl count',
4202 g_oe_line_tbl.LAST);
4203 rlm_core_sv.dlog(C_DEBUG, 'Output tbl count',
4204 l_oe_line_tbl_out.LAST);
4205 END IF;
4206 --
4207 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN --{
4208 --
4209 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4210 --}
4211 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN --{
4212 --
4213 RAISE FND_API.G_EXC_ERROR;
4214 --}
4215 ELSE --{
4216 --
4217 counter2 := counter2 + 1;
4218 x_return_status := TRUE;
4219 --
4220 IF (l_debug <> -1) THEN
4221 rlm_core_sv.dlog(C_DEBUG,
4222 'Order line is updated successfully');
4223 END IF;
4224 --
4225 rlm_message_sv.get_msg_text(
4226 x_message_name => 'RLM_CUM_RESET_TRAIL4',
4227 x_text => v_trail4);
4228 --
4229 fnd_file.put_line(fnd_file.output, v_trail1);
4230 fnd_file.put_line(fnd_file.output, v_trail2);
4231 fnd_file.put_line(fnd_file.output, v_trail3);
4232 fnd_file.put_line(fnd_file.output, v_trail4);
4233 --
4234 END IF; --}
4235 --
4236 g_oe_line_tbl.DELETE;
4237 --
4238 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
4239 --
4240 g_oe_line_tbl(v_index2) := g_oe_tmp_line_tbl(v_index3);
4241 --
4242 END IF; --} if the header_id has not changed
4243 --
4244 END LOOP; --}
4245 --
4246 EXCEPTION
4247 --
4248 WHEN FND_API.G_EXC_ERROR THEN --{
4249 --
4250 x_return_status := FALSE;
4251 --
4252 -- Get message count and data
4253 --
4254 OE_MSG_PUB.Count_And_Get(
4255 p_count => v_msg_count,
4256 p_data => v_msg_data);
4257 --
4258 IF (l_debug <> -1) THEN
4259 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_ERROR');
4260 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status',
4261 l_return_status);
4262 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status',
4263 x_return_status);
4264 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_count', v_msg_count);
4265 rlm_core_sv.dlog(C_SDEBUG, 'Main v_msg_data', v_msg_data);
4266 END IF;
4267 --
4268 fnd_file.put_line(fnd_file.log, 'Process Order Error: '
4269 ||v_msg_data);
4270 fnd_file.put_line(fnd_file.log, ' ');
4271 --
4272 IF v_msg_count > 0 THEN --{
4273 --
4274 FOR k in 1 .. v_msg_count LOOP --{
4275 --
4276 v_msg_data := oe_msg_pub.get( p_msg_index => k,
4277 p_encoded=> 'F');
4278 --
4279 fnd_file.put_line(fnd_file.log, v_msg_data);
4280 --
4281 IF (l_debug <> -1) THEN
4282 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_data',
4283 v_msg_data);
4284 END IF;
4285 --
4286 END LOOP; --}
4287 --
4288 END IF; --}
4289 --
4290 IF (l_debug <> -1) THEN
4291 rlm_core_sv.dpop(C_SDEBUG,
4292 'Process Order Error. Rollback');
4293 END IF;
4294 --
4295 --
4296 rlm_message_sv.get_msg_text(
4297 x_message_name => 'RLM_CUM_RESET_TRAIL5',
4298 x_text => v_trail5);
4299 --
4300 fnd_file.put_line(fnd_file.output, v_trail1);
4301 fnd_file.put_line(fnd_file.output, v_trail2);
4302 fnd_file.put_line(fnd_file.output, v_trail3);
4303 fnd_file.put_line(fnd_file.output, v_trail4);
4304 fnd_file.put_line(fnd_file.output, v_trail5);
4305 --
4306 error_count := error_count+1;
4307 --
4308 ROLLBACK;
4309 --}
4310
4311 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4312 --{
4313 x_return_status := FALSE;
4314 --
4315 --
4316 -- Get message count and data
4317 --
4318 OE_MSG_PUB.Count_And_Get(
4319 p_count => v_msg_count,
4320 p_data => v_msg_data);
4321 --
4322 IF (l_debug <> -1) THEN
4323 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_UNEXPECTED_ERROR');
4324 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status',
4325 l_return_status);
4326 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status',
4327 x_return_status);
4328 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_count', v_msg_count);
4329 rlm_core_sv.dlog(C_SDEBUG, 'Main v_msg_data', v_msg_data);
4330 END IF;
4331 --
4332 fnd_file.put_line(fnd_file.log, 'Process Order Error: '
4333 ||v_msg_data);
4334 fnd_file.put_line(fnd_file.log, ' ');
4335 IF v_msg_count > 0 THEN --{
4336 --
4337 FOR k in 1 .. v_msg_count LOOP --{
4338 --
4339 v_msg_data := oe_msg_pub.get( p_msg_index => k,
4340 p_encoded=> 'F');
4341 --
4342 fnd_file.put_line(fnd_file.log, v_msg_data);
4343 --
4344 IF (l_debug <> -1) THEN
4345 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_data',
4346 v_msg_data);
4347 END IF;
4348 --
4349 END LOOP; --}
4350 --
4351 END IF; --}
4352 --
4353 IF (l_debug <> -1) THEN
4354 rlm_core_sv.dpop(C_SDEBUG,
4355 'Process Order Error. Rollback');
4356 END IF;
4357 --
4358 --
4359 fnd_file.put_line(fnd_file.log, 'Process Order Error: '
4360 ||v_msg_data);
4361 fnd_file.put_line(fnd_file.log, ' ');
4362 --
4363 rlm_message_sv.get_msg_text(
4364 x_message_name => 'RLM_CUM_RESET_TRAIL5',
4365 x_text => v_trail5);
4366 --
4367 fnd_file.put_line(fnd_file.output, v_trail1);
4368 fnd_file.put_line(fnd_file.output, v_trail2);
4369 fnd_file.put_line(fnd_file.output, v_trail3);
4370 fnd_file.put_line(fnd_file.output, v_trail4);
4371 fnd_file.put_line(fnd_file.output, v_trail5);
4372 --
4373 error_count := error_count+1;
4374 --
4375 ROLLBACK;
4376 --}
4377 WHEN OTHERS THEN
4378 --{
4379 x_return_status := FALSE;
4380 --
4381 -- Get message count and data
4382 --
4383 OE_MSG_PUB.Count_And_Get(
4384 p_count => v_msg_count,
4385 p_data => v_msg_data);
4386 --
4387 IF (l_debug <> -1) THEN
4388 rlm_core_sv.dlog(C_SDEBUG, 'WHEN OTHERS');
4389 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status',
4390 l_return_status);
4391 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status',
4392 x_return_status);
4393 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_count', v_msg_count);
4394 rlm_core_sv.dlog(C_SDEBUG, 'Main v_msg_data', v_msg_data);
4395 END IF;
4396 --
4397 fnd_file.put_line(fnd_file.log, 'Process Order Error: '
4398 ||v_msg_data);
4399 fnd_file.put_line(fnd_file.log, ' ');
4400 --
4401 IF v_msg_count > 0 THEN --{
4402 --
4403 FOR k in 1 .. v_msg_count LOOP --{
4404 --
4405 v_msg_data := oe_msg_pub.get( p_msg_index => k,
4406 p_encoded=> 'F');
4407 --
4408 fnd_file.put_line(fnd_file.log, v_msg_data);
4409 --
4410 IF (l_debug <> -1) THEN
4411 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_data',
4412 v_msg_data);
4413 END IF;
4414 --
4415 END LOOP; --}
4416 --
4417 END IF; --}
4418 --
4419 IF (l_debug <> -1) THEN
4420 rlm_core_sv.dpop(C_SDEBUG,
4421 'Process Order Error. Rollback');
4422 END IF;
4423 --
4424 fnd_file.put_line(fnd_file.log, 'Process Order Error: '
4425 || v_msg_data);
4426 fnd_file.put_line(fnd_file.log, ' ');
4427 --
4428 rlm_message_sv.get_msg_text(
4429 x_message_name => 'RLM_CUM_RESET_TRAIL5',
4430 x_text => v_trail5);
4431 --
4432 fnd_file.put_line(fnd_file.output, v_trail1);
4433 fnd_file.put_line(fnd_file.output, v_trail2);
4434 fnd_file.put_line(fnd_file.output, v_trail3);
4435 fnd_file.put_line(fnd_file.output, v_trail4);
4436 fnd_file.put_line(fnd_file.output, v_trail5);
4437 --
4438 error_count := error_count+1;
4439 --
4440 ROLLBACK;
4441 --}
4442 END; --}
4443 -- DEBUGGING
4444 --
4445 END IF; -- v_terms_level }
4446 --}
4447 ELSE --{
4448 --
4449 v_msg_data := 'Adjust CUM Transactions is not processed against NO_CUM and CUM_BY_PO_ONLY CUM management types';
4450 --
4451 IF (l_debug <> -1) THEN
4452 rlm_core_sv.dlog(C_DEBUG, v_msg_data);
4453 END IF;
4454 --
4455 fnd_file.put_line(fnd_file.log, v_msg_data);
4456 --
4457 END IF; -- cum_control_code }
4458 --}
4459 ELSE --{
4460 --
4461 v_msg_data := 'Release Management setup terms are not found';
4462 --
4463 IF (l_debug <> -1) THEN
4464 rlm_core_sv.dlog(C_DEBUG, v_msg_data);
4465 END IF;
4466 --
4467 fnd_file.put_line(fnd_file.log, v_msg_data);
4468 --
4469 END IF; -- setup_terms_status }
4470 --
4471 v_msg_data := 'Number of lines eligible for adjustment: ';
4472 --
4473 IF (l_debug <> -1) THEN
4474 rlm_core_sv.dlog(C_DEBUG, v_msg_data, counter -1);
4475 END IF;
4476 --
4477 --fnd_file.put_line(fnd_file.log, v_msg_data ||counter2);
4478 --
4479 IF error_count > 0 THEN --{
4480 --
4481 v_msg_data := 'Completed with errors';
4482 --
4483 IF (l_debug <> -1) THEN
4484 rlm_core_sv.dpop(C_DEBUG, v_msg_data);
4485 END IF;
4486 --
4487 fnd_file.put_line(fnd_file.log, v_msg_data);
4488 -- }
4489 ELSE
4490 -- {
4491 IF (l_debug <> -1) THEN
4492 rlm_core_sv.dlog(C_DEBUG, 'v_old_cum_records.COUNT',
4493 v_old_cum_records.COUNT);
4494 END IF;
4495 --
4496 IF v_old_cum_records.COUNT > 0 THEN
4497 --
4498 UpdateOldKey( v_old_cum_records,
4499 v_cum_records(1).shipment_rule_code,
4500 v_cum_records(1).yesterday_time_cutoff,
4501 v_cum_key_record,
4502 p_ship_from_org_id,
4503 p_ship_to_org_id,
4504 p_intmed_ship_to_org_id,
4505 p_bill_to_org_id,
4506 x_customer_item_id,
4507 v_return_status);
4508 --
4509 IF v_return_status THEN
4510 --
4511 v_msg_data := 'Completed successfully';
4512 --
4513 COMMIT;
4514 --
4515 ELSE
4516 --
4517 v_msg_data := 'Update old CUM key error. Rollback';
4518 --
4519 ROLLBACK;
4520 --
4521 END IF;
4522 --
4523 ELSE
4524 --
4525 v_msg_data := 'Completed successfully';
4526 --
4527 END IF;
4528 --
4529 IF (l_debug <> -1) THEN
4530 rlm_core_sv.dpop(C_DEBUG, v_msg_data);
4531 END IF;
4532 --
4533 fnd_file.put_line(fnd_file.log, v_msg_data);
4534 --
4535 END IF;--} if error_count = 0
4536 --
4537 EXCEPTION
4538 --
4539 WHEN NO_DATA_FOUND THEN
4540 --
4541 IF v_level = 'SHIP_TO_ADDRESS_ID' THEN
4542 --
4543 IF (l_debug <> -1) THEN
4544 rlm_core_sv.dlog(C_SDEBUG,
4545 'No ship_to_address_id is associated with the ship_to_org_id');
4546 END IF;
4547 --
4548 ELSIF v_level = 'INTRMD_SHIP_TO_ADDRESS_ID' THEN
4549 --
4550 IF (l_debug <> -1) THEN
4551 rlm_core_sv.dlog(C_SDEBUG,
4552 'No intrmd_ship_to_address_id is associated with the'
4553 ||' intmed_ship_to_org_id');
4554 END IF;
4555 --
4556 ELSIF v_level = 'CUSTOMER_ID' THEN
4557 --
4558 IF (l_debug <> -1) THEN
4559 rlm_core_sv.dlog(C_SDEBUG,
4560 'No customer_id is associated with the address_id');
4561 END IF;
4562 --
4563 ELSIF v_level = 'BILL_TO_ADDRESS_ID' THEN
4564 --
4565 IF (l_debug <> -1) THEN
4566 rlm_core_sv.dlog(C_SDEBUG,
4567 'No bill_to_address_id is associated with the bill_to_org_id');
4568 END IF;
4569 --
4570 ELSIF v_level = 'SHIP_TO_ADDRESS_ID2' THEN
4571 --
4572 IF (l_debug <> -1) THEN
4573 rlm_core_sv.dlog(C_SDEBUG,
4574 'Second time: No ship_to_address_id is associated with the'
4575 ||' ship_to_org_id');
4576 END IF;
4577 --
4578 ELSIF v_level = 'INTRMD_SHIP_TO_ADDRESS_ID2' THEN
4579 --
4580 IF (l_debug <> -1) THEN
4581 rlm_core_sv.dlog(C_SDEBUG,
4582 'Second time: No intrmd_ship_to_address_id is associated '
4583 ||'with the intmed_ship_to_org_id');
4584 END IF;
4585 --
4586 ELSIF v_level = 'BILL_TO_ADDRESS_ID2' THEN
4587 --
4588 IF (l_debug <> -1) THEN
4589 rlm_core_sv.dlog(C_SDEBUG,
4590 'Second time: No bill_to_address_id is associated with the'
4591 || ' bill_to_org_id');
4592 END IF;
4593 --
4594 END IF;
4595 --
4596 ROLLBACK;
4597 --
4598 IF (l_debug <> -1) THEN
4599 rlm_core_sv.dpop(C_SDEBUG, 'No data found');
4600 END IF;
4601 --
4602 WHEN e_NoCum THEN
4603 --
4604 --ROLLBACK;
4605 COMMIT;
4606 --
4607 v_msg_data := 'There are no qualifying shipments.';
4608 --
4609 fnd_file.put_line(fnd_file.log,v_msg_data);
4610 --
4611 IF (l_debug <> -1) THEN
4612 rlm_core_sv.dpop(C_SDEBUG,'ResetCum:e_NoCum');
4613 END IF;
4614 --
4615 WHEN e_NoShipment THEN
4616 --
4617 v_msg_data := 'There are no qualifying shipments. Manual adjustments'
4618 ||' would be processed';
4619 --
4620 fnd_file.put_line(fnd_file.log,v_msg_data);
4621 --
4622 BEGIN
4623 --
4624 IF (l_debug <> -1) THEN
4625 rlm_core_sv.dlog(C_DEBUG, 'v_old_cum_records.COUNT',
4626 v_old_cum_records.COUNT);
4627 END IF;
4628 --
4629 IF v_old_cum_records.COUNT > 0 THEN
4630 --
4631 UpdateOldKey( v_old_cum_records,
4632 v_cum_records(1).shipment_rule_code,
4633 v_cum_records(1).yesterday_time_cutoff,
4634 v_cum_key_record,
4635 p_ship_from_org_id,
4636 p_ship_to_org_id,
4637 p_intmed_ship_to_org_id,
4638 p_bill_to_org_id,
4639 x_customer_item_id,
4640 v_return_status);
4641 --
4642 IF v_return_status THEN
4643 --
4644 v_msg_data := 'Completed successfully';
4645 --
4646 COMMIT;
4647 --
4648 ELSE
4649 --
4650 v_msg_data := 'Update old CUM key error. Rollback';
4651 --
4652 ROLLBACK;
4653 --
4654 END IF;
4655 --
4656 fnd_file.put_line(fnd_file.log,v_msg_data);
4657 --
4658 ELSE
4659 --
4660 v_msg_data := 'Completed successfully';
4661 --
4662 fnd_file.put_line(fnd_file.log,v_msg_data);
4663 --
4664 END IF;
4665 --
4666 COMMIT;
4667 --
4668 EXCEPTION
4669 WHEN OTHERS THEN
4670 --
4671 IF (l_debug <> -1) THEN
4672 rlm_core_sv.dlog(C_DEBUG, 'when others::',substr(SQLERRM,1,200));
4673 END IF;
4674 --
4675 fnd_file.put_line(fnd_file.log, substr(SQLERRM,1,200));
4676 --
4677 x_return_status := FALSE;
4678 END;
4679 --
4680 IF (l_debug <> -1) THEN
4681 rlm_core_sv.dpop(C_SDEBUG,'ResetCum:e_NoShipment');
4682 END IF;
4683 --
4684 WHEN OTHERS THEN
4685 --
4686 IF (l_debug <> -1) THEN
4687 rlm_core_sv.dpop(C_SDEBUG, substr(SQLERRM,1,200));
4688 END IF;
4689 --
4690 fnd_file.put_line(fnd_file.log, substr(SQLERRM,1,200));
4691 --
4692 x_return_status := FALSE;
4693 --
4694 ROLLBACK;
4695 --
4696 END ResetCum;
4697
4698
4699
4700 /*============================================================================
4701
4702 PROCEDURE NAME: GetCums
4703
4704
4705 This procedure is called by reset cum. According to the parameters and
4706 the setup terms for the cum, it gets all the cum records from
4707 rlm_cust_item_cum_keys. From the records returned, the program filters
4708 out those recors which do not have any manual adjustments within the period
4709 nor any shipments(if there is any shipment the field last_cum_qty_update_date
4710 would be within the time frame). These records would be sorted, so that all
4711 corresponding Cums are in sorted together(for example same customer items
4712 may be sorted together). The program recognizes the first record of each
4713 group as the newly created CUM and the reset of the group as the CUMs which
4714 are being adjusted. It then puts all the new cums in one table and all the
4715 old one in a different table.
4716
4717
4718 PARAMETERS:
4719
4720 ** x_rlm_setup_terms_record IN
4721 This is setupterms generated from the resetCums parameters
4722 ** x_terms_level IN
4723 This is the same as parameter x_terms_definition_level of
4724 rlm_setup_terms_sv.get_setup_terms
4725 ** x_cum_key_record IN
4726 This records would containe the followings if it could be derived in
4727 resetcum
4728 bill_to_address_id, ship_to_address_id, intrmd_ship_to_address_id,
4729 ship_from_org_id,customer_item_id,customer_id
4730 ** x_transaction_start_date IN
4731 same as parameter in resetcum
4732 ** x_transaction_end_date IN
4733 same as parameter in resetcum would be defaulted to sysdate
4734 ** x_cum_records OUT NOCOPY
4735 These are records of all new cum_keys created
4736 ** x_old_cum_records OUT NOCOPY
4737 These are all old_cums which either have shipment or manual adjustments
4738 ** x_counter OUT NOCOPY
4739 This is a table that indicates the relation ship between x_cum_records
4740 and x_old_cum_records. For example, if x_cum_records(3) has
4741 2 records in the old cums table x_old_cum_records, then
4742 x_counter(3) would have the value 2
4743 ** x_return_status OUT NOCOPY
4744 1 if any cums found to be adjusted, 0 if no cum
4745
4746 =============================================================================*/
4747
4748 PROCEDURE GetCums (
4749 x_rlm_setup_terms_record IN rlm_setup_terms_sv.setup_terms_rec_typ,
4750 x_terms_level IN VARCHAR2,
4751 x_cum_key_record IN OUT NOCOPY rlm_cum_sv.cum_key_attrib_rec_type,
4752 x_transaction_start_date IN DATE,
4753 x_transaction_end_date IN DATE ,
4754 x_ship_from_org_id IN NUMBER,
4755 x_ship_to_org_id IN NUMBER,
4756 x_intmed_ship_to_org_id IN NUMBER,
4757 x_bill_to_org_id IN NUMBER,
4758 x_cum_records OUT NOCOPY RLM_CUM_SV.t_cums,
4759 x_old_cum_records OUT NOCOPY RLM_CUM_SV.t_cums,
4760 x_counter OUT NOCOPY RLM_CUM_SV.t_new_ship_count,
4761 x_return_status OUT NOCOPY NUMBER)
4762 IS
4763 v_cum_control_code rlm_cust_shipto_terms.cum_control_code%TYPE;
4764 v_cum_org_level_code rlm_cust_shipto_terms.cum_org_level_code%TYPE;
4765 v_tmp_cum_record rlm_cum_sv.cum_rec_type;
4766 v_address_id NUMBER;
4767 v_cum_rec_ctr NUMBER DEFAULT 0;
4768 v_old_cum_ctr NUMBER DEFAULT 0;
4769 v_counter_ctr NUMBER DEFAULT 0;
4770 v_exist NUMBER;
4771 v_new_customer_item_id NUMBER DEFAULT 0;
4772 v_old_customer_item_id NUMBER DEFAULT 0;
4773 p_ship_from_org_id NUMBER DEFAULT NULL;
4774 p_ship_to_address_id NUMBER DEFAULT NULL;
4775 p_intrmd_ship_to_address_id NUMBER DEFAULT NULL;
4776 p_bill_to_address_id NUMBER DEFAULT NULL;
4777 p_customer_item_id NUMBER DEFAULT NULL;
4778 msg_data VARCHAR2(2500);
4779 msg_name VARCHAR2(30) DEFAULT NULL;
4780 v_new_purchase_order_number RLM_CUST_ITEM_CUM_KEYS.PURCHASE_ORDER_NUMBER%TYPE DEFAULT NULL;
4781 v_new_cust_record_year RLM_CUST_ITEM_CUM_KEYS.CUST_RECORD_YEAR%TYPE
4782 DEFAULT NULL;
4783 v_ship_from_org_name VARCHAR2(250);
4784 v_customer_name VARCHAR2(360);
4785 v_ship_to_location VARCHAR2(250);
4786 v_customer_item_number VARCHAR2(250);
4787 v_new_cum_start_date DATE DEFAULT NULL;
4788
4789 /* these strings will create the cursor that contains the cum keys*/
4790
4791 v_select VARCHAR2(3600);
4792 v_where_clause VARCHAR2(3600);
4793 v_statment VARCHAR2(3600);
4794 v_shipment_count NUMBER;
4795
4796 E_UNEXPECTED EXCEPTION;
4797
4798 TYPE ref_cum_t IS REF CURSOR;
4799 c_cum_keys ref_cum_t;
4800 --
4801
4802
4803 BEGIN --{
4804 --
4805 IF (l_debug <> -1) THEN
4806 rlm_core_sv.dpush(C_SDEBUG, 'GetCums');
4807 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id',
4808 x_cum_key_record.ship_from_org_id);
4809 rlm_core_sv.dlog(C_DEBUG, 'customer_item_id',
4810 x_cum_key_record.customer_item_id);
4811 rlm_core_sv.dlog(C_DEBUG,'Ship_to_address_id',
4812 x_cum_key_record.ship_to_address_id);
4813 rlm_core_sv.dlog(C_DEBUG,'intrmd_ship_to_address_id',
4814 x_cum_key_record.intrmd_ship_to_address_id);
4815 rlm_core_sv.dlog(C_DEBUG,'bill_to_address_id',
4816 x_cum_key_record.bill_to_address_id);
4817 rlm_core_sv.dlog(C_DEBUG,'x_terms_level'
4818 ,x_terms_level);
4819 END IF;
4820 --
4821 --return status of zero indicates that procedure did not find any
4822 --cum records, return status of 1 tells there are some records found
4823 x_return_status := 1;
4824
4825 -- Determine whether to use Ship To or Intermediate Ship To
4826 --
4827 IF x_cum_key_record.intrmd_ship_to_address_id IS NULL THEN --{
4828 --
4829 IF x_cum_key_record.ship_to_address_id IS NULL THEN --{
4830 --
4831 msg_name := 'RLM_CUM_ADDRESS_REQUIRED';
4832 rlm_message_sv.get_msg_text(
4833 x_message_name => msg_name,
4834 x_text => msg_data);
4835 --
4836 RAISE E_UNEXPECTED;
4837 --
4838 ELSE
4839 --
4840 v_address_id := x_cum_key_record.ship_to_address_id;
4841 --
4842 END IF; --}
4843 --
4844 ELSE
4845 --
4846 IF x_cum_key_record.ship_to_address_id IS NULL THEN
4847 --
4848 v_address_id := x_cum_key_record.intrmd_ship_to_address_id;
4849 --
4850 ELSE
4851 --
4852 v_address_id := x_cum_key_record.ship_to_address_id;
4853 --
4854 END IF;
4855 --
4856 END IF; --}
4857 --
4858 IF (l_debug <> -1) THEN
4859 rlm_core_sv.dlog(C_DEBUG, 'address_id', v_address_id);
4860 END IF;
4861 --
4862 -- Get the CUM Control Code from the setup terms table
4863 --
4864 v_cum_control_code := x_rlm_setup_terms_record.cum_control_code;
4865 --
4866 IF (l_debug <> -1) THEN
4867 rlm_core_sv.dlog(C_DEBUG, 'v_cum_control_code',v_cum_control_code);
4868 END IF;
4869 --
4870 IF x_rlm_setup_terms_record.cum_control_code IS NULL THEN --{
4871 --
4872 msg_name := 'RLM_CUM_CTRLCD_REQUIRED';
4873 --
4874 rlm_message_sv.get_msg_text(
4875 x_message_name => msg_name,
4876 x_text => msg_data);
4877 --
4878 RAISE E_UNEXPECTED;
4879 --}
4880 /*
4881 ELSE
4882 --{
4883
4884 IF (x_terms_level = 'CUSTOMER_ITEM')
4885 AND (nvl(x_rlm_setup_terms_record.calc_cum_flag,'N') <> 'Y') THEN --{
4886 we do not need this check anymore. We can get all setup information for
4887 cum at the address level. calc_cum_flag is the only field that could be
4888 different at the customer item level. However, we check later on that
4889 all items should have a new cum key and also shipment/adjustments during
4890 the transactions
4891 --
4892 v_ship_from_org_name := RLM_CORE_SV.get_ship_from(x_cum_key_record.ship_from_org_id);
4893 v_customer_name := RLM_CORE_SV.get_customer_name(x_cum_key_record.customer_id);
4894 v_ship_to_location := RLM_CORE_SV.get_ship_to(v_address_id);
4895 v_customer_item_number := RLM_CORE_SV.get_item_number(x_cum_key_record.customer_item_id);
4896 --
4897 msg_name := 'RLM_CUM_NO_CALC_FLAG';
4898 --
4899 rlm_message_sv.get_msg_text(
4900 x_message_name => msg_name,
4901 x_text => msg_data,
4902 x_token1 => 'CI',
4903 x_value1 => v_customer_item_number);
4904 --
4905 RAISE E_UNEXPECTED;
4906 --
4907 END IF; --}
4908 */
4909 --
4910 END IF; --}
4911
4912 --
4913 -- CUM Organization Level
4914 --
4915 v_cum_org_level_code := x_rlm_setup_terms_record.cum_org_level_code;
4916 --
4917 /* Customer Item Id is always populated in the CUM Key table regardless of
4918 CUM control code or CUM Organization Level. Ship From Organization Id
4919 is always populated in the CUM Key table except for the case of
4920 ALL_SHIP_FROMS. Therefore, the switches below are turned ON and
4921 assigned to the associated parameters passed by the calling program */
4922 --
4923 p_customer_item_id := x_cum_key_record.customer_item_id;
4924 p_ship_from_org_id := x_cum_key_record.ship_from_org_id;
4925 --
4926 --Turn ON switches based on cum control code
4927 --
4928 IF (l_debug <> -1) THEN
4929 rlm_core_sv.dlog(C_DEBUG, 'cum_control_code',
4930 x_rlm_setup_terms_record.cum_control_code);
4931 END IF;
4932 --
4933 IF v_cum_org_level_code = 'BILL_TO_SHIP_FROM' THEN
4934 --
4935 IF x_cum_key_record.bill_to_address_id IS NULL THEN
4936 --
4937 msg_name := 'RLM_CUM_BILL_TO_REQUIRED';
4938 --
4939 rlm_message_sv.get_msg_text(
4940 x_message_name => msg_name,
4941 x_text => msg_data);
4942 --
4943 RAISE E_UNEXPECTED;
4944 --
4945 END IF;
4946 --
4947 p_bill_to_address_id := x_cum_key_record.bill_to_address_id;
4948 --
4949 ELSIF v_cum_org_level_code = 'SHIP_TO_SHIP_FROM' THEN
4950 --
4951 IF x_cum_key_record.ship_to_address_id IS NULL THEN
4952 --
4953 msg_name := 'RLM_CUM_SHIP_TO_REQUIRED';
4954 --
4955 rlm_message_sv.get_msg_text(
4956 x_message_name => msg_name,
4957 x_text => msg_data);
4958 --
4959 RAISE E_UNEXPECTED;
4960 --
4961 END IF;
4962 --
4963 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
4964 --
4965 ELSIF v_cum_org_level_code = 'INTRMD_SHIP_TO_SHIP_FROM' THEN
4966 --
4967 IF x_cum_key_record.intrmd_ship_to_address_id IS NULL THEN
4968 --
4969 msg_name := 'RLM_CUM_INTER_SHIP_TO_REQUIRED' ;
4970 --
4971 rlm_message_sv.get_msg_text(
4972 x_message_name => msg_name,
4973 x_text => msg_data);
4974 --
4975 RAISE E_UNEXPECTED;
4976 --
4977 END IF;
4978 --
4979 p_intrmd_ship_to_address_id := x_cum_key_record.intrmd_ship_to_address_id;
4980 --
4981 ELSIF v_cum_org_level_code = 'SHIP_TO_ALL_SHIP_FROMS' THEN
4982 --
4983 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
4984 p_ship_from_org_id := NULL;
4985 --
4986 ELSE
4987 --
4988 msg_name := 'RLM_CUM_UNKNOWN_ORG_LEVEL';
4989 --
4990 rlm_message_sv.get_msg_text(
4991 x_message_name => msg_name,
4992 x_text => msg_data);
4993 --
4994 RAISE E_UNEXPECTED;
4995 --
4996 END IF;
4997 --
4998 --
4999 --Build the cursor dynamicly
5000 --
5001 v_select := 'SELECT cum_key_id, cum_qty, cum_qty_to_be_accumulated, cum_qty_after_cutoff,
5002 last_cum_qty_update_date,cust_uom_code,cum_start_date,
5003 cust_record_year,purchase_order_number ,customer_item_id
5004 FROM RLM_CUST_ITEM_CUM_KEYS
5005 ';
5006
5007 IF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_ONLY'
5008 OR x_rlm_setup_terms_record.cum_control_code = 'CUM_UNTIL_MANUAL_RESET'
5009 THEN
5010 --
5011 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN
5012 --
5013 /* ---------------------------------------------
5014 This cursor is used when the proc is called by ResetCum and the cum
5015 control code is cum by date only and the cum organization level is not
5016 for all ship froms ------------------------------------ */
5017
5018 v_where_clause := '
5019 WHERE NVL(ship_from_org_id,0)= NVL('''||p_ship_from_org_id||''',0)
5020 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5021 AND NVL(intrmd_ship_to_id,0)
5022 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5023 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5024 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5025 ('''||p_customer_item_id||''' IS NULL))
5026 AND cum_start_date IS NOT NULL
5027 AND cum_start_date < SYSDATE
5028 AND purchase_order_number IS NULL
5029 AND cust_record_year IS NULL
5030 AND NVL(inactive_flag,''N'') = ''N''
5031 ORDER BY customer_item_id,creation_date DESC,cum_start_date DESC';
5032 ELSE
5033 --
5034 /*-------------------------------------------------------------------
5035 This cursor is used when the proc is called by ResetCum and the cum
5036 control code is cum by date only and the cum organization level is for
5037 all ship froms ----------------------------------------------------*/
5038
5039 v_where_clause:='
5040 WHERE ship_from_org_id IS NULL
5041 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5042 AND NVL(intrmd_ship_to_id,0)
5043 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5044 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5045 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5046 ('''||p_customer_item_id||''' IS NULL))
5047 AND cum_start_date IS NOT NULL
5048 AND cum_start_date < SYSDATE
5049 AND purchase_order_number IS NULL
5050 AND cust_record_year IS NULL
5051 AND NVL(inactive_flag,''N'') = ''N''
5052 ORDER BY customer_item_id,creation_date DESC,cum_start_date DESC';
5053 --
5054 END IF;
5055 --
5056 ELSIF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_RECORD_YEAR'
5057 THEN
5058 --
5059 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN
5060 --
5061 /* --------------------------------------------------------------------
5062 This cursor is used when the proc is called by ResetCum and the cum
5063 control code is cum by date/record year and the cum organization level
5064 is not for all ship froms -----------------------------------------*/
5065
5066 v_where_clause:='
5067 WHERE NVL(ship_from_org_id,0) = NVL('''||p_ship_from_org_id||''',0)
5068 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5069 AND NVL(intrmd_ship_to_id,0)
5070 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5071 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5072 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5073 ('''||p_customer_item_id||''' IS NULL))
5074 AND cum_start_date IS NOT NULL
5075 AND cum_start_date < SYSDATE
5076 AND purchase_order_number IS NULL
5077 AND cust_record_year IS NOT NULL
5078 AND NVL(inactive_flag,''N'') = ''N''
5079 ORDER BY customer_item_id,creation_date DESC,cum_start_date DESC,cust_record_year DESC';
5080 --
5081 ELSE
5082 --
5083 /* ---------------------------------------------------------------------
5084 This cursor is used when the proc is called by ResetCum and the cum
5085 control code is cum by date/record year and the cum organization level
5086 is for all ship froms -----------------------------------------------*/
5087
5088 v_where_clause :='
5089 WHERE ship_from_org_id IS NULL
5090 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5091 AND NVL(intrmd_ship_to_id,0)
5092 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5093 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5094 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5095 ('''||p_customer_item_id||''' IS NULL))
5096 AND cum_start_date IS NOT NULL
5097 AND cum_start_date < SYSDATE
5098 AND purchase_order_number IS NULL
5099 AND cust_record_year IS NOT NULL
5100 AND NVL(inactive_flag,''N'') = ''N''
5101 ORDER BY customer_item_id,creation_date DESC,cum_start_date DESC,cust_record_year DESC';
5102 --
5103 END IF;
5104 --
5105 ELSIF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_PO' THEN
5106 --
5107 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN
5108 --
5109 /* ---------------------------------------------------------------------
5110 This cursor is used when the proc is called by ResetCum and the cum
5111 control code is cum by date/po and the cum organization level is not for
5112 all ship froms -------------------------------------------------------*/
5113
5114 v_where_clause :='
5115 WHERE NVL(ship_from_org_id,0) = NVL('''||p_ship_from_org_id||''',0)
5116 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5117 AND NVL(intrmd_ship_to_id,0)
5118 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5119 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5120 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5121 ('''||p_customer_item_id||''' IS NULL))
5122 AND cum_start_date IS NOT NULL
5123 AND cum_start_date < SYSDATE
5124 AND purchase_order_number IS NOT NULL
5125 AND cust_record_year IS NULL
5126 AND NVL(inactive_flag,''N'') = ''N''
5127 ORDER BY customer_item_id,creation_date DESC, cum_start_date DESC, purchase_order_number DESC ';
5128 --
5129 ELSE
5130 --
5131 /*------------------------------------------------------------------------
5132 This cursor is used when the proc is called by ResetCum and the cum
5133 control code is cum by date/po and the cum organization level is for
5134 all ship froms ------------------------------------------------------*/
5135
5136 v_where_clause := '
5137 WHERE ship_from_org_id IS NULL
5138 AND NVL(ship_to_address_id,0)= NVL('''||p_ship_to_address_id||''',0)
5139 AND NVL(intrmd_ship_to_id,0)
5140 = NVL('''||p_intrmd_ship_to_address_id||''',0)
5141 AND NVL(bill_to_address_id,0)= NVL('''||p_bill_to_address_id||''',0)
5142 AND ((customer_item_id = '''||p_customer_item_id||''') OR
5143 ('''||p_customer_item_id||''' IS NULL))
5144 AND cum_start_date IS NOT NULL
5145 AND cum_start_date < SYSDATE
5146 AND purchase_order_number IS NOT NULL
5147 AND cust_record_year IS NULL
5148 AND NVL(inactive_flag,''N'') = ''N''
5149 ORDER BY customer_item_id,creation_date DESC,cum_start_date DESC, purchase_order_number DESC';
5150
5151 END IF;
5152 --
5153 END IF;
5154 --
5155 v_statment := v_select || v_where_clause;
5156 --
5157 IF (l_debug <> -1) THEN
5158 rlm_core_sv.dlog(C_DEBUG,v_statment);
5159 END IF;
5160 --
5161 OPEN c_cum_keys FOR v_statment;
5162 LOOP --{
5163 FETCH c_cum_keys
5164 INTO v_tmp_cum_record.cum_key_id,
5165 v_tmp_cum_record.cum_qty,
5166 v_tmp_cum_record.cum_qty_to_be_accumulated,
5167 v_tmp_cum_record.cum_qty_after_cutoff,
5168 v_tmp_cum_record.last_cum_qty_update_date,
5169 v_tmp_cum_record.cust_uom_code,
5170 v_tmp_cum_record.cum_start_date,
5171 v_new_cust_record_year,
5172 v_new_purchase_order_number,
5173 v_new_customer_item_id;
5174 --
5175 EXIT WHEN c_cum_keys%NOTFOUND;
5176 --
5177 BEGIN --{
5178 v_exist := 1;
5179
5180 v_tmp_cum_record.customer_item_id := v_new_customer_item_id;
5181 --
5182 v_new_cum_start_date := v_tmp_cum_record.cum_start_date;
5183 --
5184 IF (v_new_customer_item_id <> v_old_customer_item_id) THEN --{
5185 --
5186 v_old_customer_item_id := v_new_customer_item_id;
5187 v_cum_rec_ctr := v_cum_rec_ctr +1;
5188 --
5189 IF(v_cum_rec_ctr - v_counter_ctr) <> 1 THEN --{
5190 --
5191 IF x_cum_records.EXISTS(v_cum_rec_ctr-1) THEN
5192 fnd_file.put_line(fnd_file.log,'Could not find '
5193 ||'corresponding CumKey for cum_key_id: ' ||
5194 x_cum_records(v_cum_rec_ctr-1).cum_key_id);
5195 --
5196 IF (l_debug <> -1) THEN
5197 rlm_core_sv.dlog(C_DEBUG,'Could not find correspounding'
5198 || ' CumKey for cum_key_id: ',
5199 x_cum_records(v_cum_rec_ctr-1).cum_key_id);
5200 END IF;
5201 --
5202 ELSE
5203 --
5204 IF (l_debug <> -1) THEN
5205 rlm_core_sv.dlog(C_DEBUG,'Could not find correspounding'
5206 || ' CumKey for cum_key_id: ',v_tmp_cum_record.cum_key_id);
5207 END IF;
5208 --
5209 END IF;
5210 --
5211 v_cum_rec_ctr := v_cum_rec_ctr -1;
5212 --
5213 END IF; --}
5214 --
5215 x_cum_records(v_cum_rec_ctr).cum_key_id :=
5216 v_tmp_cum_record.cum_key_id;
5217 --
5218 IF (l_debug <> -1) THEN
5219 rlm_core_sv.dlog(C_SDEBUG,'x_cum_records(v_cum_rec_ctr).cum_key_id',
5220 x_cum_records(v_cum_rec_ctr).cum_key_id);
5221 END IF;
5222 --
5223 x_counter(v_cum_rec_ctr) := 0;
5224 --
5225 x_cum_records(v_cum_rec_ctr).cum_qty := v_tmp_cum_record.cum_qty;
5226 --
5227 x_cum_records(v_cum_rec_ctr).cum_qty_to_be_accumulated :=
5228 v_tmp_cum_record.cum_qty_to_be_accumulated;
5229 x_cum_records(v_cum_rec_ctr).cum_qty_after_cutoff :=
5230 v_tmp_cum_record.cum_qty_after_cutoff;
5231 x_cum_records(v_cum_rec_ctr).last_cum_qty_update_date :=
5232 v_tmp_cum_record.last_cum_qty_update_date;
5233 x_cum_records(v_cum_rec_ctr).cust_uom_code :=
5234 v_tmp_cum_record.cust_uom_code;
5235 x_cum_records(v_cum_rec_ctr).cum_start_date :=
5236 v_tmp_cum_record.cum_start_date;
5237 x_cum_records(v_cum_rec_ctr).customer_item_id :=
5238 v_tmp_cum_record.customer_item_id;
5239
5240 --}
5241 /*
5242 else if the customer_item_id has not changed see if there are
5243 old cum with shipment or manual adjustment for it
5244 */
5245 ELSE --{
5246 --
5247 SELECT COUNT(*)
5248 INTO v_shipment_count
5249 FROM oe_order_lines
5250 WHERE (ship_from_org_id = x_ship_from_org_id
5251 OR x_ship_from_org_id IS NULL)
5252 AND (ship_to_org_id = x_ship_to_org_id
5253 OR x_ship_to_org_id IS NULL)
5254 AND (intmed_ship_to_org_id = x_intmed_ship_to_org_id
5255 OR x_intmed_ship_to_org_id IS NULL)
5256 AND (invoice_to_org_id = x_bill_to_org_id
5257 OR x_bill_to_org_id IS NULL)
5258 AND ordered_item_id = v_new_customer_item_id
5259 AND actual_shipment_date >= x_transaction_start_date
5260 AND actual_shipment_date <= NVL(x_transaction_end_date, SYSDATE)
5261 AND open_flag = 'N'
5262 AND shipped_quantity IS NOT NULL
5263 AND source_document_type_id = 5
5264 AND veh_cus_item_cum_key_id = v_tmp_cum_record.cum_key_id;
5265
5266 --
5267 IF nvl(v_shipment_count,0) = 0 THEN --{
5268 --see if there are adjustments
5269 SELECT COUNT(*)
5270 INTO v_exist
5271 FROM rlm_cust_item_cum_adj
5272 WHERE cum_key_id = v_tmp_cum_record.cum_key_id
5273 AND transaction_date_time <= nvl(x_transaction_end_date,sysdate)
5274 AND transaction_date_time >= x_transaction_start_date;
5275 --
5276 END IF; --}
5277 --
5278 IF (l_debug <> -1) THEN
5279 rlm_core_sv.dlog(C_DEBUG, 'v_shipment_count', v_shipment_count);
5280 rlm_core_sv.dlog(C_DEBUG, 'Adjustments', v_exist);
5281 END IF;
5282 IF nvl(v_exist,0) > 0 THEN
5283 --
5284 v_old_cum_ctr := v_old_cum_ctr + 1;
5285 --
5286 x_counter(v_cum_rec_ctr) := x_counter(v_cum_rec_ctr) + 1;
5287 --
5288 v_counter_ctr := v_cum_rec_ctr;
5289 --
5290 --x_counter(v_cum_rec_ctr) := v_old_cum_ctr;
5291 --
5292 IF (l_debug <> -1) THEN
5293 rlm_core_sv.dlog(C_SDEBUG,'v_cum_rec_ctr',v_cum_rec_ctr);
5294 rlm_core_sv.dlog(C_SDEBUG,'x_counter',x_counter(v_cum_rec_ctr));
5295 rlm_core_sv.dlog(C_SDEBUG,'v_old_cum_ctr',v_old_cum_ctr);
5296 END IF;
5297 --
5298 x_old_cum_records(v_old_cum_ctr).cum_key_id :=
5299 v_tmp_cum_record.cum_key_id;
5300 --
5301 IF (l_debug <> -1) THEN
5302 rlm_core_sv.dlog(C_SDEBUG,
5303 'x_old_cum_records(v_old_cum_ctr).cum_key_id',
5304 x_old_cum_records(v_old_cum_ctr).cum_key_id);
5305 END IF;
5306 --
5307 x_old_cum_records(v_old_cum_ctr).cum_qty :=
5308 v_tmp_cum_record.cum_qty;
5309 x_old_cum_records(v_old_cum_ctr).cum_qty_to_be_accumulated :=
5310 v_tmp_cum_record.cum_qty_to_be_accumulated;
5311 x_old_cum_records(v_old_cum_ctr).cum_qty_after_cutoff :=
5312 v_tmp_cum_record.cum_qty_after_cutoff;
5313 x_old_cum_records(v_old_cum_ctr).last_cum_qty_update_date :=
5314 v_tmp_cum_record.last_cum_qty_update_date;
5315 x_old_cum_records(v_old_cum_ctr).cust_uom_code :=
5316 v_tmp_cum_record.cust_uom_code;
5317 x_old_cum_records(v_old_cum_ctr).cum_start_date :=
5318 v_tmp_cum_record.cum_start_date;
5319 x_old_cum_records(v_old_cum_ctr).customer_item_id :=
5320 v_tmp_cum_record.customer_item_id;
5321 --
5322 END IF;
5323 --
5324 END IF; --}
5325 --
5326 END; --}
5327 --
5328 END LOOP; --}
5329 --
5330 CLOSE c_cum_keys;
5331 --
5332 /* If the last new_cum did not have any old_cum then delete it from the
5333 table */
5334
5335 IF Not (x_counter.EXISTS(v_cum_rec_ctr)) THEN
5336 --
5337 IF (l_debug <> -1) THEN
5338 rlm_core_sv.dlog(C_SDEBUG,'could not find old cums for cum key id: ',
5339 x_cum_records(v_cum_rec_ctr).cum_key_id);
5340 END IF;
5341 --
5342 x_cum_records.DELETE(v_cum_rec_ctr);
5343 --
5344 v_cum_rec_ctr := v_cum_rec_ctr -1 ;
5345 --
5346 ELSE
5347 --
5348 IF x_counter(v_cum_rec_ctr) = 0 THEN
5349 --
5350 IF x_cum_records.EXISTS(v_cum_rec_ctr) THEN
5351 --
5352 IF (l_debug <> -1) THEN
5353 rlm_core_sv.dlog(C_SDEBUG,'could not find old cums for cum key id:',
5354 x_cum_records(v_cum_rec_ctr).cum_key_id);
5355 END IF;
5356 --
5357 x_cum_records.DELETE(v_cum_rec_ctr);
5358 --
5359 END IF;
5360 --
5361 x_counter.DELETE(v_cum_rec_ctr);
5362 --
5363 v_cum_rec_ctr := v_cum_rec_ctr -1 ;
5364 --
5365 END IF;
5366 --
5367 IF (l_debug <> -1) THEN
5368 rlm_core_sv.dlog(C_DEBUG,'v_cum_rec_ctr',v_cum_rec_ctr);
5369 END IF;
5370 --
5371 END IF;
5372 --
5373 /* if there are no cum found then return 0 */
5374 IF (v_cum_rec_ctr = 0 ) THEN
5375 x_return_status := 0;
5376 --
5377 IF (l_debug <> -1) THEN
5378 rlm_core_sv.dpop(C_DEBUG,
5379 'GetCums:Cum key record could not be retrieved');
5380 END IF;
5381 --
5382 ELSE
5383 x_return_status := 1;
5384 --
5385 IF (l_debug <> -1) THEN
5386 rlm_core_sv.dpop(C_DEBUG,
5387 'GetCums:Cum key record is retrieved successfully');
5388 END IF;
5389 --
5390 END IF;
5391 --
5392 EXCEPTION
5393 --
5394 WHEN E_UNEXPECTED THEN
5395 --
5396 x_return_status := 0;
5397 --
5398 IF (l_debug <> -1) THEN
5399 rlm_core_sv.dlog(C_DEBUG,'msg_data',msg_data);
5400 rlm_core_sv.dpop(C_DEBUG,'GetCums E_UNEXPECTED');
5401 END IF;
5402 --
5403 WHEN NO_DATA_FOUND THEN
5404 --
5405 x_return_status := 0;
5406 --
5407 IF (l_debug <> -1) THEN
5408 rlm_core_sv.dlog(C_DEBUG,'msg_data',msg_data);
5409 rlm_core_sv.dpop(C_DEBUG,'GetCums NO_DATA_FOUND');
5410 END IF;
5411 --
5412 WHEN OTHERS THEN
5413 --
5414 -- RLM_CUM_SQLERR
5415 --
5416 IF (l_debug <> -1) THEN
5417 rlm_core_sv.dpop(C_DEBUG,'GetCums' || substr(SQLERRM,1,100));
5418 END IF;
5419 --
5420 RAISE;
5421 END GetCums; --}
5422
5423 /*============================================================================
5424
5425 PROCEDURE NAME: SetSupplierCum
5426
5427 This procedure calls the CalculateSupplierCum for all the shipments
5428 for the given Cum Key. It populates oe global tables and it calculates
5429 the cum qty
5430
5431 PARAMETERS:
5432
5433 ** x_index IN NUMBER
5434 This is the index for table x_cum_records
5435 ** x_cum_key_record IN cum_key_attrib_rec_type
5436 contains information about address ids
5437 ** x_transaction_start_date IN DATE
5438 ** x_cum_records IN OUT NOCOPY RLM_CUM_SV.t_cums
5439 Using the x_index we get the new cum record which needs to be rest
5440 ** x_return_status OUT NOCOPY BOOLEAN
5441 This will return FALSE if unexpected error happens
5442 ** x_counter IN OUT NOCOPY NUMBER
5443 Shows the number of order lines modified
5444
5445 =============================================================================*/
5446
5447 PROCEDURE SetSupplierCum (
5448 x_index IN NUMBER,
5449 x_cum_key_record IN cum_key_attrib_rec_type,
5450 x_transaction_start_date IN DATE,
5451 x_cum_records IN OUT NOCOPY RLM_CUM_SV.t_cums,
5452 x_return_status OUT NOCOPY BOOLEAN,
5453 x_counter IN OUT NOCOPY NUMBER,
5454 x_adjustment_date IN OUT NOCOPY DATE )
5455 IS
5456 v_new_ship_count t_new_ship_count;
5457 tmp_shipment_date DATE DEFAULT TO_DATE('01/01/1500', 'DD/MM/YYYY');
5458 adj_qty NUMBER DEFAULT 0;
5459 v_header_id NUMBER;
5460 v_line_id NUMBER;
5461 v_index NUMBER;
5462
5463 e_Unexpected EXCEPTION;
5464
5465 BEGIN
5466
5467 IF (l_debug <> -1) THEN
5468 rlm_core_sv.dpush(C_SDEBUG,'SetSupplierCum');
5469 END IF;
5470 --
5471 v_new_ship_count(x_cum_records(x_index).cum_key_id) := 0;
5472 --
5473 IF (l_debug <> -1) THEN
5474 rlm_core_sv.dlog(C_DEBUG,'cum_key_id', x_cum_records(x_index).cum_key_id);
5475 END IF;
5476 --
5477 x_return_status := FALSE;
5478 --
5479 IF x_cum_records(x_index).record_return_status = FALSE THEN
5480 --
5481 IF (l_debug <> -1) THEN
5482 rlm_core_sv.dlog(C_DEBUG,'CalculateSupplierCum returned false.');
5483 END IF;
5484 --
5485 RAISE e_Unexpected;
5486 --
5487 END IF;
5488 --
5489 IF g_cum_oe_lines.COUNT > 0 THEN --{
5490 v_index := g_cum_oe_lines.FIRST;
5491 --
5492 LOOP --{
5493 --
5494 v_header_id := g_cum_oe_lines(v_index).header_id;
5495 v_line_id := g_cum_oe_lines(v_index).line_id;
5496 x_cum_records(x_index).shipped_quantity :=
5497 g_cum_oe_lines(v_index).shipped_quantity;
5498 x_cum_records(x_index).actual_shipment_date :=
5499 g_cum_oe_lines(v_index).actual_shipment_date;
5500 x_cum_records(x_index).cust_uom_code :=
5501 g_cum_oe_lines(v_index).order_quantity_uom;
5502 --
5503 IF (l_debug <> -1) THEN
5504 rlm_core_sv.dlog(C_DEBUG,'shipment_date',
5505 x_cum_records(x_index).actual_shipment_date);
5506 END IF;
5507 --
5508 IF x_cum_records(x_index).actual_shipment_date
5509 = tmp_shipment_date
5510 THEN
5511 v_new_ship_count(x_cum_records(x_index).cum_key_id) :=
5512 v_new_ship_count(x_cum_records(x_index).cum_key_id) + 1;
5513 ELSE
5514 v_new_ship_count(x_cum_records(x_index).cum_key_id) := 1;
5515 tmp_shipment_date :=
5516 x_cum_records(x_index).actual_shipment_date;
5517 END IF;
5518 --
5519 IF (l_debug <> -1) THEN
5520 rlm_core_sv.dlog(C_DEBUG,'shipped_quantity',
5521 x_cum_records(x_index).shipped_quantity);
5522 END IF;
5523 --
5524 RLM_TPA_SV.CalculateSupplierCum(
5525 x_new_ship_count => v_new_ship_count,
5526 x_cum_key_record => x_cum_key_record,
5527 x_cum_record => x_cum_records(x_index));
5528 --
5529
5530 IF x_cum_records(x_index).record_return_status = FALSE THEN
5531 --
5532 IF (l_debug <> -1) THEN
5533 rlm_core_sv.dlog(C_DEBUG,'CalculateSupplierCum returned false.');
5534 END IF;
5535 --
5536 RAISE e_Unexpected;
5537 --
5538 END IF;
5539 --
5540 IF x_adjustment_date IS NULL THEN
5541 --
5542 SELECT SUM(transaction_qty)
5543 INTO adj_qty
5544 FROM rlm_cust_item_cum_adj
5545 WHERE cum_key_id = x_cum_records(x_index).cum_key_id
5546 AND transaction_date_time <
5547 x_cum_records(x_index).actual_shipment_date;
5548 --
5549 ELSE
5550 --
5551 SELECT SUM(transaction_qty)
5552 INTO adj_qty
5553 FROM rlm_cust_item_cum_adj
5554 WHERE cum_key_id = x_cum_records(x_index).cum_key_id
5555 AND transaction_date_time >= x_adjustment_date
5556 AND transaction_date_time <
5557 x_cum_records(x_index).actual_shipment_date;
5558
5559 --
5560 END IF;
5561 --
5562 IF (l_debug <> -1) THEN
5563 rlm_core_sv.dlog(C_DEBUG,'x_adjustment_date',x_adjustment_date);
5564 END IF;
5565 --
5566 IF (l_debug <> -1) THEN
5567 rlm_core_sv.dlog(C_DEBUG,'actual_shipment_date',
5568 x_cum_records(x_index).actual_shipment_date);
5569 END IF;
5570 --
5571 IF adj_qty IS NULL THEN
5572 --
5573 adj_qty := 0;
5574 --
5575 IF (l_debug <> -1) THEN
5576 rlm_core_sv.dlog(C_DEBUG, 'No adjustment found.');
5577 END IF;
5578 --
5579 END IF;
5580 --
5581 IF (l_debug <> -1) THEN
5582 rlm_core_sv.dlog(C_DEBUG,'adj_qty',adj_qty);
5583 END IF;
5584 --
5585 x_adjustment_date := x_cum_records(x_index).actual_shipment_date;
5586 --
5587 x_cum_records(x_index).cum_qty :=
5588 x_cum_records(x_index).cum_qty + adj_qty;
5589 --
5590 IF (l_debug <> -1) THEN
5591 rlm_core_sv.dlog(C_DEBUG,'cum qty',
5592 x_cum_records(x_index).cum_qty);
5593 END IF;
5594 --
5595 --g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
5596 --
5597 g_oe_tmp_line_tbl(x_counter) := OE_Order_PUB.G_MISS_LINE_REC;
5598 --
5599 g_oe_tmp_line_tbl(x_counter).header_id := v_header_id;
5600 --
5601 g_oe_tmp_line_tbl(x_counter).line_id := v_line_id;
5602 --
5603 g_oe_tmp_line_tbl(x_counter).operation := oe_globals.G_OPR_UPDATE;
5604 --
5605 g_oe_tmp_line_tbl(x_counter).veh_cus_item_cum_key_id :=
5606 x_cum_records(x_index).cum_key_id;
5607 g_oe_tmp_line_tbl(x_counter).industry_attribute7 :=
5608 x_cum_records(x_index).cum_qty;
5609 g_oe_tmp_line_tbl(x_counter).industry_attribute8 :=
5610 x_cum_records(x_index).cust_uom_code;
5611 --
5612 IF (l_debug <> -1) THEN
5613 rlm_core_sv.dlog(C_DEBUG, 'x_counter', x_counter);
5614 rlm_core_sv.dlog(C_DEBUG, 'g_oe_tmp_line_tbl(x_counter).header_id',
5615 g_oe_tmp_line_tbl(x_counter).header_id);
5616 rlm_core_sv.dlog(C_DEBUG, 'g_oe_tmp_line_tbl(x_counter).line_id',
5617 g_oe_tmp_line_tbl(x_counter).line_id);
5618 rlm_core_sv.dlog(C_DEBUG,
5619 'g_oe_tmp_line_tbl(x_counter).veh_cus_item_cum_key_id',
5620 g_oe_tmp_line_tbl(x_counter).veh_cus_item_cum_key_id);
5621 rlm_core_sv.dlog(C_DEBUG,'g_oe_tmp_line_tbl(counter).industry_attribute7',
5622 g_oe_tmp_line_tbl(x_counter).industry_attribute7);
5623 rlm_core_sv.dlog(C_DEBUG,'g_oe_tmp_line_tbl(counter).industry_attribute8',
5624 g_oe_tmp_line_tbl(x_counter).industry_attribute8);
5625 END IF;
5626 --
5627 x_counter := x_counter + 1;
5628 --
5629 EXIT WHEN v_index = g_cum_oe_lines.LAST;
5630 --
5631 v_index := g_cum_oe_lines.NEXT(v_index);
5632 --
5633 END LOOP; --}
5634 --
5635 END IF; --}
5636 --
5637 x_return_status := TRUE;
5638 --
5639 IF (l_debug <> -1) THEN
5640 rlm_core_sv.dpop(C_DEBUG,'SetSupplierCum');
5641 END IF;
5642 --
5643 EXCEPTION
5644 --
5645 WHEN e_Unexpected THEN
5646 --
5647 IF (l_debug <> -1) THEN
5648 rlm_core_sv.dpop(C_DEBUG,'SetSupplierCum: e_unexpected');
5649 END IF;
5650 --
5651 WHEN OTHERS THEN
5652 --
5653 IF (l_debug <> -1) THEN
5654 rlm_core_sv.dpop(C_DEBUG,'SetSupplierCum' || substr(SQLERRM,1,200));
5655 END IF;
5656 --
5657 RAISE;
5658
5659 END SetSupplierCum;
5660
5661
5662 /*===========================================================================
5663
5664 PROCEDURE NAME: QuickSort
5665
5666 ===========================================================================*/
5667
5668 PROCEDURE QuickSort(first IN NUMBER,
5669 last IN NUMBER,
5670 sortType IN NUMBER)
5671 IS
5672
5673 Low NUMBER;
5674 High NUMBER;
5675 Pivot_d DATE;
5676 Pivot_n NUMBER;
5677 v_Progress VARCHAR2(3) := '010';
5678
5679 BEGIN
5680 --
5681 IF (l_debug <> -1) THEN
5682 rlm_core_sv.dpush(C_SDEBUG,'QuickSort');
5683 END IF;
5684 --
5685 low := First;
5686 high := Last;
5687
5688 /* Select an element from the middle. */
5689 IF sortType = RLM_CUM_SV.C_line_table_type THEN
5690 pivot_n := g_oe_tmp_line_tbl(TRUNC((First + Last) / 2)).header_id;
5691 LOOP
5692 /* Find lowest element that is >= Pivot */
5693 WHILE g_oe_tmp_line_tbl(Low).header_id < Pivot_n LOOP
5694 Low := Low + 1;
5695 END LOOP;
5696 /* Find highest element that is <= Pivot */
5697 WHILE g_oe_tmp_line_tbl(High).header_id > Pivot_n LOOP
5698 High := High - 1;
5699 END LOOP;
5700 /* swap the elements */
5701 IF Low <= High THEN
5702 Swap(High, Low,sortType);
5703 Low := Low + 1;
5704 High := High - 1;
5705 End IF;
5706 EXIT WHEN Low > High;
5707 END LOOP ;
5708 ELSE
5709 pivot_d := g_cum_oe_lines(TRUNC((First + Last) / 2)).actual_shipment_date;
5710 LOOP
5711 /* Find lowest element that is >= Pivot */
5712 WHILE g_cum_oe_lines(Low).actual_shipment_date < Pivot_d LOOP
5713 Low := Low + 1;
5714 END LOOP;
5715 /* Find highest element that is <= Pivot */
5716 WHILE g_cum_oe_lines(High).actual_shipment_date > Pivot_d LOOP
5717 High := High - 1;
5718 END LOOP;
5719 /* swap the elements */
5720 IF Low <= High THEN
5721 Swap(High, Low,sortType);
5722 Low := Low + 1;
5723 High := High - 1;
5724 End IF;
5725 EXIT WHEN Low > High;
5726 END LOOP ;
5727 END IF;
5728 --
5729 IF (First < High) THEN
5730 Quicksort(First, High,sortType);
5731 END IF;
5732 IF (Low < Last) THEN
5733 Quicksort(Low, Last,sortType);
5734 END IF;
5735 --
5736 IF (l_debug <> -1) THEN
5737 rlm_core_sv.dpop(C_DEBUG);
5738 END IF;
5739 --
5740 EXCEPTION
5741
5742 WHEN OTHERS THEN
5743 rlm_message_sv.sql_error('rlm_cum_sv.QuickSort', v_Progress);
5744 --
5745 IF (l_debug <> -1) THEN
5746 rlm_core_sv.dlog(C_DEBUG,'progress',v_Progress);
5747 rlm_core_sv.dpop(C_DEBUG,'EXCEPTION: '||SUBSTR(SQLERRM,1,200));
5748 END IF;
5749 --
5750 raise;
5751 --
5752 END QuickSort;
5753
5754 /*===========================================================================
5755
5756 PROCEDURE NAME: Swap
5757
5758 ===========================================================================*/
5759 PROCEDURE Swap( i IN NUMBER,
5760 j IN NUMBER,
5761 sortType IN NUMBER)
5762 IS
5763
5764 T oe_order_pub.Line_Rec_Type ;
5765 T2 rlm_cum_sv.cum_oe_lines_type;
5766 v_Progress VARCHAR2(3) := '010';
5767
5768 BEGIN
5769
5770 -- rlm_core_sv.dpush(C_SDEBUG,'Swap');
5771
5772 IF sortType = rlm_cum_sv.C_line_table_type THEN
5773 T := g_oe_tmp_line_tbl(i);
5774 g_oe_tmp_line_tbl(i) := g_oe_tmp_line_tbl(j);
5775 g_oe_tmp_line_tbl(j) := T;
5776 ELSE
5777 T2 := g_cum_oe_lines(i);
5778 g_cum_oe_lines(i) := g_cum_oe_lines(j);
5779 g_cum_oe_lines(j) := T2;
5780 END IF;
5781
5782 -- rlm_core_sv.dpop(C_SDEBUG);
5783
5784 EXCEPTION
5785
5786 WHEN OTHERS THEN
5787 --rlm_message_sv.sql_error('rlm_cum_sv.Swap', v_Progress);
5788 --rlm_core_sv.dlog(C_DEBUG,'progress',v_Progress);
5789 --rlm_core_sv.dpop(C_SDEBUG,'EXCEPTION: '||SUBSTR(SQLERRM,1,200));
5790 raise;
5791
5792 END Swap;
5793
5794 PROCEDURE GetShippLines (
5795 x_cum_key_id IN NUMBER,
5796 x_ship_from_org_id IN NUMBER,
5797 x_ship_to_org_id IN NUMBER,
5798 x_intmed_ship_to_org_id IN NUMBER,
5799 x_bill_to_org_id IN NUMBER,
5800 x_customer_item_id IN NUMBER,
5801 x_inventory_item_id IN NUMBER,
5802 x_transaction_start_date IN DATE,
5803 x_transaction_end_date IN DATE,
5804 x_index IN OUT NOCOPY NUMBER )
5805 IS
5806 CURSOR c_oe_lines IS
5807 SELECT header_id,
5808 line_id,
5809 shipped_quantity,
5810 actual_shipment_date,
5811 order_quantity_uom,
5812 org_id
5813 FROM oe_order_lines_all
5814 WHERE (ship_from_org_id = x_ship_from_org_id
5815 OR x_ship_from_org_id IS NULL)
5816 AND (ship_to_org_id = x_ship_to_org_id
5817 OR x_ship_to_org_id IS NULL)
5818 AND (intmed_ship_to_org_id = x_intmed_ship_to_org_id
5819 OR x_intmed_ship_to_org_id IS NULL)
5820 AND (invoice_to_org_id = x_bill_to_org_id
5821 OR x_bill_to_org_id IS NULL)
5822 AND (ordered_item_id = x_customer_item_id
5823 OR x_customer_item_id IS NULL)
5824 AND (actual_shipment_date >= x_transaction_start_date
5825 OR x_transaction_start_date IS NULL)
5826 AND (actual_shipment_date <= NVL(x_transaction_end_date, SYSDATE))
5827 AND shipped_quantity IS NOT NULL
5828 AND open_flag = 'N'
5829 AND source_document_type_id = 5
5830 AND veh_cus_item_cum_key_id = x_cum_key_id
5831 AND inventory_item_id = x_inventory_item_id
5832 ORDER BY actual_shipment_date;
5833
5834
5835 BEGIN
5836 --
5837 IF (l_debug <> -1) THEN
5838 rlm_core_sv.dpush(C_SDEBUG,'GetShippLines');
5839 rlm_core_sv.dlog(C_DEBUG,'cum_key_id',x_cum_key_id);
5840 rlm_core_sv.dlog(C_DEBUG,'x_ship_from_org_id',x_ship_from_org_id);
5841 rlm_core_sv.dlog(C_DEBUG,'x_ship_to_org_id',x_ship_to_org_id);
5842 rlm_core_sv.dlog(C_DEBUG,'x_intmed_ship_to_org_id',x_intmed_ship_to_org_id);
5843 rlm_core_sv.dlog(C_DEBUG,'x_bill_to_org_id',x_bill_to_org_id);
5844 rlm_core_sv.dlog(C_DEBUG,'x_customer_item_id',x_customer_item_id);
5845 rlm_core_sv.dlog(C_DEBUG,'x_inventory_item_id',x_inventory_item_id);
5846 rlm_core_sv.dlog(C_DEBUG,'x_transaction_start_date',x_transaction_start_date);
5847 rlm_core_sv.dlog(C_DEBUG,'x_transaction_end_date',x_transaction_end_date);
5848 rlm_core_sv.dlog(C_DEBUG,'x_index',x_index);
5849 END IF;
5850 --
5851 OPEN c_oe_lines ;
5852 --
5853 LOOP --{
5854 --
5855 FETCH c_oe_lines INTO
5856 g_cum_oe_lines(x_index).header_id,
5857 g_cum_oe_lines(x_index).line_id,
5858 g_cum_oe_lines(x_index).shipped_quantity,
5859 g_cum_oe_lines(x_index).actual_shipment_date,
5860 g_cum_oe_lines(x_index).order_quantity_uom,
5861 g_cum_oe_lines(x_index).org_id;
5862 --
5863 EXIT WHEN c_oe_lines%NOTFOUND;
5864 --
5865 IF (l_debug <> -1) THEN
5866 rlm_core_sv.dlog(C_DEBUG,'shipped_quantity',
5867 g_cum_oe_lines(x_index).shipped_quantity);
5868 END IF;
5869 --
5870 x_index := x_index + 1;
5871 --
5872 END LOOP; --}
5873 --
5874 CLOSE c_oe_Lines;
5875 --
5876 IF (l_debug <> -1) THEN
5877 rlm_core_sv.dpop(C_DEBUG,'GetShippLines');
5878 END IF;
5879 --
5880 EXCEPTION
5881 --
5882 WHEN OTHERS THEN
5883 --
5884 IF c_oe_lines%ISOPEN THEN
5885 --
5886 CLOSE c_oe_lines;
5887 --
5888 END IF;
5889 --
5890 IF (l_debug <> -1) THEN
5891 rlm_core_sv.dpop(C_DEBUG,'GetShippLines' || substr(SQLERRM,1,200));
5892 END IF;
5893 --
5894 RAISE;
5895
5896 END GetShippLines;
5897
5898 /*=============================================================================
5899 PROCEDURE NAME: UpdateOldKey
5900
5901 DESCRIPTION: This procedure will be called to update CUM Key ID record(s) t
5902 hat
5903 are previously attached to order lines
5904
5905 PARAMETERS: x_old_cum_table IN t_old_cum
5906
5907 ============================================================================*/
5908 --{
5909 PROCEDURE UpdateOldKey(x_old_cum_records IN OUT NOCOPY RLM_CUM_SV.t_cums,
5910 x_shipment_rule_code IN VARCHAR2,
5911 x_cutoff_time IN DATE,
5912 x_cum_key_record IN OUT NOCOPY cum_key_attrib_rec_type,
5913 x_ship_from_org_id IN NUMBER,
5914 x_ship_to_org_id IN NUMBER,
5915 x_intmed_ship_to_org_id IN NUMBER,
5916 x_bill_to_org_id IN NUMBER,
5917 x_customer_item_id IN NUMBER,
5918 x_return_status OUT NOCOPY BOOLEAN)
5919 IS
5920 v_index NUMBER;
5921 v_adjustment_date DATE;
5922 counter NUMBER DEFAULT 1;
5923 cum_records_counter NUMBER;
5924 adj_qty NUMBER DEFAULT 0;
5925 v_return_status BOOLEAN;
5926 v_line_idx NUMBER;
5927 v_tmp_line_idx NUMBER;
5928 v_header_id NUMBER;
5929 l_file_val VARCHAR2(80);
5930 v_om_dbg_dir VARCHAR2(80);
5931 x_oe_api_version NUMBER DEFAULT 1;
5932 l_return_status VARCHAR2(1);
5933 v_msg_count NUMBER;
5934 v_msg_data VARCHAR2(2000);
5935 e_noshipment EXCEPTION;
5936 e_SetSupplierCum EXCEPTION;
5937 --
5938 l_oe_line_tbl_out oe_order_pub.line_tbl_type;
5939 --
5940 BEGIN
5941 --
5942 IF (l_debug <> -1) THEN
5943 rlm_core_sv.dpush(C_DEBUG, 'UpdateOldKey');
5944 END IF;
5945 --
5946 g_oe_tmp_line_tbl.DELETE;
5947 g_oe_tmp_line_tbl := oe_order_pub.g_miss_line_tbl;
5948 g_oe_line_tbl.DELETE;
5949 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
5950 --
5951 x_return_status := TRUE;
5952 --
5953 FOR cum_records_counter in 1..x_old_cum_records.COUNT LOOP
5954 --return if the table is empty
5955 IF x_old_cum_records(cum_records_counter).cum_key_id IS NOT NULL THEN --{
5956 --
5957 g_cum_oe_lines.DELETE;
5958 v_index := 1;
5959 v_adjustment_date := NULL;
5960 v_return_status := TRUE;
5961 --
5962
5963 --for each old cum record x_cum_key_record needs to be updated with correct inventory_item_id
5964
5965 x_cum_key_record.inventory_item_id := x_old_cum_records(cum_records_counter).inventory_item_id;
5966 --
5967 IF (l_debug <> -1) THEN
5968 rlm_core_sv.dlog(C_DEBUG,'inventory_item_id', x_cum_key_record.inventory_item_id);
5969 END IF;
5970 --
5971 rlm_cum_sv.GetShippLines(
5972 x_cum_key_id => x_old_cum_records(cum_records_counter).cum_key_id,
5973 x_ship_from_org_id => x_ship_from_org_id,
5974 x_ship_to_org_id => x_ship_to_org_id,
5975 x_intmed_ship_to_org_id => x_intmed_ship_to_org_id,
5976 x_bill_to_org_id => x_bill_to_org_id,
5977 x_customer_item_id => x_customer_item_id,
5978 x_inventory_item_id => x_cum_key_record.inventory_item_id,
5979 x_transaction_start_date => NULL,
5980 x_transaction_end_date => SYSDATE,
5981 x_index => v_index);
5982 --
5983 IF g_cum_oe_lines.COUNT > 0 THEN
5984 --
5985 rlm_cum_sv.quicksort(g_cum_oe_lines.FIRST,
5986 g_cum_oe_lines.LAST,
5987 C_cum_oe_lines);
5988 --
5989 END IF;
5990 --
5991 x_old_cum_records(cum_records_counter).record_return_status := TRUE;
5992 x_old_cum_records(cum_records_counter).cum_qty := 0;
5993 --
5994 x_old_cum_records(cum_records_counter).cum_qty_to_be_accumulated := 0;
5995 --
5996 x_old_cum_records(cum_records_counter).cum_qty_after_cutoff := 0;
5997 --
5998 x_old_cum_records(cum_records_counter).use_ship_incl_rule_flag := 'Y';
5999 --
6000 x_old_cum_records(cum_records_counter).as_of_date_time := NULL;
6001
6002 -- Need to set called_by_reset_cum to 'Y'
6003 x_cum_key_record.called_by_reset_cum := 'Y';
6004 --
6005
6006 rlm_cum_sv.SetSupplierCum(
6007 x_index => cum_records_counter,
6008 x_cum_key_record => x_cum_key_record,
6009 x_transaction_start_date => NULL,
6010 x_cum_records => x_old_cum_records,
6011 x_return_status => v_return_status,
6012 x_counter => counter,
6013 x_adjustment_date => v_adjustment_date);
6014 --
6015 IF (l_debug <> -1) THEN
6016 rlm_core_sv.dlog(C_DEBUG,'v_return_status',v_return_status);
6017 END IF;
6018 --
6019 IF v_return_status = FALSE THEN
6020 --
6021 x_return_status := FALSE;
6022 --
6023 IF (l_debug <> -1) THEN
6024 rlm_core_sv.dlog(C_DEBUG,'SetSupplierCum failed');
6025 END IF;
6026 --
6027 fnd_file.put_line(fnd_file.log,'Failed to update Old CUMs, rolling back');
6028 RAISE e_SetSupplierCum;
6029 --
6030 ELSE --{
6031 --
6032 -- get all adjustments after the last shipment
6033 SELECT SUM(transaction_qty)
6034 INTO adj_qty
6035 FROM rlm_cust_item_cum_adj
6036 WHERE cum_key_id = x_old_cum_records(cum_records_counter).cum_key_id
6037 AND transaction_date_time <= sysdate
6038 AND ((transaction_date_time >= v_adjustment_date)
6039 OR (v_adjustment_date IS NULL));
6040 --
6041 IF (l_debug <> -1) THEN
6042 rlm_core_sv.dlog(C_DEBUG,'v_adjustment_date',
6043 v_adjustment_date);
6044 rlm_core_sv.dlog(C_DEBUG, 'adj_qty',adj_qty);
6045 END IF;
6046 --
6047 x_old_cum_records(cum_records_counter).cum_qty :=
6048 x_old_cum_records(cum_records_counter).cum_qty +
6049 nvl(adj_qty,0);
6050 --
6051 UPDATE rlm_cust_item_cum_keys
6052 SET cum_qty = x_old_cum_records(cum_records_counter).cum_qty,
6053 cum_qty_to_be_accumulated =
6054 x_old_cum_records(cum_records_counter).cum_qty_to_be_accumulated,
6055 cum_qty_after_cutoff =
6056 x_old_cum_records(cum_records_counter).cum_qty_after_cutoff,
6057 last_cum_qty_update_date = SYSDATE,
6058 last_update_login = FND_GLOBAL.LOGIN_ID,
6059 last_update_date = SYSDATE,
6060 last_updated_by = FND_GLOBAL.USER_ID
6061 WHERE cum_key_id=x_old_cum_records(cum_records_counter).cum_key_id
6062 AND NVL(inactive_flag,'N') = 'N';
6063 --
6064 IF (l_debug <> -1) THEN
6065 rlm_core_sv.dlog(C_DEBUG,'x_old_cum_records.cum_key_id',
6066 x_old_cum_records(cum_records_counter).cum_key_id);
6067 rlm_core_sv.dlog(C_DEBUG,'x_old_cum_records.cum_qty',
6068 x_old_cum_records(cum_records_counter).cum_qty);
6069 END IF;
6070 --
6071
6072 END IF; --}
6073 END IF; --}
6074 --
6075 END LOOP;
6076 --
6077
6078 -- group the g_oe_tmp_line_tbl by header_id
6079 IF g_oe_tmp_line_tbl.COUNT = 0 THEN
6080 --
6081 IF (l_debug <> -1) THEN
6082 rlm_core_sv.dlog(C_DEBUG,'There are no order lines to process in ' ||
6083 'update old cum');
6084 END IF;
6085 --
6086 RAISE e_NoShipment;
6087 --
6088 END IF;
6089 --
6090 rlm_cum_sv.quicksort(g_oe_tmp_line_tbl.FIRST,
6091 g_oe_tmp_line_tbl.LAST,
6092 RLM_CUM_SV.C_line_table_type);
6093 --
6094 v_tmp_line_idx := g_oe_tmp_line_tbl.FIRST;
6095 --
6096 IF (l_debug <> -1) THEN
6097 rlm_core_sv.dlog(C_DEBUG, 'v_tmp_line_idx',v_tmp_line_idx);
6098 END IF;
6099 --
6100 v_line_idx := 1;
6101 --
6102 v_header_id := g_oe_tmp_line_tbl(v_tmp_line_idx).header_id;
6103 --
6104 IF (l_debug <> -1) THEN
6105 rlm_core_sv.dlog(C_DEBUG, 'v_header_id',v_header_id);
6106 END IF;
6107 --
6108 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
6109 --
6110 BEGIN --{
6111 --
6112 fnd_profile.get('ECE_OUT_FILE_PATH',v_om_dbg_dir);
6113 --
6114 fnd_profile.put('OE_DEBUG_LOG_DIRECTORY',v_om_dbg_dir);
6115 --
6116 l_file_val := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
6117 --
6118 IF (l_debug <> -1) THEN
6119 rlm_core_sv.dlog(C_DEBUG, 'l_file_val',l_file_val);
6120 END IF;
6121 --
6122 LOOP --{
6123 /* Call OE_Order_GRP.Process_Order procedure to update OE_ORDER_LINES
6124 table by passing the g_oe_line_tbl structure that has been prepared
6125 this loop calls the process_order API once per each header_id,
6126 since the table is sorted by header_id then this loop
6127 calls the process_order once the header_id is changed */
6128 --
6129 IF (l_debug <> -1) THEN
6130 rlm_core_sv.dlog(C_DEBUG,'processing header_id',v_header_id);
6131 END IF;
6132 --
6133 IF g_oe_tmp_line_tbl(v_tmp_line_idx).header_id = v_header_id THEN --{
6134 --
6135 g_oe_line_tbl(v_line_idx) := g_oe_tmp_line_tbl(v_tmp_line_idx);
6136 --
6137 v_line_idx := v_line_idx + 1;
6138 --
6139 IF v_tmp_line_idx = g_oe_tmp_line_tbl.LAST THEN --{
6140 -- process order for the last time
6141 OE_Order_GRP.Process_order(
6142 p_api_version_number => x_oe_api_version,
6143 p_init_msg_list => FND_API.G_TRUE,
6144 p_return_values => FND_API.G_FALSE,
6145 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6146 x_return_status => l_return_status,
6147 x_msg_count => v_msg_count,
6148 x_msg_data => v_msg_data,
6149 ------------------------------------------
6150 p_line_tbl => g_oe_line_tbl,
6151 ------------------------------------------
6152 x_header_rec => g_oe_header_out_rec,
6153 x_header_val_rec => g_oe_header_val_out_rec,
6154 x_Header_Adj_tbl => g_oe_Header_Adj_out_tbl,
6155 x_Header_Adj_val_tbl => g_oe_Header_Adj_val_out_tbl,
6156 x_Header_price_Att_tbl => g_Header_price_Att_out_tbl,
6157 x_Header_Adj_Att_tbl => g_Header_Adj_Att_out_tbl,
6158 x_Header_Adj_Assoc_tbl => g_Header_Adj_Assoc_out_tbl,
6159 x_Header_Scredit_tbl => g_oe_Header_Scredit_out_tbl,
6160 x_Header_Scredit_val_tbl => g_oe_Hdr_Scdt_val_out_tbl,
6161 x_line_tbl => l_oe_line_tbl_out,
6162 x_line_val_tbl => g_oe_line_val_out_tbl,
6163 x_Line_Adj_tbl => g_oe_line_Adj_out_tbl,
6164 x_Line_Adj_val_tbl => g_oe_line_Adj_val_out_tbl,
6165 x_Line_price_Att_tbl => g_Line_price_Att_out_tbl,
6166 x_Line_Adj_Att_tbl => g_Line_Adj_Att_out_tbl,
6167 x_Line_Adj_Assoc_tbl => g_Line_Adj_Assoc_out_tbl,
6168 x_Line_Scredit_tbl => g_oe_line_scredit_out_tbl,
6169 x_Line_Scredit_val_tbl => g_oe_line_scredit_val_out_tbl,
6170 x_Lot_Serial_tbl => g_oe_lot_serial_out_tbl,
6171 x_Lot_Serial_val_tbl => g_oe_lot_serial_val_out_tbl,
6172 x_Action_Request_tbl => g_oe_Action_Request_out_Tbl) ;
6173 --
6174 IF (l_debug <> -1) THEN
6175 rlm_core_sv.dlog(C_DEBUG,'G_FILE',OE_DEBUG_PUB.G_FILE);
6176 rlm_core_sv.dlog(C_DEBUG, 'Input tbl count', g_oe_line_tbl.LAST);
6177 rlm_core_sv.dlog(C_DEBUG, 'Output tbl count',
6178 l_oe_line_tbl_out.LAST);
6179 END IF;
6180 --
6181 -- Handle the exceptions caused by the OE call
6182 --
6183
6184 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN --{
6185 --
6186 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6187 --}
6188 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN --{
6189 --
6190 RAISE FND_API.G_EXC_ERROR;
6191 --}
6192 ELSE --{
6193 --
6194 x_return_status := TRUE;
6195 --
6196 IF (l_debug <> -1) THEN
6197 rlm_core_sv.dlog(C_DEBUG,
6198 'Order line is updated successfully');
6199 END IF;
6200 --
6201 END IF; --}
6202 EXIT;
6203 --}
6204 --{ if not the last element
6205 ELSE
6206 --
6207 v_tmp_line_idx := g_oe_tmp_line_tbl.NEXT(v_tmp_line_idx);
6208 --
6209 END IF; --}
6210 --}
6211 --{ if header_id has changed
6212 ELSE
6213 --
6214 v_header_id := g_oe_tmp_line_tbl(v_tmp_line_idx).header_id;
6215 --
6216 v_line_idx := 1;
6217 --
6218
6219 OE_Order_GRP.Process_order(
6220 p_api_version_number => x_oe_api_version,
6221 p_init_msg_list => FND_API.G_TRUE,
6222 p_return_values => FND_API.G_FALSE,
6223 p_validation_level => FND_API.G_VALID_LEVEL_FULL,
6224 x_return_status => l_return_status,
6225 x_msg_count => v_msg_count,
6226 x_msg_data => v_msg_data,
6227 ------------------------------------------
6228 p_line_tbl => g_oe_line_tbl,
6229 ------------------------------------------
6230 x_header_rec => g_oe_header_out_rec,
6231 x_header_val_rec => g_oe_header_val_out_rec,
6232 x_Header_Adj_tbl => g_oe_Header_Adj_out_tbl,
6233 x_Header_Adj_val_tbl => g_oe_Header_Adj_val_out_tbl,
6234 x_Header_price_Att_tbl => g_Header_price_Att_out_tbl,
6235 x_Header_Adj_Att_tbl => g_Header_Adj_Att_out_tbl,
6236 x_Header_Adj_Assoc_tbl => g_Header_Adj_Assoc_out_tbl,
6237 x_Header_Scredit_tbl => g_oe_Header_Scredit_out_tbl,
6238 x_Header_Scredit_val_tbl => g_oe_Hdr_Scdt_val_out_tbl,
6239 x_line_tbl => l_oe_line_tbl_out,
6240 x_line_val_tbl => g_oe_line_val_out_tbl,
6241 x_Line_Adj_tbl => g_oe_line_Adj_out_tbl,
6242 x_Line_Adj_val_tbl => g_oe_line_Adj_val_out_tbl,
6243 x_Line_price_Att_tbl => g_Line_price_Att_out_tbl,
6244 x_Line_Adj_Att_tbl => g_Line_Adj_Att_out_tbl,
6245 x_Line_Adj_Assoc_tbl => g_Line_Adj_Assoc_out_tbl,
6246 x_Line_Scredit_tbl => g_oe_line_scredit_out_tbl,
6247 x_Line_Scredit_val_tbl => g_oe_line_scredit_val_out_tbl,
6248 x_Lot_Serial_tbl => g_oe_lot_serial_out_tbl,
6249 x_Lot_Serial_val_tbl => g_oe_lot_serial_val_out_tbl,
6250 x_Action_Request_tbl => g_oe_Action_Request_out_Tbl) ;
6251 --
6252 -- Handle the exceptions caused by the OE call
6253 --
6254 IF (l_debug <> -1) THEN
6255 rlm_core_sv.dlog(C_DEBUG,'G_FILE',OE_DEBUG_PUB.G_FILE);
6256 rlm_core_sv.dlog(C_DEBUG, 'Input tbl count', g_oe_line_tbl.LAST); rlm_core_sv.dlog(C_DEBUG, 'Output tbl count',
6257 l_oe_line_tbl_out.LAST);
6258 END IF;
6259 --
6260 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN --{
6261 --
6262 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6263 --}
6264 ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN --{
6265 --
6266 RAISE FND_API.G_EXC_ERROR;
6267 --}
6268 ELSE --{
6269 --
6270 x_return_status := TRUE;
6271 --
6272 IF (l_debug <> -1) THEN
6273 rlm_core_sv.dlog(C_DEBUG,
6274 'Order line is updated successfully');
6275 END IF;
6276 --
6277 END IF; --}
6278 --
6279 g_oe_line_tbl.DELETE;
6280 --
6281 g_oe_line_tbl := oe_order_pub.g_miss_line_tbl;
6282 --
6283 g_oe_line_tbl(v_line_idx) := g_oe_tmp_line_tbl(v_tmp_line_idx);
6284 --
6285 END IF; --} if the header_id has not changed
6286 --
6287 END LOOP; --}
6288 END ; --}
6289 --
6290 IF (l_debug <> -1) THEN
6291 rlm_core_sv.dpop(C_DEBUG);
6292 END IF;
6293 --
6294 EXCEPTION
6295 WHEN e_noshipment THEN
6296 --
6297 IF (l_debug <> -1) THEN
6298 rlm_core_sv.dpop(C_DEBUG, 'UpdateOldKey e_noshipment ');
6299 END IF;
6300 --
6301 WHEN e_SetSupplierCum THEN
6302 --
6303 x_return_status := FALSE;
6304 --
6305 IF (l_debug <> -1) THEN
6306 rlm_core_sv.dpop(C_DEBUG, 'UpdateOldKey e_SetSupplierCum');
6307 END IF;
6308 --
6309 WHEN FND_API.G_EXC_ERROR THEN
6310 --
6311 x_return_status := FALSE;
6312 --
6313 --Get message count and data
6314 --
6315 OE_MSG_PUB.Count_And_Get(
6316 p_count => v_msg_count,
6317 p_data => v_msg_data);
6318 --
6319 rlm_message_sv.get_msg_text(
6320 x_message_name => 'RLM_CUM_PROCESS_ORDER',
6321 x_text => v_msg_data);
6322 --
6323 fnd_file.put_line(fnd_file.log, v_msg_data);
6324 --
6325 -- DEBUGGING
6326 IF (l_debug <> -1) THEN
6327 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_ERROR');
6328 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status', l_return_status);
6329 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
6330 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_count', v_msg_count);
6331 rlm_core_sv.dlog(C_SDEBUG, 'Main v_msg_data', v_msg_data);
6332 END IF;
6333 --
6334 IF v_msg_count > 0 THEN
6335 --
6336 FOR k in 1 .. v_msg_count LOOP
6337 --
6338 v_msg_data := oe_msg_pub.get( p_msg_index => k,
6339 p_encoded => 'F');
6340 --
6341 fnd_file.put_line(fnd_file.log, v_msg_data);
6342 --
6343 IF (l_debug <> -1) THEN
6344 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_data', v_msg_data);
6345 END IF;
6346 --
6347 END LOOP;
6348 --
6349 END IF;
6350 --
6351 --
6352 --
6353 -- User friendly message
6354 --
6355 IF (l_debug <> -1) THEN
6356 rlm_core_sv.dpop(C_DEBUG, 'UpdateOldKey G_EXC_ERROR');
6357 END IF;
6358 --
6359 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6360 x_return_status := FALSE;
6361 --
6362 --Get message count and data
6363 --
6364 OE_MSG_PUB.Count_And_Get(
6365 p_count => v_msg_count,
6366 p_data => v_msg_data);
6367 --
6368 rlm_message_sv.get_msg_text(
6369 x_message_name => 'RLM_CUM_PROCESS_ORDER',
6370 x_text => v_msg_data);
6371 --
6372 fnd_file.put_line(fnd_file.log, v_msg_data);
6373 --
6374 -- DEBUGGING
6375 IF (l_debug <> -1) THEN
6376 rlm_core_sv.dlog(C_SDEBUG, 'G_EXC_UNEXPECTED_ERROR');
6377 rlm_core_sv.dlog(C_SDEBUG, 'l_return_status', l_return_status);
6378 rlm_core_sv.dlog(C_SDEBUG, 'x_return_status', x_return_status);
6379 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_count', v_msg_count);
6380 rlm_core_sv.dlog(C_SDEBUG, 'Main v_msg_data', v_msg_data);
6381 END IF;
6382 --
6383 IF v_msg_count > 0 THEN
6384 --
6385 FOR k in 1 .. v_msg_count LOOP
6386 --
6387 v_msg_data := oe_msg_pub.get( p_msg_index => k,
6388 p_encoded => 'F');
6389 --
6390 fnd_file.put_line(fnd_file.log, v_msg_data);
6391 --
6392 IF (l_debug <> -1) THEN
6393 rlm_core_sv.dlog(C_SDEBUG, 'v_msg_data', v_msg_data);
6394 END IF;
6395 --
6396 END LOOP;
6397 --
6398 END IF;
6399 --
6400 --
6401 -- User friendly message
6402 --
6403 IF (l_debug <> -1) THEN
6404 rlm_core_sv.dpop(C_DEBUG, 'UpdateOldKey G_EXC_UNEXPECTED_ERROR');
6405 END IF;
6406
6407 WHEN OTHERS THEN
6408 x_return_status := FALSE;
6409 --
6410 IF (l_debug <> -1) THEN
6411 rlm_core_sv.dpop(C_DEBUG, 'UpdateOldKey others: '|| substr(SQLERRM,1,200));
6412 END IF;
6413 --
6414 END UpdateOldKey;--}
6415
6416
6417 FUNCTION GetInventoryItemId(x_customer_item_id IN NUMBER)
6418 RETURN NUMBER
6419 IS
6420
6421 v_inventory_item_id NUMBER := NULL;
6422 Temp_Master_Organization_Id Number := NULL;
6423 Temp_Inventory_Item_Id Number := NULL;
6424 Temp_Inactive_Flag Varchar2(1) := NULL;
6425
6426 CURSOR CI_XREF_Cur IS
6427 SELECT Master_Organization_Id, Inventory_Item_Id, Inactive_Flag
6428 FROM MTL_CUSTOMER_ITEM_XREFS
6429 WHERE Customer_Item_Id = x_customer_item_id
6430 ORDER BY Preference_Number ASC;
6431
6432 BEGIN
6433 --
6434 IF (l_debug <> -1) THEN
6435 rlm_core_sv.dpush(C_SDEBUG, 'GetInventoryItemId');
6436 END IF;
6437 --
6438 OPEN CI_XREF_Cur;
6439 FETCH CI_XREF_Cur INTO Temp_Master_Organization_Id,
6440 Temp_Inventory_Item_Id,
6441 Temp_Inactive_Flag;
6442
6443 IF (CI_XREF_Cur%NOTFOUND) THEN
6444 --
6445 IF (l_debug <> -1) THEN
6446 rlm_core_sv.dlog(C_SDEBUG, 'Inventory Item Id could not be derived');
6447 rlm_core_sv.dpop(C_DEBUG, 'GetInventoryItemId');
6448 END IF;
6449 --
6450 return null;
6451 --
6452 ELSIF (Temp_Inactive_Flag = 'Y') THEN
6453
6454 LOOP
6455
6456 FETCH CI_XREF_Cur INTO Temp_Master_Organization_Id,
6457 Temp_Inventory_Item_Id,
6458 Temp_Inactive_Flag;
6459
6460 IF (CI_XREF_Cur%NOTFOUND) THEN
6461 --
6462 IF (l_debug <> -1) THEN
6463 rlm_core_sv.dlog(C_SDEBUG, 'Inventory Item Id could not be derived');
6464 rlm_core_sv.dpop(C_DEBUG, 'GetInventoryItemId');
6465 END IF;
6466 --
6467 return null;
6468 --
6469 ELSIF (Temp_Inactive_Flag = 'N') THEN
6470 --
6471 v_inventory_item_id:=Temp_Inventory_Item_Id;
6472 --
6473 END IF;
6474 --
6475 EXIT WHEN ((CI_XREF_Cur%NOTFOUND) OR (Temp_Inactive_Flag = 'N'));
6476 --
6477 END LOOP;
6478
6479 ELSE
6480
6481 v_inventory_item_id:=Temp_Inventory_Item_Id;
6482
6483 END IF;
6484
6485 CLOSE CI_XREF_Cur;
6486
6487 --CURSOR
6488
6489 IF (l_debug <> -1) THEN
6490 rlm_core_sv.dlog(C_SDEBUG, 'inventory_item_id', v_inventory_item_id);
6491 rlm_core_sv.dpop(C_DEBUG, 'GetInventoryItemId');
6492 END IF;
6493 --
6494 return v_inventory_item_id;
6495 --
6496 EXCEPTION
6497
6498 when others then
6499 --
6500 IF (l_debug <> -1) THEN
6501 rlm_core_sv.dlog(C_SDEBUG, 'Inventory Item Id could not be derived');
6502 rlm_core_sv.dpop(C_DEBUG, 'GetInventoryItemId');
6503 END IF;
6504 --
6505 return null;
6506 --
6507 END;
6508
6509
6510 /*===========================================================================
6511
6512 Procedure GetLatestCum
6513 Parameters: x_cum_key_record: Has the information needed to retrive the
6514 cum key
6515 x_rlm_setup_terms_record: It has the setup terms info
6516 x_cum_record : returns the latest cum record
6517
6518 ============================================================================*/
6519
6520
6521
6522 PROCEDURE GetLatestCum (
6523 x_cum_key_record IN RLM_CUM_SV.cum_key_attrib_rec_type,
6524 x_rlm_setup_terms_record IN rlm_setup_terms_sv.setup_terms_rec_typ,
6525 x_cum_record IN OUT NOCOPY RLM_CUM_SV.cum_rec_type,
6526 x_called_from_vd IN NUMBER)
6527 IS
6528 v_cum_org_level_code rlm_cust_shipto_terms.cum_org_level_code%TYPE;
6529 p_ship_from_org_id NUMBER DEFAULT NULL;
6530 p_ship_to_address_id NUMBER DEFAULT NULL;
6531 p_intrmd_ship_to_address_id NUMBER DEFAULT NULL;
6532 p_bill_to_address_id NUMBER DEFAULT NULL;
6533 p_customer_item_id NUMBER DEFAULT NULL;
6534 p_purchase_order_number RLM_CUST_ITEM_CUM_KEYS.PURCHASE_ORDER_NUMBER%TYPE DEFAULT NULL;
6535 p_cust_record_year RLM_CUST_ITEM_CUM_KEYS.CUST_RECORD_YEAR%TYPE DEFAULT NULL;
6536 p_cum_start_date DATE DEFAULT NULL;
6537 E_UNEXPECTED EXCEPTION;
6538
6539
6540 /* The purpose of the following cursors is to get the cum key id,
6541 cum qty, cum start date, cust record year, po number, etc. that
6542 already exist in rlm_cust_item_cum_keys table. The cum record of
6543 interest is the one that got created last and which cum start date is
6544 no later than sysdate. */
6545
6546 /* This cursor is used when the proc is called by to get the latest cum
6547 and the cum control code is cum by date only and the cum organization
6548 level is not for all ship froms */
6549
6550 --
6551 CURSOR c_cum_by_date1 IS
6552 SELECT cum_key_id,
6553 cum_qty,
6554 cum_qty_to_be_accumulated,
6555 cum_qty_after_cutoff,
6556 last_cum_qty_update_date,
6557 cust_uom_code,
6558 cum_start_date,
6559 cust_record_year,
6560 purchase_order_number
6561 FROM RLM_CUST_ITEM_CUM_KEYS
6562 WHERE NVL(ship_from_org_id,0) = NVL(p_ship_from_org_id,0)
6563 AND NVL(ship_to_address_id,0) = NVL(p_ship_to_address_id,0)
6564 AND NVL(intrmd_ship_to_id,0)=
6565 NVL(p_intrmd_ship_to_address_id,0)
6566 AND NVL(bill_to_address_id,0)= NVL(p_bill_to_address_id,0)
6567 AND NVL(customer_item_id,0) = NVL(p_customer_item_id,0)
6568 AND cum_start_date IS NOT NULL
6569 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6570 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6571 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6572 )
6573 AND purchase_order_number IS NULL
6574 AND cust_record_year IS NULL
6575 AND NVL(inactive_flag,'N') = 'N'
6576 ORDER BY creation_date DESC;
6577 --
6578
6579 /* This cursor is used when the proc is called by to get the latest cum
6580 and the cum control code is cum by date only and the cum organization
6581 level is for all ship froms */
6582 --
6583 CURSOR c_cum_by_date2 IS
6584 SELECT cum_key_id,
6585 cum_qty,
6586 cum_qty_to_be_accumulated,
6587 cum_qty_after_cutoff,
6588 last_cum_qty_update_date,
6589 cust_uom_code,
6590 cum_start_date,
6591 cust_record_year,
6592 purchase_order_number
6593 FROM RLM_CUST_ITEM_CUM_KEYS
6594 WHERE ship_from_org_id IS NULL
6595 AND NVL(ship_to_address_id,0)= NVL(p_ship_to_address_id,0)
6596 AND NVL(intrmd_ship_to_id,0) =
6597 NVL(p_intrmd_ship_to_address_id,0)
6598 AND NVL(bill_to_address_id,0) = NVL(p_bill_to_address_id,0)
6599 AND NVL(customer_item_id,0)= NVL(p_customer_item_id,0)
6600 AND cum_start_date IS NOT NULL
6601 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6602 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6603 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6604 )
6605 AND purchase_order_number IS NULL
6606 AND cust_record_year IS NULL
6607 AND NVL(inactive_flag,'N') = 'N'
6608 ORDER BY creation_date DESC;
6609 --
6610
6611 /* This cursor is used when the proc is called by to get the latest cum
6612 and the cum control code is cum by date/record year and the cum
6613 organization level is not for all ship froms */
6614 --
6615 CURSOR c_cum_by_date_record_year1 IS
6616 SELECT cum_key_id,
6617 cum_qty,
6618 cum_qty_to_be_accumulated,
6619 cum_qty_after_cutoff,
6620 last_cum_qty_update_date,
6621 cust_uom_code,
6622 cum_start_date,
6623 cust_record_year,
6624 purchase_order_number
6625 FROM RLM_CUST_ITEM_CUM_KEYS
6626 WHERE NVL(ship_from_org_id,0)= NVL(p_ship_from_org_id,0)
6627 AND NVL(ship_to_address_id,0)= NVL(p_ship_to_address_id,0)
6628 AND NVL(intrmd_ship_to_id,0)
6629 = NVL(p_intrmd_ship_to_address_id,0)
6630 AND NVL(bill_to_address_id,0)= NVL(p_bill_to_address_id,0)
6631 AND NVL(customer_item_id,0)= NVL(p_customer_item_id,0)
6632 AND cum_start_date IS NOT NULL
6633 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6634 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6635 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6636 )
6637 AND purchase_order_number IS NULL
6638 AND cust_record_year IS NOT NULL
6639 AND (cust_record_year = p_cust_record_year
6640 OR p_cust_record_year IS NULL
6641 )
6642 AND NVL(inactive_flag,'N') = 'N'
6643 ORDER BY creation_date DESC;
6644 --
6645
6646 /* This cursor is used when the proc is called by to get the latest cum
6647 and the cum control code is cum by date/record year and the cum
6648 organization level is for all ship froms */
6649 --
6650 CURSOR c_cum_by_date_record_year2 IS
6651 SELECT cum_key_id,
6652 cum_qty,
6653 cum_qty_to_be_accumulated,
6654 cum_qty_after_cutoff,
6655 last_cum_qty_update_date,
6656 cust_uom_code,
6657 cum_start_date,
6658 cust_record_year,
6659 purchase_order_number
6660 FROM RLM_CUST_ITEM_CUM_KEYS
6661 WHERE ship_from_org_id IS NULL
6662 AND NVL(ship_to_address_id,0) = NVL(p_ship_to_address_id,0)
6663 AND NVL(intrmd_ship_to_id,0)
6664 = NVL(p_intrmd_ship_to_address_id,0)
6665 AND NVL(bill_to_address_id,0) = NVL(p_bill_to_address_id,0)
6666 AND NVL(customer_item_id,0) = NVL(p_customer_item_id,0)
6667 AND cum_start_date IS NOT NULL
6668 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6669 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6670 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6671 )
6672 AND purchase_order_number IS NULL
6673 AND cust_record_year IS NOT NULL
6674 AND (cust_record_year = p_cust_record_year
6675 OR p_cust_record_year IS NULL
6676 )
6677 AND NVL(inactive_flag,'N') = 'N'
6678 ORDER BY creation_date DESC;
6679 --
6680
6681 /* This cursor is used when the proc is called by to get the latest cum
6682 and the cum control code is cum by date/po and the cum
6683 organization level is not for all ship froms */
6684 --
6685 CURSOR c_cum_by_date_po1 IS
6686 SELECT cum_key_id,
6687 cum_qty,
6688 cum_qty_to_be_accumulated,
6689 cum_qty_after_cutoff,
6690 last_cum_qty_update_date,
6691 cust_uom_code,
6692 cum_start_date,
6693 cust_record_year,
6694 purchase_order_number
6695 FROM RLM_CUST_ITEM_CUM_KEYS
6696 WHERE NVL(ship_from_org_id,0)= NVL(p_ship_from_org_id,0)
6697 AND NVL(ship_to_address_id,0)= NVL(p_ship_to_address_id,0)
6698 AND NVL(intrmd_ship_to_id,0)
6699 = NVL(p_intrmd_ship_to_address_id,0)
6700 AND NVL(bill_to_address_id,0)= NVL(p_bill_to_address_id,0)
6701 AND NVL(customer_item_id,0) = NVL(p_customer_item_id,0)
6702 AND cum_start_date IS NOT NULL
6703 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6704 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6705 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6706 )
6707 AND purchase_order_number IS NOT NULL
6708 AND (purchase_order_number = p_purchase_order_number
6709 OR p_purchase_order_number IS NULL
6710 )
6711 AND cust_record_year IS NULL
6712 AND NVL(inactive_flag,'N') = 'N'
6713 ORDER BY creation_date DESC;
6714 --
6715
6716 /* This cursor is used when the proc is called by to get the latest cum
6717 and the cum control code is cum by date/po and the cum organization
6718 level is for all ship froms */
6719 --
6720 CURSOR c_cum_by_date_po2 IS
6721 SELECT cum_key_id,
6722 cum_qty,
6723 cum_qty_to_be_accumulated,
6724 cum_qty_after_cutoff,
6725 last_cum_qty_update_date,
6726 cust_uom_code,
6727 cum_start_date,
6728 cust_record_year,
6729 purchase_order_number
6730 FROM RLM_CUST_ITEM_CUM_KEYS
6731 WHERE ship_from_org_id IS NULL
6732 AND NVL(ship_to_address_id,0) = NVL(p_ship_to_address_id,0)
6733 AND NVL(intrmd_ship_to_id,0)
6734 = NVL(p_intrmd_ship_to_address_id,0)
6735 AND NVL(bill_to_address_id,0) = NVL(p_bill_to_address_id,0)
6736 AND NVL(customer_item_id,0)= NVL(p_customer_item_id,0)
6737 AND cum_start_date IS NOT NULL
6738 --AND (cum_start_date < SYSDATE --Bugfix 10053830
6739 AND (cum_start_date < nvl(rlm_dp_sv.g_dsp_start_time,sysdate) --Bugfix 10053830
6740 OR x_called_from_vd = rlm_cum_sv.k_CalledByVD
6741 )
6742
6743 AND purchase_order_number IS NOT NULL
6744 AND (purchase_order_number = p_purchase_order_number
6745 OR p_purchase_order_number IS NULL
6746 )
6747 AND cust_record_year IS NULL
6748 AND NVL(inactive_flag,'N') = 'N'
6749 ORDER BY creation_date DESC;
6750 --
6751 BEGIN
6752 --
6753 IF (l_debug <> -1) THEN
6754 rlm_core_sv.dpush(C_SDEBUG, 'GetLatestCum');
6755 rlm_core_sv.dlog(C_DEBUG, 'ship_to_address_id',
6756 x_cum_key_record.ship_to_address_id);
6757 rlm_core_sv.dlog(C_DEBUG, 'ship_from_org_id',
6758 x_cum_key_record.ship_from_org_id);
6759 rlm_core_sv.dlog(C_DEBUG, 'bill_to_address_id',
6760 x_cum_key_record.bill_to_address_id);
6761 rlm_core_sv.dlog(C_DEBUG, 'intrmd_ship_to_address_id',
6762 x_cum_key_record.intrmd_ship_to_address_id);
6763 rlm_core_sv.dlog(C_DEBUG, 'customer_item_id',
6764 x_cum_key_record.customer_item_id);
6765 rlm_core_sv.dlog(C_DEBUG, 'purchase_order_number',
6766 x_cum_key_record.purchase_order_number);
6767 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_key_record.cum_start_date);
6768 rlm_core_sv.dlog(C_DEBUG, 'cust_record_year',
6769 x_cum_key_record.cust_record_year);
6770 END IF;
6771 --
6772 v_cum_org_level_code := x_rlm_setup_terms_record.cum_org_level_code;
6773 --
6774 p_customer_item_id := x_cum_key_record.customer_item_id;
6775 p_ship_from_org_id := x_cum_key_record.ship_from_org_id;
6776 --
6777 IF (l_debug <> -1) THEN
6778 rlm_core_sv.dlog(C_DEBUG, 'cum_control_code',
6779 x_rlm_setup_terms_record.cum_control_code);
6780 rlm_core_sv.dlog(C_DEBUG, 'cum_org_level_code', v_cum_org_level_code);
6781 END IF;
6782 --
6783 x_cum_record.cum_key_id := NULL;
6784 --
6785 IF v_cum_org_level_code = 'BILL_TO_SHIP_FROM' THEN--{
6786 --
6787 IF x_cum_key_record.bill_to_address_id IS NULL THEN--{
6788 --
6789 IF (l_debug <> -1) THEN
6790 rlm_core_sv.dlog(C_DEBUG, 'Error:',
6791 'RLM_CUM_BILL_TO_REQUIRED');
6792 END IF;
6793 --
6794 RAISE E_UNEXPECTED;
6795 --
6796 END IF;--}
6797 --
6798 p_bill_to_address_id := x_cum_key_record.bill_to_address_id;
6799 --
6800 ELSIF v_cum_org_level_code = 'SHIP_TO_SHIP_FROM' THEN--}{
6801 --
6802 IF x_cum_key_record.ship_to_address_id IS NULL THEN--{
6803 --
6804 IF (l_debug <> -1) THEN
6805 rlm_core_sv.dlog(C_DEBUG, 'Error:', 'RLM_CUM_SHIP_TO_REQUIRED');
6806 END IF;
6807 --
6808 RAISE E_UNEXPECTED;
6809 --
6810 END IF;--}
6811 --
6812 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
6813 --
6814 ELSIF v_cum_org_level_code = 'INTRMD_SHIP_TO_SHIP_FROM' THEN--}{
6815 --
6816 IF x_cum_key_record.intrmd_ship_to_address_id IS NULL THEN--{
6817 --
6818 IF (l_debug <> -1) THEN
6819 rlm_core_sv.dlog(C_DEBUG, 'Error:',
6820 'RLM_CUM_INTER_SHIP_TO_REQUIRED');
6821 END IF;
6822 --
6823 RAISE E_UNEXPECTED;
6824 --
6825 END IF;--}
6826 --
6827 p_intrmd_ship_to_address_id :=
6828 x_cum_key_record.intrmd_ship_to_address_id;
6829 ELSIF v_cum_org_level_code = 'SHIP_TO_ALL_SHIP_FROMS' THEN --}{
6830 p_ship_to_address_id := x_cum_key_record.ship_to_address_id;
6831 p_ship_from_org_id := NULL;
6832 --
6833 ELSE--}{
6834 --
6835 IF (l_debug <> -1) THEN
6836 rlm_core_sv.dlog(C_DEBUG, 'Error:', 'RLM_CUM_UNKNOWN_ORG_LEVEL');
6837 END IF;
6838 --
6839 RAISE E_UNEXPECTED;
6840 --
6841 END IF;--}
6842 --
6843 --Open the cursors previously defined and fetch only the first row of records
6844 --
6845 IF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_ONLY'
6846 OR x_rlm_setup_terms_record.cum_control_code = 'CUM_UNTIL_MANUAL_RESET' THEN--{
6847 --
6848 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN--{
6849 --
6850 OPEN c_cum_by_date1;
6851 --
6852 FETCH c_cum_by_date1
6853 INTO x_cum_record.cum_key_id,
6854 x_cum_record.cum_qty,
6855 x_cum_record.cum_qty_to_be_accumulated,
6856 x_cum_record.cum_qty_after_cutoff,
6857 x_cum_record.last_cum_qty_update_date,
6858 x_cum_record.cust_uom_code,
6859 p_cum_start_date,
6860 p_cust_record_year,
6861 p_purchase_order_number;
6862 --
6863 CLOSE c_cum_by_date1;
6864 ELSE--}{
6865 --
6866 OPEN c_cum_by_date2;
6867 FETCH c_cum_by_date2
6868 INTO x_cum_record.cum_key_id,
6869 x_cum_record.cum_qty,
6870 x_cum_record.cum_qty_to_be_accumulated,
6871 x_cum_record.cum_qty_after_cutoff,
6872 x_cum_record.last_cum_qty_update_date,
6873 x_cum_record.cust_uom_code,
6874 p_cum_start_date,
6875 p_cust_record_year,
6876 p_purchase_order_number;
6877 --
6878 CLOSE c_cum_by_date2;
6879 END IF;--}
6880 --
6881 ELSIF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_RECORD_YEAR' THEN--}{
6882 --
6883 p_cust_record_year := x_cum_key_record.cust_record_year;
6884 --
6885 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN--{
6886 --
6887 OPEN c_cum_by_date_record_year1;
6888 --
6889 FETCH c_cum_by_date_record_year1
6890 INTO x_cum_record.cum_key_id,
6891 x_cum_record.cum_qty,
6892 x_cum_record.cum_qty_to_be_accumulated,
6893 x_cum_record.cum_qty_after_cutoff,
6894 x_cum_record.last_cum_qty_update_date,
6895 x_cum_record.cust_uom_code,
6896 p_cum_start_date,
6897 p_cust_record_year,
6898 p_purchase_order_number;
6899 --
6900 CLOSE c_cum_by_date_record_year1;
6901 ELSE--}{
6902 --
6903 OPEN c_cum_by_date_record_year2;
6904 --
6905 FETCH c_cum_by_date_record_year2
6906 INTO x_cum_record.cum_key_id,
6907 x_cum_record.cum_qty,
6908 x_cum_record.cum_qty_to_be_accumulated,
6909 x_cum_record.cum_qty_after_cutoff,
6910 x_cum_record.last_cum_qty_update_date,
6911 x_cum_record.cust_uom_code,
6912 p_cum_start_date,
6913 p_cust_record_year,
6914 p_purchase_order_number;
6915 CLOSE c_cum_by_date_record_year2;
6916 --
6917 END IF;--}
6918 --
6919 ELSIF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_DATE_PO' THEN--}{
6920 --
6921 p_purchase_order_number := x_cum_key_record.purchase_order_number;
6922 --
6923 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN--{
6924 --
6925 OPEN c_cum_by_date_po1;
6926 --
6927 FETCH c_cum_by_date_po1
6928 INTO x_cum_record.cum_key_id,
6929 x_cum_record.cum_qty,
6930 x_cum_record.cum_qty_to_be_accumulated,
6931 x_cum_record.cum_qty_after_cutoff,
6932 x_cum_record.last_cum_qty_update_date,
6933 x_cum_record.cust_uom_code,
6934 p_cum_start_date,
6935 p_cust_record_year,
6936 p_purchase_order_number;
6937 --
6938 CLOSE c_cum_by_date_po1;
6939 --
6940 ELSE--}{
6941 --
6942 OPEN c_cum_by_date_po2;
6943 --
6944 FETCH c_cum_by_date_po2
6945 INTO x_cum_record.cum_key_id,
6946 x_cum_record.cum_qty,
6947 x_cum_record.cum_qty_to_be_accumulated,
6948 x_cum_record.cum_qty_after_cutoff,
6949 x_cum_record.last_cum_qty_update_date,
6950 x_cum_record.cust_uom_code,
6951 p_cum_start_date,
6952 p_cust_record_year,
6953 p_purchase_order_number;
6954 --
6955 CLOSE c_cum_by_date_po2;
6956 --
6957 END IF;--}
6958 --
6959 --Bug 4307505 uncommented the code
6960 ELSIF x_rlm_setup_terms_record.cum_control_code = 'CUM_BY_PO_ONLY' THEN--}{
6961
6962 p_purchase_order_number := x_cum_key_record.purchase_order_number;
6963
6964 IF v_cum_org_level_code <> 'SHIP_TO_ALL_SHIP_FROMS' THEN--{
6965 --
6966 SELECT cum_key_id,
6967 cum_qty,
6968 cum_qty_to_be_accumulated,
6969 cum_qty_after_cutoff,
6970 last_cum_qty_update_date,
6971 cust_uom_code
6972 INTO x_cum_record.cum_key_id,
6973 x_cum_record.cum_qty,
6974 x_cum_record.cum_qty_to_be_accumulated,
6975 x_cum_record.cum_qty_after_cutoff,
6976 x_cum_record.last_cum_qty_update_date,
6977 x_cum_record.cust_uom_code
6978 FROM RLM_CUST_ITEM_CUM_KEYS
6979 WHERE NVL(ship_from_org_id,0) = NVL(p_ship_from_org_id,0)
6980 AND NVL(ship_to_address_id,0)
6981 = NVL(p_ship_to_address_id,0)
6982 AND NVL(intrmd_ship_to_id,0)
6983 = NVL(p_intrmd_ship_to_address_id,0)
6984 AND NVL(bill_to_address_id,0)
6985 = NVL(p_bill_to_address_id,0)
6986 AND NVL(customer_item_id,0)
6987 = NVL(p_customer_item_id,0)
6988 AND purchase_order_number = NVL(p_purchase_order_number, ' ')
6989 AND NVL(cust_record_year, ' ')
6990 = NVL(p_cust_record_year, ' ')
6991 AND NVL(cum_start_date, sysdate)
6992 = NVL(p_cum_start_date, sysdate)
6993 AND purchase_order_number IS NOT NULL
6994 AND NVL(inactive_flag,'N') = 'N'
6995 ORDER BY creation_date desc ;
6996 --
6997 ELSE--}{
6998 --
6999 SELECT cum_key_id,
7000 cum_qty,
7001 cum_qty_to_be_accumulated,
7002 cum_qty_after_cutoff,
7003 last_cum_qty_update_date,
7004 cust_uom_code
7005 INTO x_cum_record.cum_key_id,
7006 x_cum_record.cum_qty,
7007 x_cum_record.cum_qty_to_be_accumulated,
7008 x_cum_record.cum_qty_after_cutoff,
7009 x_cum_record.last_cum_qty_update_date,
7010 x_cum_record.cust_uom_code
7011 FROM RLM_CUST_ITEM_CUM_KEYS
7012 WHERE ship_from_org_id IS NULL
7013 AND NVL(ship_to_address_id, 0)
7014 = NVL(p_ship_to_address_id,0)
7015 AND NVL(intrmd_ship_to_id, 0)
7016 = NVL(p_intrmd_ship_to_address_id,0)
7017 AND NVL(bill_to_address_id, 0)
7018 = NVL(p_bill_to_address_id,0)
7019 AND NVL(customer_item_id, 0)
7020 = NVL(p_customer_item_id,0)
7021 AND purchase_order_number = NVL(p_purchase_order_number, ' ')
7022 AND NVL(cust_record_year, ' ')
7023 = NVL(p_cust_record_year, ' ')
7024 AND NVL(cum_start_date, sysdate)
7025 = NVL(p_cum_start_date, sysdate)
7026 AND NVL(inactive_flag,'N') = 'N'
7027 AND purchase_order_number IS NOT NULL
7028 ORDER BY creation_date desc ;
7029 --
7030 END IF;--}
7031 --
7032
7033 END IF;--}
7034 --
7035 IF (l_debug <> -1) THEN
7036 rlm_core_sv.dlog(C_DEBUG, 'p_ship_from_org_id', p_ship_from_org_id);
7037 rlm_core_sv.dlog(C_DEBUG, 'p_ship_to_address_id', p_ship_to_address_id);
7038 rlm_core_sv.dlog(C_DEBUG, 'p_intrmd_ship_to_address_id', p_intrmd_ship_to_address_id);
7039 rlm_core_sv.dlog(C_DEBUG, 'p_bill_to_address_id', p_bill_to_address_id);
7040 rlm_core_sv.dlog(C_DEBUG, 'p_customer_item_id', p_customer_item_id);
7041 rlm_core_sv.dlog(C_DEBUG, 'p_purchase_order_number', p_purchase_order_number);
7042 rlm_core_sv.dlog(C_DEBUG, 'p_cust_record_year', p_cust_record_year);
7043 rlm_core_sv.dlog(C_DEBUG, 'p_cum_start_date', p_cum_start_date);
7044 END IF;
7045 --
7046 x_cum_record.cum_start_date := p_cum_start_date;
7047 --
7048 IF x_cum_record.cum_key_id IS NOT NULL THEN
7049 --
7050 x_cum_record.record_return_status := TRUE;
7051 --
7052 IF (x_called_from_vd = rlm_cum_sv.k_CalledByVD )
7053 AND NVL(x_cum_record.cum_start_date,SYSDATE) > SYSDATE
7054 THEN
7055 --
7056 x_cum_record.msg_name := 'RLM_CUM_START_FUTURE';
7057 --
7058 IF (l_debug <> -1) THEN
7059 rlm_core_sv.dlog(C_DEBUG, 'RLM_CUM_START_FUTURE');
7060 END IF;
7061 --
7062 END IF;
7063 --
7064 ELSE
7065 --
7066 x_cum_record.record_return_status := FALSE;
7067 --
7068 x_cum_record.msg_name := 'RLM_NO_ACTIVE_CUM_SP';
7069 --
7070 rlm_message_sv.get_msg_text(
7071 x_message_name => x_cum_record.msg_name ,
7072 x_text => x_cum_record.msg_data);
7073
7074 --
7075 END IF;
7076 --
7077 IF x_cum_record.cum_qty IS NULL THEN
7078 x_cum_record.cum_qty := 0;
7079 END IF;
7080
7081 IF x_cum_record.cum_qty_to_be_accumulated IS NULL THEN
7082 x_cum_record.cum_qty_to_be_accumulated := 0;
7083 END IF;
7084
7085 IF x_cum_record.cum_qty_after_cutoff IS NULL THEN
7086 x_cum_record.cum_qty_after_cutoff := 0;
7087 END IF;
7088
7089 IF (l_debug <> -1) THEN
7090 rlm_core_sv.dlog(C_DEBUG, 'cum_key_id', x_cum_record.cum_key_id);
7091 rlm_core_sv.dlog(C_DEBUG, 'cum_start_date', x_cum_record.cum_start_date);
7092 rlm_core_sv.dlog(C_DEBUG, 'cum_qty', x_cum_record.cum_qty);
7093 rlm_core_sv.dlog(C_DEBUG, 'record_return_status',
7094 x_cum_record.record_return_status);
7095 rlm_core_sv.dpop(C_DEBUG,'GetLatestCum');
7096 END IF;
7097 --
7098 EXCEPTION
7099 --
7100 WHEN E_UNEXPECTED THEN
7101 --
7102 x_cum_record.record_return_status := FALSE;
7103 --
7104 x_cum_record.msg_name := 'RLM_NO_ACTIVE_CUM_SP';
7105 --
7106 rlm_message_sv.get_msg_text(
7107 x_message_name => x_cum_record.msg_name ,
7108 x_text => x_cum_record.msg_data);
7109
7110 --
7111 IF (l_debug <> -1) THEN
7112 rlm_core_sv.dpop(C_DEBUG,'E_UNEXPECTED');
7113 END IF;
7114 --
7115 WHEN OTHERS THEN
7116 --
7117 x_cum_record.record_return_status := FALSE;
7118 --
7119 x_cum_record.msg_name := 'RLM_NO_ACTIVE_CUM_SP';
7120 --
7121 rlm_message_sv.get_msg_text(
7122 x_message_name => x_cum_record.msg_name ,
7123 x_text => x_cum_record.msg_data);
7124
7125 --
7126 IF (l_debug <> -1) THEN
7127 rlm_core_sv.dlog(C_DEBUG, 'when others');
7128 rlm_core_sv.dpop(C_DEBUG, substr(SQLERRM,1,200));
7129 END IF;
7130 --
7131 END GetLatestCum;
7132
7133
7134 /*=========================================================================
7135
7136 PROCEDURE NAME: LockCumKey
7137
7138 Parameter: x_CumKeyId IN NUMBER
7139
7140 Created by: jckwok
7141
7142 Creation Date: June 15, 2004
7143
7144 History: Created due to Bug 3688778
7145
7146 ===========================================================================*/
7147
7148 FUNCTION LockCumKey (x_CumKeyId IN NUMBER)
7149 RETURN BOOLEAN
7150 IS
7151 --
7152 CURSOR c IS
7153 SELECT *
7154 FROM RLM_CUST_ITEM_CUM_KEYS_ALL
7155 WHERE cum_key_id = x_CumKeyId
7156 FOR UPDATE NOWAIT;
7157 --
7158
7159 BEGIN
7160 --
7161 IF (l_debug <> -1) THEN
7162 rlm_core_sv.dpush(C_SDEBUG,'LockCumKey');
7163 rlm_core_sv.dlog(C_DEBUG,'Locking RLM_CUST_ITEM_CUM_KEYS_ALL');
7164 END IF;
7165 --
7166 OPEN c;
7167 CLOSE c;
7168 --
7169 IF (l_debug <> -1) THEN
7170 rlm_core_sv.dpop(C_SDEBUG);
7171 END IF;
7172 --
7173 RETURN(TRUE);
7174 --
7175 EXCEPTION
7176 --
7177 WHEN APP_EXCEPTION.RECORD_LOCK_EXCEPTION THEN
7178 --
7179 IF (l_debug <> -1) THEN
7180 rlm_core_sv.dlog(C_DEBUG,'Cum Key Record in RLM_CUST_ITEM_CUM_KEYS_ALL cannot be locked');
7181 rlm_core_sv.dpop(C_SDEBUG);
7182 END IF;
7183 --
7184 RETURN(FALSE);
7185 --
7186 WHEN OTHERS THEN
7187 --
7188 rlm_message_sv.sql_error('Locking Cum Key Failed', 'rlm_cum_sv.LockCumKey');
7189 --
7190 IF (l_debug <> -1) THEN
7191 rlm_core_sv.dpop(C_SDEBUG,'EXCEPTION: OTHER - sql error');
7192 END IF;
7193 --
7194 RAISE;
7195 --
7196 END LockCumKey;
7197
7198
7199 END RLM_CUM_SV;