[Home] [Help]
PACKAGE BODY: APPS.OZF_ADJUSTMENT_EXT_PVT
Source
1 PACKAGE BODY ozf_adjustment_ext_pvt AS
2 /*$Header: ozfvadeb.pls 120.69.12020000.14 2013/02/19 07:52:48 nepanda ship $*/
3
4 -----------------------------------------------------------
5 -- PACKAGE
6 -- OZF_Adjustment_EXT_PVT
7 --
8 -- PROCEDURES
9 -- adjust_backdated_offer
10 -- process_offer_product
11 -- HISTORY
12 -- 4/18/2002 Mumu Pande Create.
13 -- 10/17/2003 Ying Zhao fix bug 3197570 - BACKDATED ADJUSTMENTS FOR AMOUNT TYPE DICOUNT RULE
14 -- 12/14/2003 kdass changed table name from ams_temp_eligibility to ozf_temp_eligibility
15 -- 02/09/2004 yzhao fix bug MASS1R1011510:REOP:VOLUME OFFER DISCOUNT LEVL NOT CHANGING EVEN AFTER REACHG VOL
16 -- offer notes object should remain in AMS_OFFR, not OZF_OFFR
17 -- 07/08/2004 kdass changed the dynamic cursors in perform_adjustment to static cursors
18 -- 07/19/2004 kdass fix for 11.5.9 bug 3742174
19 -- 16/11/2004 Ribha Fix for bug 4013141 - Volume offer adjustment should get applied only when there is a tier-change.
20 -- 17/11/2004 Ribha Fix for bug 4015372 - Backdated adjustments should not get closed if not applied.
21 -- 01/05/2005 kdass fix for 11.5.9 bug 4033558 - handle volume offer adjustments for RMA order
22 -- 01/31/2005 kdass fix for 11.5.10 bug 4129759 - handle backdated adjustments for multi-tier discounts
23 -- 05/05/2005 Ribha fix for bug 4309014
24 -- 05/11/2005 Ribha fix for bug 4357772
25 -- 05/11/2005 kdass fix for 11.5.10 bug 4362575 - for all types of volume offers - offinvoice or accrual,
26 -- consider list price instead of selling price
27 -- 08/16/2005 feliu fix backdated adjustment for third party accrual.
28 -- Third party accrual support following offers:
29 -- Accrual, off-invoice, trade deal.
30 -- 12/09/2005 kdass fix for bug 4872799
31 -- 02/28/2006 kdass fixed bug 5059735
32 -- 03/31/2006 kdass fixed bug 5101720
33 -- 05/05/2006 kdass fixed bugs 5205721, 5198547
34 -- 06/21/2006 kdass fixed bug 5337761
35 -- 07/31/2006 kpatro fixed bug 5375224 for SQL ID# 19125146
36 -- 08/04/2006 kdass fixed bug 5446622
37 -- 08/24/2006 kdass fixed bug 5485172
38 -- 09/11/2006 kdass fixed bug 5497876
39 -- 12/04/2006 feliu fixed bug 5675871,5671169,and 5689866
40 -- 02/24/2007 kdass fixed bug 5610124 - retroactive adjustments for volume offer before offer start date
41 -- 04/04/2007 nirprasa fix for bug 5944862
42 -- 04/13/2007 nirprasa fixed bug 5975203
43 -- 04/13/2007 nirprasa fixed bug 5767748
44 -- 04/13/2007 nirprasa fixed bug 5979971
45 -- 05/11/2007 nirprasa fixed bug 6021635 - added volume_offer_util_adjustment for utilized amount and
46 -- changed adjustment_volume_retro for booked orders.
47 -- 05/21/2007 kdass fixed bug 6059036
48 -- 05/28/2007 nirprasa fixed bug 6077042
49 -- 06/27/2007 nirprasa fixed bug 6021538
50 -- 08/16/2007 nirprasa fixed bug 6345305
51 -- 08/16/2007 nirprasa fixed bug 6369218
52 -- 04/21/2008 psomyaju Bugfix 6278466 - FP:11510-R12 6051298 - FUNDS EARNED NOT RECOGNISED AS ELIGBLE FOR
53 -- 08/01/2008 nirprasa fixed bug 7030415
54 -- 05/24/2009 kdass fixed bug 8510774 - FP: 11.5.10-R12 8408922 - TMR4: OFFER ADJUSTMENTS FAIL AND NO OFFER ADJUSTMENTS
55 -- 1/27/2010 nepanda Fix for bug 9318975 - volume offer with discount amount tiers has no accrued earnings as there should
56 -- 2/17/2010 nepanda Bug 9131648 : multi currency changes
57 -- 12/27/2010 kdass fixed bug 10305820 (FP 10229781)- OFFER ADJUSTMENT CREATE ACCRUALS BASED ON ORDERED UOM NOT THE PRICING UOM
58 -- 8/11/2011 nepanda Fix for bug 12660466 - idsm backdating adjustment created a duplicate accrual
59 -- 10/10/2011 nirprasa fixed bug 13061780 - DIVISOR BY ZERO ERROR IN FUNDS ACCRUAL ENGINE
60 -- 10/13/2011 nirprasa ER10157845 ER: NEED BACKDATING ADJUSTMENT FUNCTIONALITY FOR SUPPLIER SHIP & DEBIT OFFERS
61 -- 11/17/2011 kdass fixed bug 13322965 FAE CREATING INCORRECT ADJUSTMENT FOR INDIRECT ORDERS WHEN DISCOUNT IS NEW PRICE [leapfrog of 120.55.12010000.11]
62 -- 11/25/2011 nirprasa fixed bug 13448056 TST1213:SSDADJ :- ADDING NEW PRODUCT VIA ADJUSTMENT IS NOT WORKING FINE
63 -- [merged the changes of bugfix 13322965]
64 -- 12/20/2011 nirprasa 13406517 - TST1213:SSDADJ:CALCULATION INCORRECT IF ONE ITEM
65 -- ADDED MULTIPLE TIMES TO OFFER
66 -- 01/04/2012 nirprasa 13535147 - R.TST1213:SSDADJ: ELIG USING SEEDED QUALIFIERS (BK DATED ADJ)NOT WKING AS EXPECT
67 -- 02/28/2012 nirprasa 13579540 - R.TST1213:FAE IS GETTING COMPLETED WITH ERROR IN CZ8ST214
68 -- 03/15/2012 nirprasa - Decrease Adjustment Bug. ER10157845
69 -- 03/21/2012 nirprasa - REGULAR ADJUSTMENT INCORRECT FOR CURRENT DAY ORDER(SYSDATE)
70 -- 8/29/2012 nepanda - Bug 14521452 - backdated offer adjustment with null currency stays as active
71 -- 10/3/2012 ninarasi Bug 14610746 - ORA-20010: GLMCCURB ERROR IN FUNDS ACCRUAL ENGINE
72 -- 10/31/2012 nirprasa Bug 14811824 - OFFER ADJUSTMENTS ARE NOT GETTING CLOSED AFTER RUNNING FAE TO ADJUST THE OFFER
73 -- 11/29/2012 ninarasi Bug 15877269 - OFFER IN TRADE PLANNING CREATING IMPROPER ADJUSTMENTS
74 -- 12/30/2012 amitamku Bug 15935374 - FAE COMPLETES WITH ERROR FOR VOLUME OFFER WITH MULTIPLE DISCOUNT TABLES
75 -- 01/16/2013 ninarasi Bug 16029659 - OFFER IN TRADE PLANNING CREATING IMPROPER ADJUSTMENTS
76 ---------------------------------------------------------------------------------------------------
77
78 g_pkg_name CONSTANT VARCHAR2 (30) := 'OZF_Adjustment_Ext_PVT';
79 g_recal_flag CONSTANT VARCHAR2(1) := NVL(fnd_profile.value('OZF_BUDGET_ADJ_ALLOW_RECAL'),'N');
80 g_order_gl_phase CONSTANT VARCHAR2 (15) :=NVL(fnd_profile.VALUE ('OZF_ORDER_GLPOST_PHASE'), 'SHIPPED');
81 g_debug_flag VARCHAR2 (1) := 'N';
82 G_DEBUG BOOLEAN := FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_debug_high);
83 -- 13579540 changed g_bulk_limit from 5k to 10k as per the discussion with performance team
84 -- Also, we would want to see the performance on customer's instance and then decide on the
85 -- use of profile OZF: Bulk Limit Size
86 g_bulk_limit CONSTANT NUMBER := 10000;
87
88 TYPE amountTbl IS TABLE OF ozf_funds_utilized_all_b.amount%TYPE;
89 TYPE glDateTbl IS TABLE OF ozf_funds_utilized_all_b.gl_date%TYPE;
90 TYPE exchangeRateDateTbl IS TABLE OF ozf_funds_utilized_all_b.exchange_rate_date%TYPE;
91 TYPE objectTypeTbl IS TABLE OF ozf_funds_utilized_all_b.object_type%TYPE;
92 TYPE objectIdTbl IS TABLE OF ozf_funds_utilized_all_b.object_id%TYPE;
93 TYPE priceAdjustmentIDTbl IS TABLE OF ozf_funds_utilized_all_b.price_adjustment_id%TYPE;
94 TYPE glPostedFlagTbl IS TABLE OF ozf_funds_utilized_all_b.gl_posted_flag%TYPE;
95 TYPE orderLineIdTbl IS TABLE OF ozf_funds_utilized_all_b.order_line_id%TYPE;
96 TYPE utilizationIdTbl IS TABLE OF ozf_funds_utilized_all_b.utilization_id%TYPE; --Added for bug 7030415
97
98 TYPE order_line_rec_type IS RECORD(order_header_id NUMBER
99 ,order_line_id NUMBER
100 ,inventory_item_id NUMBER
101 ,unit_list_price NUMBER
102 ,quantity NUMBER
103 ,transactional_curr_code oe_order_headers_all.transactional_curr_code%TYPE
104 ,line_category_code oe_order_lines_all.line_category_code%TYPE
105 ,reference_line_id NUMBER
106 ,order_number NUMBER
107 ,group_nos VARCHAR2(256)
108 ,uom_ratio NUMBER
109 );
110
111 TYPE order_line_tbl_type IS TABLE OF order_line_rec_type INDEX BY BINARY_INTEGER;
112 TYPE offer_id_tbl IS TABLE OF NUMBER index by binary_integer;
113 TYPE product_attr_val_cursor_type is ref cursor;
114 TYPE purchase_price_cursor_type is ref cursor;
115 g_offer_id_tbl offer_id_tbl;
116 l_adjIdByListLineId numberTbl;
117
118
119 -------------------------------------------------------------------
120 -- PROCEDURE
121 -- process_offer_product
122 -- PURPOSE
123 --
124 -- PARAMETERS
125 -- p_offer_adjustment_id IN NUMBER
126 -- History
127 -- 4/18/2002 Mumu Pande Create.
128 ----------------------------------------------------------------
129 PROCEDURE process_offer_product (
130 p_offer_adjustment_id IN NUMBER,
131 x_return_status OUT NOCOPY VARCHAR2
132 );
133
134 ---------------------------------------------------------------------
135 -- PROCEDURE
136 -- perform_adjustment
137 --
138 -- PURPOSE
139 --
140 -- PARAMETERS
141 -- p_from_date IN DATE
142 -- p_to_Date IN DATE
143 -- p_qp_list_header_id IN NUMBER
144 -- NOTES
145 -- HISTORY
146 -- 4/18/2002 Mumu Pande Create.
147 ----------------------------------------------------------------------
148 PROCEDURE perform_adjustment (
149 p_from_date IN DATE,
150 p_to_date IN DATE,
151 p_qp_list_header_id IN NUMBER,
152 p_offer_adjustment_id IN NUMBER,
153 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
154 p_commit IN VARCHAR2 := fnd_api.g_false,
155 x_return_status OUT NOCOPY VARCHAR2,
156 x_msg_count OUT NOCOPY NUMBER,
157 x_msg_data OUT NOCOPY VARCHAR2
158 );
159
160
161 ------------------------------------------------------------------------------
162 -- Procedure Name
163 -- write_con_log
164 -- Purpose
165 -- to write some debug message in the log file
166 -- History
167 -- 7/22/2002 mpande Created
168 -- 10/21/2002 mpande Changed for GSCC warnings
169 ------------------------------------------------------------------------------
170 PROCEDURE write_conc_log ( p_text IN VARCHAR2)
171 IS
172 BEGIN
173 IF g_debug_flag = 'Y' THEN
174 ozf_utility_pvt.write_conc_log (p_text);
175 --ozf_utility_pvt.debug_message(p_text);
176 END IF;
177 END;
178
179 ---------------------------------------------------------------------
180 -- PROCEDURE
181 -- get_orders
182 -- PURPOSE
183 -- returns qualified orders (copy of ozf_net_accrual_engine_pvt.offer_adj_new_product)
184 -- HISTORY
185 -- 12/30/2005 kdass Created
186 ----------------------------------------------------------------------
187 PROCEDURE get_orders(
188 p_api_version IN NUMBER
189 ,p_init_msg_list IN VARCHAR2
190 ,p_commit IN VARCHAR2
191 ,x_return_status OUT NOCOPY VARCHAR2
192 ,x_msg_count OUT NOCOPY NUMBER
193 ,x_msg_data OUT NOCOPY VARCHAR2
194 ,p_list_header_id IN NUMBER
195 ,p_offer_org_id IN NUMBER
196 ,p_offer_currency IN VARCHAR2
197 ,p_offer_uom_code IN VARCHAR2
198 ,p_arithmetic_operator IN VARCHAR2
199 ,p_list_line_id IN VARCHAR2
200 ,p_start_date IN DATE
201 ,p_end_date IN DATE
202 ,x_order_line_tbl OUT NOCOPY order_line_tbl_type)
203 IS
204
205 --kdass 05-MAY-2006 bug 5198547 - split cursor c_order_line into 2 for using hints suggested by perf team
206 CURSOR c_order_line IS
207 SELECT /*+ leading(temp) use_nl(temp line header) */
208 line.header_id, line.line_id, line.inventory_item_id, line.unit_list_price,
209 NVL(line.shipped_quantity, NVL(line.ordered_quantity, 0)) quantity,
210 header.transactional_curr_code, line.invoice_to_org_id,
211 line.sold_to_org_id, line.ship_to_org_id,line.line_category_code, line.reference_line_id,
212 header.order_number, header.org_id, line.order_quantity_uom, line.pricing_quantity_uom
213 FROM oe_order_lines_all line, oe_order_headers_all header,
214 (SELECT DISTINCT eligibility_id FROM ozf_temp_eligibility) temp
215 WHERE trunc(NVL(line.pricing_date, NVL(line.actual_shipment_date, line.fulfillment_date)))
216 BETWEEN p_start_date AND p_end_date
217 AND line.booked_flag = 'Y'
218 AND line.cancelled_flag = 'N'
219 --AND line.line_category_code <> 'RETURN'
220 AND line.inventory_item_id = temp.eligibility_id
221 AND line.header_id = header.header_id;
222
223 CURSOR c_order_line1 IS
224 SELECT /*+ parallel(line) */
225 line.header_id, line.line_id, line.inventory_item_id, line.unit_list_price,
226 NVL(line.shipped_quantity, NVL(line.ordered_quantity, 0)) quantity,
227 header.transactional_curr_code, line.invoice_to_org_id,
228 line.sold_to_org_id, line.ship_to_org_id,line.line_category_code, line.reference_line_id,
229 header.order_number, header.org_id, line.order_quantity_uom, line.pricing_quantity_uom
230 FROM oe_order_lines_all line, oe_order_headers_all header,
231 (SELECT DISTINCT eligibility_id FROM ozf_temp_eligibility) temp
232 WHERE trunc(NVL(line.pricing_date, NVL(line.actual_shipment_date, line.fulfillment_date)))
233 BETWEEN p_start_date AND p_end_date
234 AND line.booked_flag = 'Y'
235 AND line.cancelled_flag = 'N'
236 --AND line.line_category_code <> 'RETURN'
237 AND line.inventory_item_id = temp.eligibility_id
238 AND line.header_id = header.header_id;
239
240 CURSOR c_count_temp IS
241 SELECT COUNT(DISTINCT eligibility_id)
242 FROM ozf_temp_eligibility;
243
244 -- Segment and buying group has no acct info. use party_id for validation
245 CURSOR c_party_id(p_sold_to_org_id IN NUMBER) IS
246 SELECT party_id
247 FROM hz_cust_accounts
248 WHERE cust_account_id = p_sold_to_org_id;
249
250 CURSOR c_customer_qualified(p_invoice_to_org_id IN NUMBER, p_ship_to_org_id IN NUMBER, p_party_id NUMBER) IS
251 SELECT 'Y', object_type, qp_qualifier_group
252 FROM ozf_activity_customers
253 WHERE (
254 (site_use_id = p_invoice_to_org_id AND site_use_code = 'BILL_TO') OR
255 (site_use_id = p_ship_to_org_id AND site_use_code = 'SHIP_TO') OR
256 (party_id = p_party_id AND site_use_code IS NULL) OR
257 (party_id = -1)
258 )
259 AND object_class = 'OFFR'
260 AND object_id = p_list_header_id
261 AND ROWNUM = 1;
262
263 CURSOR c_cust_acct_qualified(p_sold_to_org_id IN NUMBER, p_party_id NUMBER) IS
264 SELECT 'Y', object_type, qp_qualifier_group
265 FROM ozf_activity_customers
266 WHERE (
267 (cust_account_id = p_sold_to_org_id) OR
268 (party_id = p_party_id AND site_use_code IS NULL) OR
269 (party_id = -1)
270 )
271 AND object_class = 'OFFR'
272 AND object_id = p_list_header_id
273 AND ROWNUM = 1;
274
275 TYPE numberTbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
276 TYPE orderCurrTbl IS TABLE OF oe_order_headers_all.transactional_curr_code%TYPE;
277 TYPE lineCatCodeTbl IS TABLE OF oe_order_lines_all.line_category_code%TYPE;
278 TYPE groupNosTbl IS TABLE OF VARCHAR2(256) INDEX BY BINARY_INTEGER;
279 TYPE uomTbl IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
280
281 l_headerIdTbl numberTbl;
282 l_lineIdTbl numberTbl;
283 l_inventoryItemIdTbl numberTbl;
284 l_unitListPriceTbl numberTbl;
285 l_quantityTbl numberTbl;
286 l_orderCurrTbl orderCurrTbl;
287 l_invoiceToOrgIdTbl numberTbl;
288 l_soldToOrgIdTbl numberTbl;
289 l_shipToOrgIdTbl numberTbl;
290 l_lineCatCodeTbl lineCatCodeTbl;
291 l_refLineIdTbl numberTbl;
292 l_orderNumberTbl numberTbl;
293 l_group_nos groupNosTbl;
294 l_orgIdTbl numberTbl;
295 l_orderUomTbl uomTbl;
296 l_pricingUomTbl uomTbl;
297
298 l_party_id NUMBER;
299 l_customer_qualified VARCHAR2(1) := 'Y';
300 l_tbl_index NUMBER := 1;
301 l_api_name CONSTANT VARCHAR2(30) := 'get_orders';
302
303 l_stmt_denorm VARCHAR2(32000) := NULL;
304 l_denorm_csr NUMBER;
305 l_ignore NUMBER;
306 l_product_stmt VARCHAR2(32000) := NULL;
307 l_count_temp NUMBER;
308 l_object_type VARCHAR2(20);
309 l_group NUMBER;
310 l_group_string VARCHAR2(256);
311 l_org_match VARCHAR2(1);
312 l_currency_match VARCHAR2(1);
313 l_uom_match VARCHAR2(1);
314 l_uom_ratio NUMBER;
315
316 BEGIN
317
318 IF Fnd_Api.to_boolean(p_init_msg_list) THEN
319 Fnd_Msg_Pub.initialize;
320 END IF;
321
322 x_return_status := Fnd_Api.g_ret_sts_success;
323
324 --kdass 28-FEB-2006 fixed bug 5059735 - denorm offer's product eligibility to handle all types of product levels
325 EXECUTE IMMEDIATE 'DELETE FROM ozf_temp_eligibility';
326
327 FND_DSQL.init;
328 FND_DSQL.add_text('INSERT INTO ozf_temp_eligibility(object_type, eligibility_id) ');
329 FND_DSQL.add_text('(SELECT ''OFFR'', product_id ' );
330 FND_DSQL.add_text(' FROM ( ');
331
332 /*kdass 05-MAY-2006 bug 5205721 - use refresh_products() as it considers excluded items
333 l_temp_sql := ozf_offr_elig_prod_denorm_pvt.get_sql(p_context => 'ITEM'
334 ,p_attribute => p_product_attr
335 ,p_attr_value_from => p_product
336 ,p_attr_value_to => NULL
337 ,p_comparison => NULL
338 ,p_type => 'PROD'
339 );
340 */
341
342 --kdass 21-JUN-2006 bug 5337761 - added exception handling code
343 BEGIN
344 SAVEPOINT refresh_prod;
345
346 ozf_offr_elig_prod_denorm_pvt.refresh_products(p_api_version => p_api_version
347 ,p_init_msg_list => p_init_msg_list
348 ,p_commit => p_commit
349 ,p_list_header_id => p_list_header_id
350 ,p_calling_from_den => 'N'
351 ,x_return_status => x_return_status
352 ,x_msg_count => x_msg_count
353 ,x_msg_data => x_msg_data
354 ,x_product_stmt => l_product_stmt
355 ,p_lline_id => p_list_line_id
356 );
357
358 FND_DSQL.add_text('))');
359
360 write_conc_log ('l_product_stmt: ' || l_product_stmt);
361
362 l_denorm_csr := DBMS_SQL.open_cursor;
363 FND_DSQL.set_cursor(l_denorm_csr);
364 l_stmt_denorm := FND_DSQL.get_text(FALSE);
365 DBMS_SQL.parse(l_denorm_csr, l_stmt_denorm, DBMS_SQL.native);
366 FND_DSQL.do_binds;
367 l_ignore := DBMS_SQL.execute(l_denorm_csr);
368
369 EXCEPTION
370 WHEN OTHERS THEN
371 ROLLBACK TO refresh_prod;
372 x_return_status := Fnd_Api.g_ret_sts_unexp_error;
373 write_conc_log ('unexpected exception in refresh_products');
374 END;
375
376 IF x_return_status <> fnd_api.g_ret_sts_success THEN
377 RETURN;
378 END IF;
379
380 l_count_temp := 0;
381
382 OPEN c_count_temp;
383 FETCH c_count_temp INTO l_count_temp;
384 CLOSE c_count_temp;
385
386 IF l_count_temp < 6 THEN
387 OPEN c_order_line;
388 ELSE
389 OPEN c_order_line1;
390 END IF;
391
392 LOOP
393
394 IF l_count_temp < 6 THEN
395 FETCH c_order_line BULK COLLECT INTO l_headerIdTbl, l_lineIdTbl, l_inventoryItemIdTbl,
396 l_unitListPriceTbl, l_quantityTbl, l_orderCurrTbl,
397 l_invoiceToOrgIdTbl, l_soldToOrgIdTbl, l_shipToOrgIdTbl,
398 l_lineCatCodeTbl, l_refLineIdTbl, l_orderNumberTbl, l_orgIdTbl,
399 l_orderUomTbl, l_pricingUomTbl
400 LIMIT g_bulk_limit;
401 ELSE
402 FETCH c_order_line1 BULK COLLECT INTO l_headerIdTbl, l_lineIdTbl, l_inventoryItemIdTbl,
403 l_unitListPriceTbl, l_quantityTbl, l_orderCurrTbl,
404 l_invoiceToOrgIdTbl, l_soldToOrgIdTbl, l_shipToOrgIdTbl,
405 l_lineCatCodeTbl, l_refLineIdTbl, l_orderNumberTbl, l_orgIdTbl,
406 l_orderUomTbl, l_pricingUomTbl
407 LIMIT g_bulk_limit;
408 END IF;
409
410 IF l_lineIdTbl.FIRST IS NULL THEN
411 EXIT;
412 END IF;
413
414 FOR i IN l_lineIdTbl.FIRST .. l_lineIdTbl.LAST
415 LOOP
416
417 write_conc_log ('order_line_id: ' || l_lineIdTbl(i));
418 write_conc_log ('order currency: ' || l_orderCurrTbl(i));
419 write_conc_log ('order org: ' || l_orgIdTbl(i));
420
421 --kdass bug 8510774 - added validation between Offer's OU and Order's OU
422 l_org_match := 'Y';
423 IF p_offer_org_id IS NOT NULL AND p_offer_org_id <> l_orgIdTbl(i) THEN
424 l_org_match := 'N';
425 END IF;
426
427 --kdass bug 8510774 - added validation between Offer's currency and Order's currency
428 l_currency_match := 'Y';
429 IF p_offer_currency IS NOT NULL AND p_offer_currency <> l_orderCurrTbl(i) THEN
430 l_currency_match := 'N';
431 END IF;
432
433 IF l_org_match = 'Y' AND l_currency_match = 'Y' THEN
434
435 OPEN c_party_id (l_soldToOrgIdTbl(i));
436 FETCH c_party_id INTO l_party_id;
437 CLOSE c_party_id;
438
439 l_customer_qualified := 'N';
440
441 l_group := NULL;
442 l_group_string := NULL;
443
444 IF l_invoiceToOrgIdTbl(i) IS NULL AND l_shipToOrgIdTbl(i) IS NULL THEN
445
446 --kdass bug 5610124
447 OPEN c_cust_acct_qualified(l_soldToOrgIdTbl(i), l_party_id);
448 LOOP
449 FETCH c_cust_acct_qualified INTO l_customer_qualified, l_object_type, l_group;
450 EXIT WHEN c_cust_acct_qualified%NOTFOUND;
451
452 IF l_object_type = 'VOLUME_OFFER' AND l_group IS NOT NULL THEN
453 l_group_string := l_group_string || ',' || l_group;
454 END IF;
455
456 END LOOP;
457 CLOSE c_cust_acct_qualified;
458
459 ELSE
460
461 --kdass bug 5610124
462 OPEN c_customer_qualified(l_invoiceToOrgIdTbl(i), l_shipToOrgIdTbl(i), l_party_id);
463 LOOP
464 FETCH c_customer_qualified INTO l_customer_qualified, l_object_type, l_group;
465 EXIT WHEN c_customer_qualified%NOTFOUND;
466
467 IF l_object_type = 'VOLUME_OFFER' AND l_group IS NOT NULL THEN
468 l_group_string := l_group_string || ',' || l_group;
469 END IF;
470
471 END LOOP;
472 CLOSE c_customer_qualified;
473
474 END IF;
475
476 IF l_group_string IS NOT NULL THEN
477 l_group_nos(i) := substr(l_group_string,2); --remove first comma
478 END IF;
479
480 END IF;
481
482 write_conc_log ('Offer UOM: ' || p_offer_uom_code);
483 write_conc_log ('Order UOM: ' || l_orderUomTbl(i));
484 write_conc_log ('Pricing UOM: ' || l_pricingUomTbl(i));
485 write_conc_log ('Quantity: ' || l_quantityTbl(i));
486 write_conc_log ('p_arithmetic_operator: ' || p_arithmetic_operator);
487
488 l_uom_match := 'Y';
489
490 --kdass bug 10305820 - convert quantity from order UOM to offer UOM
491 --Offers will no UOM will pick all Orders irrespective of Order UOM.
492 --Offers with UOMs will pick up Orders with same Pricing UOMs.
493 IF (p_offer_uom_code IS NOT NULL) AND (p_offer_uom_code <> l_pricingUomTbl(i)) THEN
494 l_uom_match := 'N';
495 ELSE
496
497 --UOM conversion is only valid for Amount and New Price discount and not for Percent and Lumpsum discounts
498 IF (NVL(p_offer_uom_code,l_pricingUomTbl(i)) <> l_orderUomTbl(i)) AND (p_arithmetic_operator IN ('AMT', 'NEWPRICE')) THEN
499
500 l_uom_ratio := inv_convert.inv_um_convert(l_inventoryItemIdTbl(i)
501 ,NULL
502 ,1
503 ,l_orderUomTbl(i)
504 ,NVL(p_offer_uom_code,l_pricingUomTbl(i))
505 ,NULL
506 ,NULL
507 );
508
509 IF (l_uom_ratio = -99999) THEN
510 write_conc_log ('Error in UOM conversion');
511 l_uom_match := 'N';
512 END IF;
513
514 ELSE
515 l_uom_ratio := 1;
516 END IF;
517
518 write_conc_log ('UOM Ratio: ' || l_uom_ratio);
519
520 END IF;
521
522 write_conc_log ('l_org_match ' || l_org_match);
523 write_conc_log ('l_currency_match ' || l_currency_match);
524 write_conc_log ('l_customer_qualified: ' || l_customer_qualified);
525 write_conc_log ('l_uom_match: ' || l_uom_match);
526
527 IF l_customer_qualified = 'Y' AND l_org_match = 'Y' AND l_currency_match = 'Y' AND l_uom_match = 'Y' THEN
528 x_order_line_tbl(l_tbl_index).order_header_id := l_headerIdTbl(i);
529 x_order_line_tbl(l_tbl_index).order_line_id := l_lineIdTbl(i);
530 x_order_line_tbl(l_tbl_index).inventory_item_id := l_inventoryItemIdTbl(i);
531 x_order_line_tbl(l_tbl_index).unit_list_price := l_unitListPriceTbl(i);
532 x_order_line_tbl(l_tbl_index).quantity := l_quantityTbl(i);
533 x_order_line_tbl(l_tbl_index).transactional_curr_code := l_orderCurrTbl(i);
534 x_order_line_tbl(l_tbl_index).line_category_code := l_lineCatCodeTbl(i);
535 x_order_line_tbl(l_tbl_index).reference_line_id := l_refLineIdTbl(i);
536 x_order_line_tbl(l_tbl_index).order_number := l_orderNumberTbl(i);
537 x_order_line_tbl(l_tbl_index).uom_ratio := l_uom_ratio;
538
539 IF l_group_string IS NOT NULL THEN
540 x_order_line_tbl(l_tbl_index).group_nos := l_group_nos(i);
541 END IF;
542
543 l_tbl_index := l_tbl_index + 1;
544 END IF;
545 END LOOP; --FOR i IN l_line_id_tbl.FIRST .. l_line_id_tbl.LAST
546
547 IF l_count_temp < 6 THEN
548 EXIT WHEN c_order_line%NOTFOUND;
549 ELSE
550 EXIT WHEN c_order_line1%NOTFOUND;
551 END IF;
552
553 END LOOP;
554
555 IF l_count_temp < 6 THEN
556 CLOSE c_order_line;
557 ELSE
558 CLOSE c_order_line1;
559 END IF;
560
561 END get_orders;
562
563 ---------------------------------------------------------------------
564 -- PROCEDURE
565 -- adjustment_net_accrual
566 -- PURPOSE
567 -- adjustment for new product and retroactive adjustment before offer start date
568 -- HISTORY
569 -- 4/22/2004 kdass Created
570 ----------------------------------------------------------------------
571 PROCEDURE adjustment_net_accrual (p_api_version IN NUMBER
572 ,p_offer_type IN VARCHAR2
573 ,p_original_discount IN NUMBER
574 ,p_modified_discount IN NUMBER
575 ,p_arithmetic_operator IN VARCHAR2
576 ,p_offer_uom_code IN VARCHAR2 --kdass bug 10305820
577 ,p_start_date IN DATE
578 ,p_end_date IN DATE
579 ,p_list_header_id IN NUMBER
580 ,p_offer_org_id IN NUMBER
581 ,p_offer_currency IN VARCHAR2
582 ,p_list_line_id IN VARCHAR2
583 ,p_offer_adjustment_id IN NUMBER
584 ,p_type IN VARCHAR2
585 ,x_return_status IN OUT NOCOPY VARCHAR2
586 ,x_msg_count IN OUT NOCOPY NUMBER
587 ,x_msg_data IN OUT NOCOPY VARCHAR2
588 )
589 IS
590
591 CURSOR c_offer_info IS
592 SELECT nvl(transaction_currency_code,fund_request_curr_code)offer_currency_code
593 ,transaction_currency_code
594 , beneficiary_account_id,autopay_party_attr,autopay_party_id -- Added for bug 7030415, correct org_id in accrual records
595 FROM ozf_offers
596 WHERE qp_list_header_id = p_list_header_id;
597
598 CURSOR c_cust_number (p_header_id IN NUMBER) IS
599 SELECT cust.cust_account_id
600 FROM hz_cust_acct_sites_all acct_site,
601 hz_cust_site_uses_all site_use,
602 hz_cust_accounts cust,
603 oe_order_headers_all header
604 WHERE header.header_id = p_header_id
605 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
606 AND acct_site.cust_account_id = cust.cust_account_id
607 AND site_use.site_use_id = header.invoice_to_org_id ;
608
609 --nirprasa, 12.1.1 enhancement, replace amount with plan_curr_amount column.
610 --This is a bug since the original accrual is in offer currency.
611 CURSOR c_order_adjustment_amt (p_object_id IN NUMBER, p_order_line_id IN NUMBER, p_prod_id IN NUMBER) IS
612 SELECT SUM(plan_curr_amount)
613 FROM ozf_funds_utilized_all_b
614 WHERE plan_type = 'OFFR'
615 AND plan_id = p_list_header_id
616 AND object_type = 'ORDER'
617 AND object_id = p_object_id
618 AND order_line_id = p_order_line_id
619 AND product_level_type = 'PRODUCT'
620 AND product_id = p_prod_id
621 AND utilization_type NOT IN ('REQUEST', 'TRANSFER'); --kdass 29-MAR-2006 bug 5120491
622 --AND utilization_type = 'ADJUSTMENT';
623
624 --nirprasa, 12.1.1 enhancement, replace amount with plan_curr_amount column.
625
626 CURSOR c_orig_order_adj_amt (p_order_line_id IN NUMBER) IS
627 SELECT SUM(plan_curr_amount)
628 FROM ozf_funds_utilized_all_b
629 WHERE plan_type = 'OFFR'
630 AND plan_id = p_list_header_id
631 AND order_line_id = p_order_line_id
632 AND utilization_type NOT IN ('REQUEST', 'TRANSFER');
633
634 CURSOR c_order_line (p_order_line_id IN NUMBER) IS
635 SELECT NVL(invoiced_quantity, NVL(shipped_quantity, 0)) quantity,
636 ship_to_org_id, invoice_to_org_id
637 FROM oe_order_lines_all
638 WHERE line_id = p_order_line_id;
639
640 l_order_org_id NUMBER;
641 l_exchange_rate_type VARCHAR2(30) := FND_API.G_MISS_CHAR;
642 l_autopay_party_id NUMBER;
643 l_autopay_party_attr VARCHAR2(30);
644 l_org_id NUMBER; -- site's lorg id
645
646 -- Added for bug 7030415. get order's org_id
647 CURSOR c_order_org_id (p_line_id IN NUMBER) IS
648 SELECT header.org_id
649 FROM oe_order_lines_all line, oe_order_headers_all header
650 WHERE line_id = p_line_id
651 AND line.header_id = header.header_id;
652
653 -- get conversion type
654 CURSOR c_get_conversion_type( p_org_id IN NUMBER) IS
655 SELECT exchange_rate_type
656 FROM ozf_sys_parameters_all
657 WHERE org_id = p_org_id;
658
659 -- get sites org id type
660 CURSOR c_org_id (p_site_use_id IN NUMBER) IS
661 SELECT org_id
662 FROM hz_cust_site_uses_all
663 WHERE site_use_id = p_site_use_id;
664
665 CURSOR c_offer_type (p_offer_id IN NUMBER) IS
666 SELECT autopay_party_attr,autopay_party_id
667 FROM ozf_offers
668 WHERE qp_list_header_id = p_offer_id;
669
670 l_offer_info c_offer_info%ROWTYPE;
671
672 l_util_amount NUMBER;
673 l_rate NUMBER;
674 l_act_budget_id NUMBER;
675 l_total_price NUMBER;
676 l_cust_number NUMBER;
677 l_qp_list_header_id NUMBER;
678 l_error_location NUMBER;
679 l_line_ctr NUMBER := 1;
680 l_adj_amount NUMBER := 0;
681
682 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
683 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
684 l_modifier_list_rec ozf_offer_pvt.modifier_list_rec_type;
685 l_modifier_line_tbl ozf_offer_pvt.modifier_line_tbl_type;
686 l_order_line_tbl order_line_tbl_type;
687
688 l_api_name VARCHAR2(50) := 'adjustment_net_accrual';
689 l_full_name CONSTANT VARCHAR2(90) := g_pkg_name || '.' || l_api_name;
690 l_justification VARCHAR2(50);
691 l_conv_util_amount NUMBER;
692 l_orig_util_amount NUMBER;
693 l_orig_order_qty NUMBER;
694 l_ship_to_org_id NUMBER;
695 l_invoice_to_org_id NUMBER;
696
697 --nirprasa,12.2
698 l_converted_util_amount NUMBER;
699 BEGIN
700
701 OPEN c_offer_info;
702 FETCH c_offer_info INTO l_offer_info;
703 CLOSE c_offer_info;
704
705 write_conc_log ('p_type: ' || p_type);
706 write_conc_log ('offer_id: ' || p_list_header_id);
707 write_conc_log ('p_start_date: ' || p_start_date);
708 write_conc_log ('p_end_date: ' || p_end_date);
709 write_conc_log ('p_offer_adjustment_id: ' || p_offer_adjustment_id);
710 write_conc_log ('p_list_line_id: ' || p_list_line_id);
711 write_conc_log ('offer_org_id: ' || p_offer_org_id);
712 write_conc_log ('offer_currency ' || p_offer_currency);
713
714 --get the qualified orders
715 get_orders(p_api_version => p_api_version
716 ,p_init_msg_list => FND_API.G_FALSE
717 ,p_commit => FND_API.G_FALSE
718 ,x_return_status => x_return_status
719 ,x_msg_count => x_msg_count
720 ,x_msg_data => x_msg_data
721 ,p_list_header_id => p_list_header_id
722 ,p_offer_org_id => p_offer_org_id --kdass bug 8510774 - pass offer's OU
723 ,p_offer_currency => p_offer_currency --kdass bug 8510774 - pass offer's currency code
724 ,p_offer_uom_code => p_offer_uom_code --kdass bug 10305820 - pass offer UOM code
725 ,p_arithmetic_operator => p_arithmetic_operator --kdass bug 10305820 - pass offer line discount type
726 ,p_list_line_id => p_list_line_id
727 ,p_start_date => p_start_date
728 ,p_end_date => p_end_date
729 ,x_order_line_tbl => l_order_line_tbl
730 );
731
732 write_conc_log ('x_return_status: ' || x_return_status);
733 write_conc_log ('number of orders: ' || l_order_line_tbl.count);
734
735 /*kdass 04-AUG-2006 fixed bug 5446622
736 IF x_return_status = fnd_api.g_ret_sts_error THEN
737 RAISE fnd_api.g_exc_error;
738 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
739 RAISE fnd_api.g_exc_unexpected_error;
740 END IF;
741 */
742 IF x_return_status <> fnd_api.g_ret_sts_success THEN
743 RETURN;
744 END IF;
745
746 IF p_type = 'product' THEN
747 write_conc_log ('adjustment for new product');
748 l_justification := 'Offer adjustment for new product';
749
750 /*removed code for future dated adjustments since offers team will be taking care of this.
751 original code in version 120.19
752 */
753 ELSE
754 write_conc_log (l_full_name || ' adjustment before offer start date');
755 l_justification := 'Offer adjustment before offer start date';
756 END IF;
757
758 IF l_order_line_tbl.count > 0 THEN
759
760 l_act_budgets_rec.act_budget_used_by_id := p_list_header_id;
761 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
762 l_act_budgets_rec.budget_source_type := 'OFFR';
763 l_act_budgets_rec.budget_source_id := p_list_header_id;
764 --nirprasa,ER 8399134 comment out these two columns and assign them with transactional curr
765 -- assign fund_request_currency_code column with offer's currency.
766 --l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
767 --l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
768 l_act_util_rec.fund_request_currency_code := l_offer_info.offer_currency_code;
769 --end,ER 8399134
770 l_act_budgets_rec.request_date := SYSDATE;
771 l_act_budgets_rec.status_code := 'APPROVED';
772 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
773 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
774
775 l_act_budgets_rec.approval_date := SYSDATE;
776 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
777 l_act_budgets_rec.justification := l_justification;
778 l_act_budgets_rec.transfer_type := 'UTILIZED';
779
780 l_act_util_rec.utilization_type :='ADJUSTMENT';
781 l_act_util_rec.product_level_type := 'PRODUCT';
782 --nirprasa,ER 8399134 replace sysdate by OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
783 l_act_util_rec.adjustment_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE; --SYSDATE;
784 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
785
786 FOR j IN l_order_line_tbl.first .. l_order_line_tbl.last
787 LOOP
788
789 write_conc_log('order header id: ' || l_order_line_tbl(j).order_header_id);
790 write_conc_log('order line id: ' || l_order_line_tbl(j).order_line_id);
791 write_conc_log('inventory item id: ' || l_order_line_tbl(j).inventory_item_id);
792
793 l_act_util_rec.product_id := l_order_line_tbl(j).inventory_item_id;
794 l_act_util_rec.object_type :='ORDER';
795 l_act_util_rec.object_id := l_order_line_tbl(j).order_header_id;
796 l_act_util_rec.order_line_id := l_order_line_tbl(j).order_line_id;
797
798 OPEN c_cust_number (l_order_line_tbl(j).order_header_id);
799 FETCH c_cust_number INTO l_cust_number;
800 CLOSE c_cust_number;
801
802 l_act_util_rec.billto_cust_account_id := l_cust_number;
803
804 IF l_offer_info.beneficiary_account_id IS NULL THEN
805 l_act_util_rec.cust_account_id := l_cust_number;
806 END IF;
807
808 write_conc_log ('billto_cust_account_id: ' || l_act_util_rec.billto_cust_account_id);
809 write_conc_log ('cust_account_id: ' || l_act_util_rec.cust_account_id);
810 write_conc_log ('unit_list_price: ' || l_order_line_tbl(j).unit_list_price);
811 write_conc_log ('quantity: ' || l_order_line_tbl(j).quantity);
812 write_conc_log ('p_modified_discount: ' || p_modified_discount);
813 write_conc_log ('p_original_discount: ' || p_original_discount);
814 write_conc_log ('p_arithmetic_operator: ' || p_arithmetic_operator);
815
816 /*
817 If you enter 5 for discount, then the following would result for the various discount types
818 Amount = $5.00 off the price per unit
819 Percent = 5% off the price per unit
820 New Price = the new price per unit is $5.00
821 Lumpsum = a flat $5.00 off an order for that product regardless of quantity
822 */
823 l_total_price := l_order_line_tbl(j).unit_list_price * l_order_line_tbl(j).quantity;
824
825 -- 7030415 , get the order's org_id to get the exchange rate.
826 OPEN c_order_org_id(l_order_line_tbl(j).order_line_id);
827 FETCH c_order_org_id INTO l_order_org_id;
828 CLOSE c_order_org_id;
829
830 OPEN c_offer_type(p_list_header_id);
831 FETCH c_offer_type INTO l_autopay_party_attr,l_autopay_party_id;
832 CLOSE c_offer_type;
833
834 write_conc_log ('l_order_org_id: ' || l_order_org_id);
835 l_act_util_rec.org_id := l_order_org_id;
836
837 IF l_act_util_rec.cust_account_id IS NULL THEN
838 IF l_offer_info.beneficiary_account_id IS NOT NULL THEN
839 IF l_autopay_party_attr <> 'CUSTOMER' AND l_autopay_party_attr IS NOT NULL THEN
840 --Added c_org_id for bugfix 6278466
841 OPEN c_org_id (l_autopay_party_id);
842 FETCH c_org_id INTO l_org_id;
843 CLOSE c_org_id;
844 l_act_util_rec.org_id := l_org_id;
845 END IF;
846 END IF;
847 END IF;
848
849 IF p_arithmetic_operator = 'AMT' THEN
850 l_util_amount := p_modified_discount * l_order_line_tbl(j).quantity * l_order_line_tbl(j).uom_ratio;
851 ELSIF p_arithmetic_operator = '%' THEN
852 write_conc_log ('p_modified_discount ' || p_modified_discount);
853 write_conc_log ('l_total_price ' || l_total_price);
854 l_util_amount := p_modified_discount * l_total_price / 100;
855
856 ozf_utility_pvt.write_conc_log('offer curr: '||l_offer_info.transaction_currency_code);
857 ozf_utility_pvt.write_conc_log('order curr: '||l_order_line_tbl(j).transactional_curr_code);
858
859 --nirprasa,12.1.1 remove conversion. keep the utilization in order currency.
860 --kdass 31-MAR-2006 bug 5101720 convert from order currency to offer currency
861 IF l_offer_info.transaction_currency_code IS NOT NULL
862 AND l_offer_info.transaction_currency_code <> l_order_line_tbl(j).transactional_curr_code THEN
863
864 ozf_utility_pvt.write_conc_log('order curr: ' || l_order_line_tbl(j).transactional_curr_code);
865 ozf_utility_pvt.write_conc_log('offer curr: ' || l_offer_info.transaction_currency_code);
866 ozf_utility_pvt.write_conc_log('l_util_amount: ' || l_util_amount);
867
868
869 OPEN c_get_conversion_type(l_act_util_rec.org_id);
870 FETCH c_get_conversion_type INTO l_exchange_rate_type;
871 CLOSE c_get_conversion_type;
872
873
874 ozf_utility_pvt.convert_currency (x_return_status => x_return_status
875 ,p_from_currency => l_order_line_tbl(j).transactional_curr_code
876 ,p_to_currency => l_offer_info.transaction_currency_code
877 ,p_conv_type => l_exchange_rate_type
878 ,p_conv_date => OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
879 ,p_from_amount => l_util_amount
880 ,x_to_amount => l_conv_util_amount
881 ,x_rate => l_rate
882 );
883
884 ozf_utility_pvt.write_conc_log('x_return_status: ' || x_return_status);
885 IF x_return_status <> fnd_api.g_ret_sts_success THEN
886 RETURN;
887 END IF;
888
889 l_util_amount := l_conv_util_amount;
890
891 write_conc_log ('util amt after currency conversion: ' || l_util_amount);
892
893 ELSE
894 l_util_amount := ozf_utility_pvt.currround(l_util_amount, l_order_line_tbl(j).transactional_curr_code);
895 ozf_utility_pvt.write_conc_log('l_util_amount: '||l_util_amount);
896 END IF;
897 ELSIF p_arithmetic_operator = 'NEWPRICE' THEN
898 l_util_amount := (l_order_line_tbl(j).unit_list_price - (p_modified_discount * l_order_line_tbl(j).uom_ratio)) * l_order_line_tbl(j).quantity;
899 ELSIF p_arithmetic_operator = 'LUMPSUM' THEN
900 l_util_amount := p_modified_discount;
901 END IF;
902 --nirprasa,ER 8399134 for null currency offer the transaction currency will be order currency
903 --all other cases, it will be offer currency(Arrows case included)
904 write_conc_log ('null currency offer?: ' || l_offer_info.transaction_currency_code);
905
906 IF l_offer_info.transaction_currency_code IS NULL THEN
907 l_act_util_rec.plan_currency_code := l_order_line_tbl(j).transactional_curr_code;
908 l_act_budgets_rec.request_currency := l_order_line_tbl(j).transactional_curr_code;
909 l_act_budgets_rec.approved_in_currency := l_order_line_tbl(j).transactional_curr_code;
910 l_util_amount := ozf_utility_pvt.currround(l_util_amount, l_order_line_tbl(j).transactional_curr_code);
911 ELSE
912 l_act_util_rec.plan_currency_code := l_offer_info.transaction_currency_code;
913 l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
914 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
915 l_util_amount := ozf_utility_pvt.currround(l_util_amount, l_offer_info.transaction_currency_code);
916 END IF;
917 --end ER 8399134
918
919 write_conc_log ('adjustment amount: ' || l_util_amount);
920
921 l_ship_to_org_id := NULL;
922 l_invoice_to_org_id := NULL;
923
924 -- handle RMA order to fix bug 5147399.
925 IF l_order_line_tbl(j).line_category_code ='RETURN' THEN
926 IF l_order_line_tbl(j).reference_line_id is NOT NULL THEN
927 OPEN c_orig_order_adj_amt (l_order_line_tbl(j).reference_line_id);
928 FETCH c_orig_order_adj_amt INTO l_orig_util_amount;
929 CLOSE c_orig_order_adj_amt;
930
931 --kdass 24-AUG-2006 fix for bug 5485172
932 OPEN c_order_line (l_order_line_tbl(j).reference_line_id);
933 FETCH c_order_line INTO l_orig_order_qty, l_ship_to_org_id, l_invoice_to_org_id;
934 CLOSE c_order_line;
935
936 write_conc_log ('l_orig_util_amount: ' || l_orig_util_amount);
937 write_conc_log ('l_orig_order_qty: ' || l_orig_order_qty);
938
939 IF l_orig_order_qty = 0 THEN
940 write_conc_log ('l_orig_order_qty is 0, exit loop');
941 GOTO l_endoforderloop;
942 END IF;
943
944 --calculate utilization amount in proportion of the number of items returned
945 l_util_amount := l_orig_util_amount / l_orig_order_qty * l_order_line_tbl(j).quantity;
946
947 write_conc_log ('l_util_amount: ' || l_util_amount);
948
949 IF l_util_amount > l_orig_util_amount THEN
950 l_util_amount := l_orig_util_amount;
951 write_conc_log ('greater than orig amount - l_util_amount: ' || l_util_amount);
952 END IF;
953
954 END IF;
955
956 l_util_amount := - l_util_amount;
957 write_conc_log ('adjustment amount for RMA: ' || l_util_amount);
958
959 END IF; -- l_order_line_tbl(j).line_category_code ='RETURN'
960
961 IF l_ship_to_org_id IS NULL THEN
962 OPEN c_order_line (l_order_line_tbl(j).order_line_id);
963 FETCH c_order_line INTO l_orig_order_qty, l_ship_to_org_id, l_invoice_to_org_id;
964 CLOSE c_order_line;
965 END IF;
966
967 l_act_util_rec.ship_to_site_use_id := l_ship_to_org_id;
968 l_act_util_rec.bill_to_site_use_id := l_invoice_to_org_id;
969
970 --kdass 20-JUL-05 Bug 4489233 - gets the previous adjusted amount for the order line
971 OPEN c_order_adjustment_amt (l_order_line_tbl(j).order_header_id, l_order_line_tbl(j).order_line_id, l_order_line_tbl(j).inventory_item_id);
972 FETCH c_order_adjustment_amt INTO l_adj_amount;
973 CLOSE c_order_adjustment_amt;
974 write_conc_log ('l_adj_amount : '||l_adj_amount);
975
976 l_util_amount := NVL(l_util_amount,0) - NVL(l_adj_amount,0);
977
978 write_conc_log ('remaining adjustment amount: ' || l_util_amount);
979
980 IF l_util_amount > 0 THEN
981 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
982 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
983 --nirprasa,ER 8399134
984 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
985 ELSE
986 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
987 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
988 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
989 END IF;
990
991
992
993 IF l_util_amount <> 0 THEN
994
995 l_act_budgets_rec.request_amount := l_util_amount;
996 l_act_budgets_rec.approved_amount := l_util_amount;
997 write_conc_log(l_full_name || ': ozf_fund_adjustment_pvt.process_act_budgets');
998
999 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
1000 ,x_msg_count => x_msg_count
1001 ,x_msg_data => x_msg_data
1002 ,p_act_budgets_rec => l_act_budgets_rec
1003 ,p_act_util_rec => l_act_util_rec
1004 ,x_act_budget_id => l_act_budget_id
1005 );
1006
1007 write_conc_log('process_act_budgets returns: ' || x_return_status);
1008
1009 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1010 RETURN;
1011 END IF;
1012
1013 END IF;
1014
1015 <<l_endoforderloop>>
1016 write_conc_log('adjustment_net_accrual returns: ' || x_return_status);
1017
1018 END LOOP;
1019 END IF;
1020
1021 END adjustment_net_accrual;
1022
1023
1024 ---------------------------------------------------------------------
1025 -- PROCEDURE
1026 -- adjustment_volume_retro
1027 -- PURPOSE
1028 -- adjustment for retroactive adjustment before offer start date for volume offer
1029 -- HISTORY
1030 -- 2/16/2007 kdass Created for bug 5610124
1031 ----------------------------------------------------------------------
1032 PROCEDURE adjustment_volume_retro(p_api_version IN NUMBER
1033 ,p_start_date IN DATE
1034 ,p_end_date IN DATE
1035 ,p_list_header_id IN NUMBER
1036 ,p_offer_org_id IN NUMBER
1037 ,p_offer_currency IN VARCHAR2
1038 ,p_offer_adjustment_id IN NUMBER
1039 ,x_return_status IN OUT NOCOPY VARCHAR2
1040 ,x_msg_count IN OUT NOCOPY NUMBER
1041 ,x_msg_data IN OUT NOCOPY VARCHAR2
1042 )
1043 IS
1044
1045 --query to retrieve list_line_id
1046 CURSOR c_list_line (p_offer_id IN NUMBER, p_product_id IN VARCHAR2) IS
1047 SELECT oq.list_line_id, op.product_attribute, op.product_attr_value
1048 FROM ozf_offer_discount_products op, ozf_qp_discounts oq
1049 WHERE (op.product_attr_value = p_product_id OR op.product_attr_value = 'ALL')
1050 AND op.offer_id = p_offer_id
1051 AND op.offer_discount_line_id = oq.offer_discount_line_id
1052 AND rownum = 1;
1053
1054 CURSOR c_order_line_details (p_line_id IN NUMBER) IS
1055 SELECT actual_shipment_date, shipped_quantity, flow_status_code, invoice_interface_status_code,
1056 invoiced_quantity, sold_to_org_id, invoice_to_org_id, ship_to_org_id, shipping_quantity_uom,
1057 order_quantity_uom, unit_selling_price, org_id, ordered_quantity
1058 FROM oe_order_lines_all
1059 WHERE line_id = p_line_id;
1060
1061 CURSOR c_invoice_date(p_line_id IN NUMBER, p_order_number IN VARCHAR2) IS
1062 SELECT cust.trx_date -- transaction(invoice) date
1063 FROM ra_customer_trx_all cust
1064 , ra_customer_trx_lines_all cust_lines
1065 WHERE cust.customer_trx_id = cust_lines.customer_trx_id
1066 AND cust_lines.sales_order = p_order_number -- added condition for partial index for bug fix 3917556
1067 AND cust_lines.interface_line_attribute6 = TO_CHAR(p_line_id);
1068
1069 CURSOR party_id_csr(p_cust_account_id IN NUMBER) IS
1070 SELECT party_id
1071 FROM hz_cust_accounts
1072 WHERE cust_account_id = p_cust_account_id;
1073
1074 CURSOR party_site_id_csr(p_account_site_id IN NUMBER) IS
1075 SELECT a.party_site_id
1076 FROM hz_cust_acct_sites_all a,
1077 hz_cust_site_uses_all b
1078 WHERE b.site_use_id = p_account_site_id
1079 AND b.cust_acct_site_id = a.cust_acct_site_id;
1080
1081 CURSOR sales_transation_csr(p_line_id IN NUMBER) IS
1082 SELECT 1 FROM DUAL WHERE EXISTS
1083 ( SELECT 1
1084 FROM ozf_sales_transactions_all trx
1085 WHERE trx.line_id = p_line_id
1086 AND source_code = 'OM');
1087
1088 CURSOR c_adjustment_exists (p_list_header_id IN NUMBER, p_order_line_id IN NUMBER) IS
1089 SELECT 1
1090 FROM ozf_funds_utilized_all_b
1091 WHERE plan_id = p_list_header_id
1092 AND plan_type = 'OFFR'
1093 AND order_line_id = p_order_line_id;
1094
1095 CURSOR c_offer_info (p_list_header_id IN NUMBER) IS
1096 SELECT nvl(transaction_currency_code,fund_request_curr_code) offer_currency_code
1097 , transaction_currency_code
1098 , beneficiary_account_id, offer_id
1099 FROM ozf_offers
1100 WHERE qp_list_header_id = p_list_header_id;
1101
1102 CURSOR c_cust_number (p_header_id IN NUMBER) IS
1103 SELECT cust.cust_account_id
1104 FROM hz_cust_acct_sites_all acct_site,
1105 hz_cust_site_uses_all site_use,
1106 hz_cust_accounts cust,
1107 oe_order_headers_all header
1108 WHERE header.header_id = p_header_id
1109 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
1110 AND acct_site.cust_account_id = cust.cust_account_id
1111 AND site_use.site_use_id = header.invoice_to_org_id ;
1112
1113 CURSOR c_apply_discount(p_offer_id IN NUMBER,p_product_id IN VARCHAR2) IS
1114 SELECT NVL(apply_discount_flag,'N')
1115 FROM ozf_offer_discount_products
1116 WHERE offer_id = p_offer_id
1117 AND product_attr_value = p_product_id;
1118
1119 CURSOR c_get_items_type(p_list_header_id number,p_inventory_item_id IN NUMBER) IS
1120 select item_type, ITEMS_CATEGORY
1121 from ozf_activity_products
1122 where object_id = p_list_header_id
1123 and item=p_inventory_item_id;
1124
1125
1126 CURSOR c_get_cond_id_column(p_prod_attr varchar2) IS
1127 select condition_id_column
1128 from ozf_denorm_queries
1129 where context='ITEM'
1130 and attribute =p_prod_attr and rownum = 1;
1131
1132
1133 CURSOR c_discount_header(p_discount_line_id IN NUMBER) IS
1134 SELECT discount_type,volume_type
1135 FROM ozf_offer_discount_lines
1136 WHERE offer_discount_line_id = p_discount_line_id
1137 AND tier_type = 'PBH';
1138
1139 CURSOR c_get_group(p_order_line_id IN NUMBER,p_list_header_id IN NUMBER) IS
1140 SELECT group_no,pbh_line_id,include_volume_flag
1141 FROM ozf_order_group_prod
1142 WHERE order_line_id = p_order_line_id
1143 AND qp_list_header_id = p_list_header_id;
1144
1145 CURSOR c_market_option(p_list_header_id IN NUMBER, p_group_id IN NUMBER) IS
1146 SELECT opt.retroactive_flag
1147 FROM ozf_offr_market_options opt
1148 WHERE opt.GROUP_NUMBER= p_group_id
1149 AND opt.qp_list_header_id = p_list_header_id;
1150
1151 CURSOR c_current_discount(p_volume IN NUMBER, p_parent_discount_id IN NUMBER) IS
1152 SELECT discount
1153 FROM ozf_offer_discount_lines
1154 WHERE p_volume > volume_from
1155 AND p_volume <= volume_to
1156 AND parent_discount_line_id = p_parent_discount_id;
1157
1158 CURSOR c_get_tier_limits (p_parent_discount_id IN NUMBER) IS
1159 SELECT MIN(volume_from),MAX(volume_to)
1160 FROM ozf_offer_discount_lines
1161 WHERE parent_discount_line_id = p_parent_discount_id;
1162
1163 CURSOR c_get_max_tier (p_max_volume_to IN NUMBER,p_parent_discount_id IN NUMBER) IS
1164 SELECT discount
1165 FROM ozf_offer_discount_lines
1166 WHERE volume_to =p_max_volume_to
1167 AND parent_discount_line_id = p_parent_discount_id;
1168
1169
1170 --nirprasa,12.2 replace amount by plan_curr_amount
1171 CURSOR c_order_adjustment_amt (p_object_id IN NUMBER, p_order_line_id IN NUMBER, p_prod_id IN NUMBER) IS
1172 SELECT SUM(plan_curr_amount)
1173 FROM ozf_funds_utilized_all_b
1174 WHERE plan_type = 'OFFR'
1175 AND plan_id = p_list_header_id
1176 AND object_type = 'ORDER'
1177 AND object_id = p_object_id
1178 AND order_line_id = p_order_line_id
1179 AND product_level_type = 'PRODUCT'
1180 AND product_id = p_prod_id
1181 AND utilization_type NOT IN ('REQUEST', 'TRANSFER');
1182
1183
1184
1185 CURSOR c_order_adj_amount ( p_prod_id IN NUMBER) IS
1186 SELECT SUM(amount)
1187 FROM ozf_funds_utilized_all_b
1188 WHERE plan_type = 'OFFR'
1189 AND plan_id = p_list_header_id
1190 AND object_type = 'ORDER'
1191 -- AND object_id = p_object_id
1192 AND product_level_type = 'PRODUCT'
1193 AND product_id = p_prod_id
1194 AND utilization_type NOT IN ('REQUEST', 'TRANSFER');
1195
1196 CURSOR c_prior_tiers(p_parent_discount_id IN NUMBER, p_volume IN NUMBER ) IS
1197 SELECT offer_discount_line_id ,volume_from ,volume_to, discount
1198 FROM ozf_offer_discount_lines
1199 WHERE parent_discount_line_id = p_parent_discount_id
1200 AND p_volume >= volume_from
1201 ORDER BY volume_from DESC;
1202
1203 CURSOR c_preset_tier(p_pbh_line_id IN NUMBER, p_qp_list_header_id IN NUMBER,p_group_id IN NUMBER) IS
1204 SELECT a.discount
1205 FROM ozf_offer_discount_lines a, ozf_market_preset_tiers b, ozf_offr_market_options c
1206 WHERE a.offer_discount_line_id = b.dis_offer_discount_id
1207 AND b.pbh_offer_discount_id = p_pbh_line_id
1208 AND b.offer_market_option_id = c.offer_market_option_id
1209 AND c.qp_list_header_id = p_qp_list_header_id
1210 AND c.group_number = p_group_id;
1211
1212
1213 CURSOR c_exchange_rate_type(p_org_id IN NUMBER) IS
1214 SELECT exchange_rate_type
1215 FROM ozf_sys_parameters_all
1216 WHERE org_id = p_org_id;
1217
1218
1219 l_offer_info c_offer_info%ROWTYPE;
1220 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
1221 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
1222 l_cust_number NUMBER;
1223 l_order_line_tbl order_line_tbl_type;
1224 l_req_line_attrs_tbl qp_runtime_source.accum_req_line_attrs_tbl;
1225 l_index NUMBER := 1;
1226 l_dummy NUMBER;
1227 l_list_line_id NUMBER;
1228 l_order_header_id NUMBER;
1229 l_order_line_id NUMBER;
1230 l_string VARCHAR2(1024);
1231 l_first_pos NUMBER := 1;
1232 l_last_pos NUMBER := 0;
1233 l_value VARCHAR2(1024);
1234 l_cntr NUMBER := 0;
1235 l_num_chars VARCHAR2(1024);
1236 l_sales_transaction_rec OZF_SALES_TRANSACTIONS_PVT.SALES_TRANSACTION_REC_TYPE;
1237 l_order_gl_phase CONSTANT VARCHAR2 (15) := NVL(fnd_profile.VALUE ('OZF_ORDER_GLPOST_PHASE'), 'SHIPPED');
1238 l_sales_transaction_id NUMBER;
1239 l_gl_date DATE;
1240 l_shipment_date DATE;
1241 l_shipped_qty NUMBER;
1242 l_flow_status_code VARCHAR2(30);
1243 l_invoice_status_code VARCHAR2(30);
1244 l_invoiced_quantity NUMBER;
1245 l_order_number NUMBER;
1246 l_sold_to_org_id NUMBER;
1247 l_invoice_to_org_id NUMBER;
1248 l_ship_to_org_id NUMBER;
1249 l_shipping_quantity_uom VARCHAR2(30);
1250 l_order_quantity_uom VARCHAR2(30);
1251 l_unit_selling_price NUMBER;
1252 l_org_id NUMBER;
1253 l_sales_trans NUMBER;
1254 l_adjustment_exists NUMBER;
1255 l_act_budget_id NUMBER;
1256 l_apply_discount VARCHAR2(1);
1257
1258 l_prod_attr VARCHAR2(50);
1259 l_prod_attr_val VARCHAR2(20);
1260 l_item VARCHAR2(240);
1261 l_cond_id_column varchar2(240) := null;
1262 l_product_val_cursor product_attr_val_cursor_type;
1263 l_category_id NUMBER;
1264 l_stmt VARCHAR2(3000);
1265
1266
1267 l_group_id NUMBER;
1268 l_pbh_line_id NUMBER;
1269 l_included_vol_flag VARCHAR2(1);
1270 l_retroactive VARCHAR2(1) ;
1271 l_discount_type VARCHAR2(30);
1272 l_volume_type VARCHAR2(30);
1273 l_return_status VARCHAR2 (20) := fnd_api.g_ret_sts_success;
1274 l_msg_count NUMBER;
1275 l_msg_data VARCHAR2 (2000) := NULL;
1276 l_source_code VARCHAR2(30);
1277 l_volume NUMBER;
1278 l_ordered_qty NUMBER;
1279 l_utilization_amount NUMBER;
1280 l_new_discount NUMBER;
1281 l_min_tier NUMBER;
1282 l_max_tier NUMBER;
1283 l_adj_amount NUMBER;
1284
1285
1286 l_current_offer_tier_id NUMBER;
1287 y1 NUMBER; -- Initial Adjsutment
1288 l_current_max_tier NUMBER;
1289 l_current_min_tier NUMBER;
1290 l_current_tier_value NUMBER;
1291 l_previous_tier_max NUMBER;
1292 l_preset_tier NUMBER;
1293 l_conv_type ozf_funds_utilized_all_b.exchange_rate_type%TYPE;
1294 l_conv_price NUMBER;
1295 l_rate NUMBER;
1296
1297 BEGIN
1298
1299 write_conc_log ('in adjustment_volume_retro');
1300 write_conc_log ('offer_org_id: ' || p_offer_org_id);
1301 write_conc_log ('offer_currency ' || p_offer_currency);
1302
1303 --get the qualified orders
1304 get_orders(p_api_version => p_api_version
1305 ,p_init_msg_list => FND_API.G_FALSE
1306 ,p_commit => FND_API.G_FALSE
1307 ,x_return_status => x_return_status
1308 ,x_msg_count => x_msg_count
1309 ,x_msg_data => x_msg_data
1310 ,p_list_header_id => p_list_header_id
1311 ,p_offer_org_id => p_offer_org_id
1312 ,p_offer_currency => p_offer_currency
1313 ,p_offer_uom_code => NULL
1314 ,p_arithmetic_operator => NULL
1315 ,p_list_line_id => NULL
1316 ,p_start_date => p_start_date
1317 ,p_end_date => p_end_date
1318 ,x_order_line_tbl => l_order_line_tbl
1319 );
1320
1321 write_conc_log ('x_return_status: ' || x_return_status);
1322 write_conc_log ('number of orders: ' || l_order_line_tbl.count);
1323
1324 l_volume:=0;
1325 l_utilization_amount := 0;
1326
1327
1328 IF l_order_line_tbl.count > 0 THEN
1329
1330 FOR j IN l_order_line_tbl.first .. l_order_line_tbl.last
1331 LOOP
1332
1333 write_conc_log ('==============');
1334 write_conc_log ('order number: ' || l_order_line_tbl(j).order_number);
1335 write_conc_log ('order line: ' || l_order_line_tbl(j).order_line_id);
1336 write_conc_log ('==============');
1337
1338
1339 --fix for bug # 5944862
1340 OPEN c_offer_info (p_list_header_id);
1341 FETCH c_offer_info INTO l_offer_info;
1342 CLOSE c_offer_info;
1343 -- -----
1344 write_conc_log('p_list_header_id: '||p_list_header_id);
1345 write_conc_log('l_order_line_tbl(j).inventory_item_id '||l_order_line_tbl(j).inventory_item_id);
1346
1347 OPEN c_get_items_type(p_list_header_id,l_order_line_tbl(j).inventory_item_id);
1348 FETCH c_get_items_type INTO l_prod_attr, l_prod_attr_val;
1349 CLOSE c_get_items_type;
1350
1351 write_conc_log('l_prod_attr: '||l_prod_attr);
1352 write_conc_log('l_prod_attr_val: '||l_prod_attr_val);
1353
1354 OPEN c_get_cond_id_column(l_prod_attr);
1355 FETCH c_get_cond_id_column INTO l_cond_id_column;
1356 CLOSE c_get_cond_id_column;
1357
1358 write_conc_log('l_cond_id_column: '||l_cond_id_column);
1359 -- fix for bug 5767748
1360
1361 IF l_prod_attr_val IS NULL THEN -- if not item category
1362
1363 l_prod_attr_val :=l_order_line_tbl(j).inventory_item_id;
1364 IF l_cond_id_column IS NOT NULL THEN --if product context
1365
1366 l_stmt := 'select ' || l_cond_id_column ||
1367 ' from mtl_system_items where ORGANIZATION_ID = FND_PROFILE.VALUE(''QP_ORGANIZATION_ID'') and inventory_item_id =:1 and rownum = 1';
1368 write_conc_log(l_stmt);
1369
1370 OPEN l_product_val_cursor FOR l_stmt using l_prod_attr_val;
1371 LOOP
1372 FETCH l_product_val_cursor INTO l_prod_attr_val;
1373 EXIT WHEN l_product_val_cursor%NOTFOUND;
1374 END LOOP;
1375
1376 --ELSE -- if inventory item
1377 --l_prod_attr_val :=l_order_line_tbl(j).inventory_item_id;
1378 END IF;
1379 END IF;
1380
1381 write_conc_log('l_prod_attr_val: '||l_prod_attr_val);
1382 write_conc_log('l_offer_info.offer_id: '||l_offer_info.offer_id);
1383
1384
1385 OPEN c_list_line (l_offer_info.offer_id,l_prod_attr_val);
1386 FETCH c_list_line INTO l_list_line_id,l_prod_attr,l_prod_attr_val;
1387 CLOSE c_list_line;
1388
1389
1390 write_conc_log('l_list_line_id: '||l_list_line_id);
1391 write_conc_log('l_prod_attr: '||l_prod_attr);
1392 write_conc_log('ll_prod_attr_val: '||l_prod_attr_val);
1393 -- -----
1394
1395
1396 l_index := 1;
1397 -- product
1398 l_req_line_attrs_tbl(l_index).line_index := 1;
1399 l_req_line_attrs_tbl(l_index).attribute_type := 'PRODUCT';
1400 l_req_line_attrs_tbl(l_index).context := NULL;
1401 l_req_line_attrs_tbl(l_index).attribute := l_prod_attr;
1402 l_req_line_attrs_tbl(l_index).value := l_prod_attr_val; -- inventory_item_id
1403 l_req_line_attrs_tbl(l_index).grouping_no := NULL;
1404
1405
1406 l_cntr := 0;
1407 l_last_pos := 0;
1408 l_first_pos := 1;
1409 l_num_chars := 0;
1410
1411 write_conc_log ('l_order_line_tbl(j).group_nos: ' || l_order_line_tbl(j).group_nos);
1412
1413 IF l_order_line_tbl(j).group_nos IS NOT NULL THEN
1414
1415 --loop to get individual group number from the comma seperated list
1416 l_string := l_order_line_tbl(j).group_nos;
1417 LOOP
1418 l_last_pos := INSTR(l_string,',',1,l_cntr+1);
1419 l_num_chars := l_last_pos - l_first_pos;
1420 IF l_last_pos = 0 THEN
1421 l_value := SUBSTR(l_string, l_first_pos);
1422 ELSE
1423 l_value := substr(l_string, l_first_pos,l_num_chars);
1424 l_first_pos := l_last_pos + 1;
1425 END IF;
1426 l_cntr := l_cntr + 1;
1427
1428 -- qualifier
1429 l_index := l_index + 1;
1430 l_req_line_attrs_tbl(l_index).line_index := 1;
1431 l_req_line_attrs_tbl(l_index).attribute_type := 'QUALIFIER';
1432 l_req_line_attrs_tbl(l_index).context := NULL;
1433 l_req_line_attrs_tbl(l_index).attribute := NULL;
1434 l_req_line_attrs_tbl(l_index).value := NULL;
1435 l_req_line_attrs_tbl(l_index).grouping_no := l_value;
1436
1437 write_conc_log('group no: ' || l_value);
1438
1439 IF l_last_pos = 0 THEN
1440 EXIT;
1441 END IF;
1442 END LOOP;
1443
1444 END IF;
1445
1446
1447
1448 write_conc_log('l_list_line_id: ' || l_list_line_id);
1449 write_conc_log('calling OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value');
1450
1451 --simulation of pricing engine call while booking order
1452 l_dummy := OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value
1453 (p_list_line_id => l_list_line_id
1454 ,p_list_line_no => NULL
1455 ,p_order_header_id => l_order_line_tbl(j).order_header_id
1456 ,p_order_line_id => l_order_line_tbl(j).order_line_id
1457 ,p_price_effective_date => NULL
1458 ,p_req_line_attrs_tbl => l_req_line_attrs_tbl
1459 ,p_accum_rec => NULL
1460 );
1461
1462 write_conc_log('calling OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value returns: ' || l_dummy);
1463
1464 l_gl_date := NULL;
1465
1466 OPEN c_order_line_details (l_order_line_tbl(j).order_line_id);
1467 FETCH c_order_line_details into l_shipment_date, l_shipped_qty, l_flow_status_code, l_invoice_status_code,
1468 l_invoiced_quantity, l_sold_to_org_id, l_invoice_to_org_id, l_ship_to_org_id,
1469 l_shipping_quantity_uom, l_order_quantity_uom, l_unit_selling_price, l_org_id, l_ordered_qty;
1470 CLOSE c_order_line_details;
1471
1472 write_conc_log ('order org: ' || l_org_id);
1473
1474 IF ( l_order_gl_phase = 'SHIPPED' AND l_order_line_tbl(j).line_category_code <> 'RETURN' AND
1475 NVL(l_shipped_qty,0) <> 0 AND l_flow_status_code = 'SHIPPED') THEN
1476
1477 l_gl_date := l_shipment_date;
1478 l_sales_transaction_rec.quantity := l_shipped_qty;
1479 l_sales_transaction_rec.transfer_type := 'IN';
1480
1481 write_conc_log('gl date is shipment date: ' || l_gl_date);
1482
1483 END IF;
1484
1485 IF l_gl_date IS NULL THEN
1486 IF (l_invoice_status_code = 'YES' OR NVL(l_invoiced_quantity,0) <> 0) THEN
1487 OPEN c_invoice_date(l_order_line_tbl(j).order_line_id, l_order_line_tbl(j).order_number);
1488 FETCH c_invoice_date INTO l_gl_date;
1489 CLOSE c_invoice_date;
1490
1491 write_conc_log('gl date is invoice date: ' || l_gl_date);
1492
1493 IF l_gl_date IS NULL THEN
1494 l_gl_date := sysdate;
1495 write_conc_log('gl date is sysdate: ' || l_gl_date);
1496 END IF;
1497
1498 l_sales_transaction_rec.quantity := l_invoiced_quantity;
1499
1500 END IF;
1501 END IF;
1502
1503 write_conc_log('gl date: ' || l_gl_date);
1504 write_conc_log('line id: ' || l_order_line_tbl(j).order_line_id);
1505
1506 IF l_gl_date IS NOT NULL THEN
1507 OPEN sales_transation_csr(l_order_line_tbl(j).order_line_id);
1508 FETCH sales_transation_csr INTO l_sales_trans;
1509 CLOSE sales_transation_csr;
1510
1511 write_conc_log('l_sales_trans: ' || l_sales_trans);
1512
1513 l_sales_transaction_rec.sold_to_cust_account_id := l_sold_to_org_id;
1514
1515 OPEN party_id_csr(l_sales_transaction_rec.sold_to_cust_account_id);
1516 FETCH party_id_csr INTO l_sales_transaction_rec.sold_to_party_id;
1517 CLOSE party_id_csr;
1518
1519 OPEN party_site_id_csr(l_invoice_to_org_id);
1520 FETCH party_site_id_csr INTO l_sales_transaction_rec.sold_to_party_site_id;
1521 CLOSE party_site_id_csr;
1522
1523 l_sales_transaction_rec.ship_to_site_use_id := l_ship_to_org_id;
1524 l_sales_transaction_rec.bill_to_site_use_id := l_invoice_to_org_id;
1525 l_sales_transaction_rec.uom_code:= NVL(l_shipping_quantity_uom, l_order_quantity_uom);
1526 l_sales_transaction_rec.amount := l_unit_selling_price * l_sales_transaction_rec.quantity;
1527 l_sales_transaction_rec.currency_code := l_order_line_tbl(j).transactional_curr_code;
1528 l_sales_transaction_rec.inventory_item_id := l_order_line_tbl(j).inventory_item_id;
1529 l_sales_transaction_rec.header_id := l_order_line_tbl(j).order_header_id;
1530 l_sales_transaction_rec.line_id := l_order_line_tbl(j).order_line_id;
1531 l_sales_transaction_rec.source_code := 'OM';
1532
1533 IF l_order_line_tbl(j).line_category_code <> 'RETURN' THEN
1534 l_sales_transaction_rec.transfer_type := 'IN';
1535 ELSE
1536 l_sales_transaction_rec.transfer_type := 'OUT';
1537 END IF;
1538
1539 l_sales_transaction_rec.transaction_date := l_gl_date;
1540 l_sales_transaction_rec.org_id := l_org_id;
1541 l_sales_transaction_rec.qp_list_header_id := p_list_header_id;
1542
1543 write_conc_log('calling Create_Transaction');
1544
1545 OZF_SALES_TRANSACTIONS_PVT.Create_Transaction(p_api_version => 1.0
1546 ,p_init_msg_list => FND_API.G_FALSE
1547 ,p_commit => FND_API.G_FALSE
1548 ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
1549 ,p_transaction_rec => l_sales_transaction_rec
1550 ,x_sales_transaction_id => l_sales_transaction_id
1551 ,x_return_status => x_return_status
1552 ,x_msg_data => x_msg_data
1553 ,x_msg_count => x_msg_count
1554 );
1555
1556 write_conc_log('Create_Transaction returns: ' || x_return_status);
1557 write_conc_log('l_sales_transaction_id: ' || l_sales_transaction_id);
1558
1559 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1560 RETURN;
1561 END IF;
1562
1563 END IF; --IF l_gl_date IS NOT NULL THEN
1564
1565 -- As booked orders are also considered so closed the "IF l_gl_date IS NOT NULL THEN" condition here
1566 -- fix for bug 6021635
1567
1568 --OPEN c_apply_discount(l_offer_info.offer_id, l_order_line_tbl(j).inventory_item_id);
1569 OPEN c_apply_discount(l_offer_info.offer_id, l_prod_attr_val);
1570 FETCH c_apply_discount INTO l_apply_discount;
1571 CLOSE c_apply_discount;
1572
1573 IF l_apply_discount = 'N' THEN
1574 write_conc_log('no discount since apply discount flag is unchecked: '|| l_order_line_tbl(j).inventory_item_id);
1575 GOTO l_endofOrderloop;
1576 END IF;
1577
1578 OPEN c_adjustment_exists (p_list_header_id, l_order_line_tbl(j).order_line_id);
1579 FETCH c_adjustment_exists INTO l_adjustment_exists;
1580 CLOSE c_adjustment_exists;
1581
1582 l_adjustment_exists := 0;
1583
1584 -- create adjustment record for the order line if it doesn't exists, otherwise
1585 -- volume_offer_adjustment will not consider this order line
1586 -- IF NVL(l_adjustment_exists,0) <> 1 THEN
1587
1588 l_act_budgets_rec.act_budget_used_by_id := p_list_header_id;
1589 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
1590 l_act_budgets_rec.budget_source_type := 'OFFR';
1591 l_act_budgets_rec.budget_source_id := p_list_header_id;
1592 --nirprasa,12.2 If condition to handle null currency offers
1593 --else will work fine for Arrow's case as well.
1594 IF l_offer_info.transaction_currency_code IS NULL THEN
1595 l_act_budgets_rec.request_currency := l_order_line_tbl(j).transactional_curr_code;
1596 l_act_budgets_rec.approved_in_currency := l_order_line_tbl(j).transactional_curr_code;
1597 l_act_util_rec.plan_currency_code := l_order_line_tbl(j).transactional_curr_code;
1598 ELSE
1599 l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
1600 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
1601 l_act_util_rec.plan_currency_code := l_order_line_tbl(j).transactional_curr_code;
1602 END IF;
1603 l_act_util_rec.fund_request_currency_code := l_offer_info.transaction_currency_code;
1604 --nirprasa,12.2
1605 l_act_budgets_rec.request_date := SYSDATE;
1606 l_act_budgets_rec.status_code := 'APPROVED';
1607 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
1608 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
1609
1610 l_act_budgets_rec.approval_date := SYSDATE;
1611 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
1612 l_act_budgets_rec.justification := 'Offer adjustment before offer start date';
1613 l_act_budgets_rec.transfer_type := 'UTILIZED';
1614
1615 l_act_util_rec.utilization_type :='ADJUSTMENT';
1616 l_act_util_rec.product_level_type := 'PRODUCT';
1617 l_act_util_rec.adjustment_date := SYSDATE;
1618 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
1619 l_act_util_rec.ship_to_site_use_id := l_sales_transaction_rec.ship_to_site_use_id;
1620 l_act_util_rec.bill_to_site_use_id := l_sales_transaction_rec.bill_to_site_use_id;
1621
1622 l_act_util_rec.product_id := l_order_line_tbl(j).inventory_item_id;
1623 l_act_util_rec.object_type :='ORDER';
1624 l_act_util_rec.object_id := l_order_line_tbl(j).order_header_id;
1625 l_act_util_rec.order_line_id := l_order_line_tbl(j).order_line_id;
1626 l_act_util_rec.price_adjustment_id := -1;
1627 l_act_util_rec.org_id := l_org_id; --nirprasa, added for bug 7030415
1628
1629
1630 OPEN c_cust_number (l_order_line_tbl(j).order_header_id);
1631 FETCH c_cust_number INTO l_cust_number;
1632 CLOSE c_cust_number;
1633
1634 l_act_util_rec.billto_cust_account_id := l_cust_number;
1635
1636 IF l_offer_info.beneficiary_account_id IS NULL THEN
1637 l_act_util_rec.cust_account_id := l_cust_number;
1638 END IF;
1639
1640 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
1641 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
1642
1643
1644 --For booked orders get the total volume and the discount based on the
1645 --tiers then create the utilization
1646
1647
1648 OPEN c_get_group(l_order_line_tbl(j).order_line_id,p_list_header_id);
1649 FETCH c_get_group INTO l_group_id,l_pbh_line_id,l_included_vol_flag;
1650 CLOSE c_get_group;
1651
1652 IF G_DEBUG THEN
1653 ozf_utility_pvt.debug_message(' l_group_id: '|| l_group_id );
1654 ozf_utility_pvt.debug_message(' l_pbh_line_id: '|| l_pbh_line_id );
1655 ozf_utility_pvt.debug_message(' l_included_vol_flag: '|| l_included_vol_flag );
1656 END IF;
1657 write_conc_log(' l_group_id: '|| l_group_id );
1658 write_conc_log(' l_pbh_line_id: '|| l_pbh_line_id );
1659 write_conc_log(' l_included_vol_flag: '|| l_included_vol_flag );
1660
1661 IF l_group_id is NULL OR l_pbh_line_id is NULL THEN
1662 GOTO l_endofOrderloop;
1663 END IF;
1664
1665 OPEN c_market_option(p_list_header_id,l_group_id);
1666 FETCH c_market_option INTO l_retroactive;
1667 CLOSE c_market_option;
1668
1669 OPEN c_discount_header(l_pbh_line_id);
1670 FETCH c_discount_header INTO l_discount_type,l_volume_type;
1671 CLOSE c_discount_header;
1672
1673 write_conc_log('l_retroactive: '||l_retroactive);
1674 write_conc_log('p_qp_list_header_id: '||p_list_header_id);
1675 write_conc_log('l_order_line_tbl(j).order_line_id: '||l_order_line_tbl(j).order_line_id);
1676
1677
1678 l_volume:=l_volume+NVL(l_ordered_qty,0);
1679
1680 OPEN c_order_adjustment_amt (l_order_line_tbl(j).order_header_id, l_order_line_tbl(j).order_line_id, l_order_line_tbl(j).inventory_item_id);
1681 FETCH c_order_adjustment_amt INTO l_adj_amount;
1682 CLOSE c_order_adjustment_amt;
1683
1684 write_conc_log('l_volume: '||l_volume);
1685 write_conc_log('l_adj_amount : '||l_adj_amount);
1686 --12.2, multi-currency enhancement. added for Arrow's case
1687 IF l_offer_info.transaction_currency_code IS NOT NULL
1688 AND l_offer_info.transaction_currency_code <> l_order_line_tbl(j).transactional_curr_code THEN
1689
1690 --Added for bug 7030415
1691 OPEN c_exchange_rate_type(l_org_id);
1692 FETCH c_exchange_rate_type INTO l_conv_type;
1693 CLOSE c_exchange_rate_type;
1694
1695 ozf_utility_pvt.write_conc_log('order curr: ' || l_order_line_tbl(j).transactional_curr_code);
1696 ozf_utility_pvt.write_conc_log('offer curr: ' || l_offer_info.transaction_currency_code);
1697 ozf_utility_pvt.write_conc_log('selling price: ' || l_unit_selling_price);
1698 ozf_utility_pvt.write_conc_log('l_conv_type: ' || l_conv_type);
1699
1700 --Since it is increased earned always so no change for
1701 ozf_utility_pvt.convert_currency (x_return_status => l_return_status
1702 ,p_conv_type => l_conv_type --7030415
1703 ,p_conv_date => OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
1704 ,p_from_currency => l_order_line_tbl(j).transactional_curr_code
1705 ,p_to_currency => l_offer_info.transaction_currency_code
1706 ,p_from_amount => l_unit_selling_price
1707 ,x_to_amount => l_conv_price
1708 ,x_rate => l_rate
1709 );
1710
1711 IF l_return_status = fnd_api.g_ret_sts_error THEN
1712 RAISE fnd_api.g_exc_error;
1713 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1714 RAISE fnd_api.g_exc_unexpected_error;
1715 END IF;
1716
1717 l_unit_selling_price := l_conv_price;
1718 write_conc_log ('selling price after currency conversion: ' || l_unit_selling_price);
1719
1720 END IF;
1721 --12.2 end
1722 IF l_retroactive = 'Y' THEN
1723
1724 OPEN c_current_discount(l_volume,l_pbh_line_id);
1725 FETCH c_current_discount INTO l_new_discount;
1726 CLOSE c_current_discount;
1727 write_conc_log('l_new_discount 111: '||l_new_discount);
1728
1729 IF l_new_discount is NULL THEN
1730 OPEN c_get_tier_limits(l_pbh_line_id);
1731 FETCH c_get_tier_limits INTO l_min_tier,l_max_tier;
1732 CLOSE c_get_tier_limits;
1733 IF l_volume < l_min_tier THEN
1734 l_new_discount := 0;
1735 ELSE
1736 OPEN c_get_max_tier(l_max_tier,l_pbh_line_id);
1737 FETCH c_get_max_tier INTO l_new_discount;
1738 CLOSE c_get_max_tier;
1739 END IF;
1740 IF G_DEBUG THEN
1741 ozf_utility_pvt.debug_message(' l_new_discount: '|| l_new_discount );
1742 END IF;
1743 write_conc_log(' l_new_discount: '|| l_new_discount );
1744 END IF;
1745
1746 l_preset_tier := NULL;
1747
1748 OPEN c_preset_tier(l_pbh_line_id,p_list_header_id,l_group_id);
1749 FETCH c_preset_tier INTO l_preset_tier;
1750 CLOSE c_preset_tier;
1751
1752 write_conc_log( ' l_preset_tier=' || l_preset_tier);
1753 write_conc_log( ' l_new_discount=' || l_new_discount);
1754
1755 IF l_preset_tier is NOT NULL AND l_preset_tier > l_new_discount THEN
1756 l_new_discount := l_preset_tier;
1757 IF G_DEBUG THEN
1758 ozf_utility_pvt.debug_message('not reach preset tier: ');
1759 END IF;
1760 write_conc_log(' not reach preset tier:');
1761 END IF;
1762
1763
1764 write_conc_log(' l_new_discount: '|| l_new_discount );
1765 IF l_discount_type = '%' THEN
1766 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
1767 l_utilization_amount := l_ordered_qty * l_new_discount / 100;
1768 ELSE -- % is for unit price. need to multiple when range in quantity.
1769 l_utilization_amount := l_ordered_qty * l_unit_selling_price * l_new_discount / 100;
1770 END IF;
1771 ELSIF l_discount_type = 'AMT' THEN
1772 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
1773 -- amt is for unit pirce. need to divide when range in amount.
1774 l_utilization_amount :=l_ordered_qty / l_unit_selling_price * l_new_discount ;
1775 ELSE
1776 l_utilization_amount :=l_ordered_qty * l_new_discount ;
1777 END IF;
1778 END IF;
1779
1780 --end
1781
1782 END IF; -- end of IF l_retroactive = 'Y' THEN
1783
1784
1785
1786 --for non retro same as volume offer adjustment
1787
1788
1789 IF NVL(l_retroactive, 'N') = 'N' THEN
1790
1791 l_utilization_amount:=0;
1792
1793 IF l_included_vol_flag = 'Y' THEN
1794 l_previous_tier_max := l_volume;
1795 ELSE
1796 /*
1797 logic here is to add current order line's volume to offer's volume for adjustment.
1798 eg: offer's volume=2.
1799 order line's volume = 5, then total volume = 7.
1800 */
1801 l_previous_tier_max := l_volume + l_ordered_qty;
1802 END IF;
1803
1804 IF G_DEBUG THEN
1805 ozf_utility_pvt.debug_message( ' l_ordered_qty=' || l_ordered_qty);
1806 END IF;
1807 write_conc_log( ' l_value=' || l_ordered_qty);
1808 l_preset_tier := NULL;
1809
1810 OPEN c_prior_tiers(l_pbh_line_id, l_volume);
1811 LOOP
1812 FETCH c_prior_tiers INTO l_current_offer_tier_id,l_current_min_tier,l_current_max_tier,l_current_tier_value;
1813 EXIT WHEN c_prior_tiers%NOTFOUND;
1814
1815 write_conc_log( ' l_current_offer_tier_id=' || l_current_offer_tier_id);
1816
1817
1818
1819 OPEN c_preset_tier(l_pbh_line_id,p_list_header_id,l_group_id);
1820 FETCH c_preset_tier INTO l_preset_tier;
1821 CLOSE c_preset_tier;
1822
1823
1824 write_conc_log( ' l_preset_tier=' || l_preset_tier);
1825 write_conc_log( ' l_current_tier_value=' || l_current_tier_value);
1826
1827 IF l_preset_tier is NOT NULL AND l_preset_tier > l_current_tier_value THEN
1828 l_current_tier_value := l_preset_tier;
1829 IF G_DEBUG THEN
1830 ozf_utility_pvt.debug_message('not reach preset tier: ');
1831 END IF;
1832 write_conc_log(' not reach preset tier:');
1833 END IF;
1834
1835
1836 y1 := LEAST((l_previous_tier_max-l_current_min_tier),l_ordered_qty) ;
1837 l_ordered_qty := l_ordered_qty - y1;
1838 IF l_discount_type = '%' THEN
1839 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
1840 l_utilization_amount := l_utilization_amount + y1* l_current_tier_value / 100;
1841 ELSE
1842 l_utilization_amount := l_utilization_amount + y1* l_unit_selling_price * l_current_tier_value / 100;
1843 END IF;
1844 ELSIF l_discount_type = 'AMT' THEN
1845 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
1846 l_utilization_amount := l_utilization_amount + y1 / l_unit_selling_price * l_current_tier_value ;
1847 ELSE
1848 l_utilization_amount := l_utilization_amount + y1* l_current_tier_value ;
1849 END IF;
1850 END IF;
1851
1852 --l_previous_tier_max := l_current_min_tier - 1 ;
1853 l_previous_tier_max := l_current_min_tier;
1854
1855 IF G_DEBUG THEN
1856 ozf_utility_pvt.debug_message(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
1857 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
1858 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
1859 || ' l_new_utilization: ' || l_utilization_amount);
1860 END IF;
1861 write_conc_log(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
1862 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
1863 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
1864 || ' l_new_utilization: ' || l_utilization_amount);
1865
1866 EXIT WHEN l_ordered_qty <= 0;
1867
1868 END LOOP; -- end of loop for c_prior_tiers
1869 CLOSE c_prior_tiers;
1870
1871 END IF; -- IF NVL(l_retroactive, 'N') = 'N' THEN
1872
1873
1874 write_conc_log('l_utilization_amount : '||l_utilization_amount);
1875
1876
1877 l_utilization_amount := NVL(l_utilization_amount,0) - NVL(l_adj_amount,0);
1878
1879 l_act_budgets_rec.request_amount := l_utilization_amount;
1880 l_act_budgets_rec.approved_amount := l_utilization_amount;
1881 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
1882
1883 ----end of booked orders
1884
1885 write_conc_log('calling ozf_fund_adjustment_pvt.process_act_budgets');
1886
1887 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
1888 ,x_msg_count => x_msg_count
1889 ,x_msg_data => x_msg_data
1890 ,p_act_budgets_rec => l_act_budgets_rec
1891 ,p_act_util_rec => l_act_util_rec
1892 ,x_act_budget_id => l_act_budget_id
1893 );
1894
1895 write_conc_log('process_act_budgets returns: ' || x_return_status);
1896
1897 IF x_return_status <> fnd_api.g_ret_sts_success THEN
1898 RETURN;
1899 END IF;
1900
1901 --END IF; --IF NVL(l_adjustment_exists,0) <> 1 THEN
1902
1903 -- END IF; --IF l_gl_date IS NOT NULL THEN
1904
1905 <<l_endofOrderloop>>
1906 NULL;
1907
1908 END LOOP; --FOR j IN l_order_line_tbl.first .. l_order_line_tbl.last
1909
1910 END IF; --IF l_order_line_tbl.count > 0 THEN
1911
1912 END adjustment_volume_retro;
1913 ---------------------------------------------------------------------
1914 -- PROCEDURE
1915 -- adjust_backdated_offer
1916 --
1917 -- PURPOSE
1918 -- This API is called from the concurrent process Post Backdated Adjusted Offer
1919 -- PARAMETERS
1920 -- x_errbuf OUT NOCOPY VARCHAR2 STANDARD OUT NOCOPY PARAMETER
1921 -- x_retcode OUT NOCOPY NUMBER STANDARD OUT NOCOPY PARAMETER
1922 -- NOTES
1923 -- HISTORY
1924 -- 4/18/2002 Mumu Pande Create.
1925 -- 07/05/2005 feliu fix following issues
1926 -- 1. update discount in QP only when sysdate pass effective date.
1927 ----------------------------------------------------------------------
1928 PROCEDURE adjust_backdated_offer (x_errbuf OUT NOCOPY VARCHAR2,
1929 x_retcode OUT NOCOPY NUMBER,
1930 p_debug IN VARCHAR2 := 'N' ) IS
1931
1932 CURSOR c_adjusted_offer_cur IS
1933 SELECT offer_adjustment_id,
1934 list_header_id,
1935 effective_date,
1936 approved_date
1937 FROM ozf_offer_adjustments_b
1938 WHERE status_code = 'ACTIVE'
1939 AND nvl(budget_adjusted_flag, 'N') = 'N'
1940 AND effective_date < approved_date; --query only backdated adjustments
1941
1942 --This cursor consists of following 3 sections:
1943 --1) Pick new products added via adjustment, this was fixed in 11.5.10
1944 --This was missing from R12+
1945 --2) Pick all lines for accrual/off-inv, promotional, order value and trade deal offes
1946 --3) pick volume offer lines since it uses diff. tables other than all offer types.
1947 --For trade deal its better to use case as in c_order_header cursor
1948 --but we will need to join with ozf_offers table.Check and do it.
1949
1950 CURSOR c_adjusted_line_cur(p_offer_adjustment_id IN NUMBER) IS
1951 SELECT adj.offer_adjustment_line_id,
1952 adj.list_line_id to_list_line_id
1953 FROM ozf_offer_adjustment_lines adj
1954 WHERE adj.offer_adjustment_id = p_offer_adjustment_id
1955 AND adj.created_from_adjustments = 'Y'
1956 UNION ALL
1957 SELECT adj.offer_adjustment_line_id,
1958 to_list_line_id
1959 FROM ozf_offer_adjustment_lines adj,
1960 qp_list_lines lines,
1961 ozf_offer_adj_rltd_lines rltd
1962 WHERE adj.offer_adjustment_id = p_offer_adjustment_id
1963 AND lines.list_line_type_code = 'DIS'
1964 AND lines.list_line_id =nvl(adj.list_line_id, adj.list_line_id_td)
1965 AND rltd.from_list_line_id = adj.list_line_id
1966 AND rltd.offer_adjustment_id = adj.offer_adjustment_id
1967 UNION ALL
1968 SELECT DISTINCT orig_line.parent_discount_line_id offer_adjustment_line_id,
1969 --AMITAMKU Fix for bug 15935374
1970 orig_line.parent_discount_line_id to_list_line_id --null to_list_line_id
1971 FROM ozf_offer_adjustment_tiers adj_line,
1972 ozf_offer_discount_lines orig_line
1973 WHERE adj_line.offer_adjustment_id = p_offer_adjustment_id
1974 AND adj_line.offer_discount_line_id = orig_line.offer_discount_line_id;
1975
1976
1977 --ozf_temp_eligibility table can have huge volume of data given that the
1978 --prod categories will be denormed and added there.
1979 --Given that it is joined with oe_order_lines_all we need to go via
1980 --perf team's suggestion on the HINTs, so it requires now 2 cursors
1981 -- Reason for 2 more cursors is explained below
1982
1983 CURSOR c_order_header1 IS
1984 SELECT
1985
1986 /*+ leading(temp) use_nl(temp line header) */ line.header_id,
1987 line.line_id,
1988 line.inventory_item_id,
1989 line.unit_list_price,
1990 line.unit_selling_price,
1991 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
1992 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
1993 line.invoice_to_org_id,
1994 line.sold_to_org_id,
1995 line.ship_to_org_id,
1996 line.line_category_code,
1997 line.reference_line_id,
1998 line.order_quantity_uom,
1999 line.pricing_quantity_uom,
2000 line.price_list_id,
2001 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2002 line.actual_shipment_date,
2003 line.request_date,
2004 line.fulfillment_date,
2005 line.line_type_id,
2006 line.end_customer_id,
2007 line.agreement_id,
2008 line.cust_po_number,
2009 line.ship_from_org_id,
2010 line.shipment_priority_code,
2011 line.shippable_flag,
2012 line.schedule_ship_date,
2013 line.source_type_code,
2014 line.org_id,
2015 line.freight_terms_code,
2016 line.payment_term_id,
2017 line.shipping_method_code,
2018 line.item_identifier_type,
2019 line.ordered_item_id,
2020 line.top_model_line_id,
2021 line.unit_percent_base_price,
2022 line.preferred_grade,
2023 line.Blanket_number,
2024 line.minisite_id,
2025 line.blanket_line_number,
2026 line.transaction_phase_code,
2027 line.charge_periodicity_code,
2028 adj_line.offer_adjustment_line_id,
2029 adj_line.list_header_id,
2030 qp.orig_org_id offer_org_id,
2031 off.transaction_currency_code offer_currency,
2032 qpa.product_uom_code,
2033 lines.arithmetic_operator,
2034 lines.list_line_id,
2035 line.shipped_quantity,
2036 line.invoice_interface_status_code,
2037 line.invoiced_quantity,
2038 line.shipping_quantity_uom,
2039 line.shipping_quantity, -- Catch Weight ER
2040 line.shipping_quantity_uom2, -- Catch Weight ER
2041 line.shipping_quantity2, -- Catch Weight ER
2042 line.fulfillment_base -- Catch Weight ER
2043 FROM oe_order_lines_all line,
2044 ozf_adj_temp_eligibility temp,
2045 ozf_offer_adjustments_b adj,
2046 ozf_offer_adjustment_lines adj_line,
2047 ozf_offers off,
2048 qp_list_lines lines,
2049 qp_list_headers_all qp,
2050 qp_pricing_attributes qpa
2051 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)))
2052 BETWEEN decode(adj_line.created_from_adjustments, 'Y', TRUNC(nvl(lines.start_date_active, adj.effective_date)), adj.effective_date)
2053 AND decode(adj_line.created_from_adjustments, 'Y', TRUNC(
2054 CASE
2055 WHEN lines.end_date_active IS NOT NULL
2056 AND lines.end_date_active < adj.approved_date THEN lines.end_date_active
2057 ELSE adj.approved_date
2058 END), TRUNC(
2059 CASE
2060 WHEN adj.approved_date > nvl(lines.start_date_active, off.start_date) THEN nvl(lines.start_date_active, off.start_date)
2061 ELSE adj.approved_date
2062 END))
2063 AND line.booked_flag = 'Y'
2064 AND line.cancelled_flag = 'N'
2065 AND off.offer_type <> 'VOLUME_OFFER'
2066 AND temp.object_type <> 'FUND'
2067 AND line.inventory_item_id = temp.eligibility_id
2068 AND temp.offer_adjustment_line_id = adj_line.offer_adjustment_line_id
2069 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2070 AND qp.list_header_id = off.qp_list_header_id
2071 AND qpa.list_line_id = lines.list_line_id
2072 AND off.qp_list_header_id = adj.list_header_id
2073 AND off.qp_list_header_id = lines.list_header_id
2074 AND adj.list_header_id = lines.list_header_id
2075 AND lines.list_line_id IN
2076 (SELECT from_list_line_id
2077 FROM ozf_offer_adj_rltd_lines adjr START WITH adjr.from_list_line_id = adj_line.list_line_id
2078 AND adjr.offer_adjustment_id = adj_line.offer_adjustment_id CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
2079 UNION ALL
2080 SELECT list_line_id
2081 FROM ozf_offer_adjustment_lines);
2082
2083
2084 CURSOR c_order_header2 IS
2085 SELECT /*+ parallel(line) */ line.header_id,
2086 line.line_id,
2087 line.inventory_item_id,
2088 line.unit_list_price,
2089 line.unit_selling_price,
2090 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
2091 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
2092 line.invoice_to_org_id,
2093 line.sold_to_org_id,
2094 line.ship_to_org_id,
2095 line.line_category_code,
2096 line.reference_line_id,
2097 line.order_quantity_uom,
2098 line.pricing_quantity_uom,
2099 line.price_list_id,
2100 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2101 line.actual_shipment_date,
2102 line.request_date,
2103 line.fulfillment_date,
2104 line.line_type_id,
2105 line.end_customer_id,
2106 line.agreement_id,
2107 line.cust_po_number,
2108 line.ship_from_org_id,
2109 line.shipment_priority_code,
2110 line.shippable_flag,
2111 line.schedule_ship_date,
2112 line.source_type_code,
2113 line.org_id,
2114 line.freight_terms_code,
2115 line.payment_term_id,
2116 line.shipping_method_code,
2117 line.item_identifier_type,
2118 line.ordered_item_id,
2119 line.top_model_line_id,
2120 line.unit_percent_base_price,
2121 line.preferred_grade,
2122 line.Blanket_number,
2123 line.minisite_id,
2124 line.blanket_line_number,
2125 line.transaction_phase_code,
2126 line.charge_periodicity_code,
2127 adj_line.offer_adjustment_line_id,
2128 adj_line.list_header_id,
2129 qp.orig_org_id offer_org_id,
2130 off.transaction_currency_code offer_currency,
2131 qpa.product_uom_code,
2132 lines.arithmetic_operator,
2133 lines.list_line_id,
2134 line.shipped_quantity,
2135 line.invoice_interface_status_code,
2136 line.invoiced_quantity,
2137 line.shipping_quantity_uom,
2138 line.shipping_quantity, -- Catch Weight ER
2139 line.shipping_quantity_uom2, -- Catch Weight ER
2140 line.shipping_quantity2, -- Catch Weight ER
2141 line.fulfillment_base -- Catch Weight ER
2142 FROM oe_order_lines_all line,
2143 ozf_adj_temp_eligibility temp,
2144 ozf_offer_adjustments_b adj,
2145 ozf_offer_adjustment_lines adj_line,
2146 ozf_offers off,
2147 qp_list_lines lines,
2148 qp_list_headers_all qp,
2149 qp_pricing_attributes qpa
2150 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)))
2151 BETWEEN decode(adj_line.created_from_adjustments, 'Y', TRUNC(nvl(lines.start_date_active, adj.effective_date)), adj.effective_date)
2152 AND decode(adj_line.created_from_adjustments, 'Y', TRUNC(
2153 CASE
2154 WHEN lines.end_date_active IS NOT NULL
2155 AND lines.end_date_active < adj.approved_date THEN lines.end_date_active
2156 ELSE adj.approved_date
2157 END), TRUNC(
2158 CASE
2159 WHEN adj.approved_date > nvl(lines.start_date_active, off.start_date) THEN nvl(lines.start_date_active, off.start_date)
2160 ELSE adj.approved_date
2161 END))
2162 AND line.booked_flag = 'Y'
2163 AND line.cancelled_flag = 'N'
2164 AND off.offer_type <> 'VOLUME_OFFER'
2165 AND temp.object_type <> 'FUND'
2166 AND line.inventory_item_id = temp.eligibility_id
2167 AND temp.offer_adjustment_line_id = adj_line.offer_adjustment_line_id
2168 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2169 AND qp.list_header_id = off.qp_list_header_id
2170 AND qpa.list_line_id = lines.list_line_id
2171 AND off.qp_list_header_id = adj.list_header_id
2172 AND off.qp_list_header_id = lines.list_header_id
2173 AND adj.list_header_id = lines.list_header_id
2174 AND lines.list_line_id IN
2175 (SELECT from_list_line_id
2176 FROM ozf_offer_adj_rltd_lines adjr START WITH adjr.from_list_line_id = adj_line.list_line_id
2177 AND adjr.offer_adjustment_id = adj_line.offer_adjustment_id CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
2178 UNION ALL
2179 SELECT list_line_id
2180 FROM ozf_offer_adjustment_lines);
2181
2182 --These two cursors are needed when a volume offer ACTIVE
2183 -- backdated adjustment exists.
2184 --union_all instead on union will improve the query perf but
2185 -- we want a unique set of order header records, so that pricing call
2186 -- is made only once per order header, even if the same order
2187 -- qualifies for volume offer as well.
2188 CURSOR c_order_header3 IS
2189 SELECT
2190
2191 /*+ leading(temp) use_nl(temp line header) */ line.header_id,
2192 line.line_id,
2193 line.inventory_item_id,
2194 line.unit_list_price,
2195 line.unit_selling_price,
2196 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
2197 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
2198 line.invoice_to_org_id,
2199 line.sold_to_org_id,
2200 line.ship_to_org_id,
2201 line.line_category_code,
2202 line.reference_line_id,
2203 line.order_quantity_uom,
2204 line.pricing_quantity_uom,
2205 line.price_list_id,
2206 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2207 line.actual_shipment_date,
2208 line.request_date,
2209 line.fulfillment_date,
2210 line.line_type_id,
2211 line.end_customer_id,
2212 line.agreement_id,
2213 line.cust_po_number,
2214 line.ship_from_org_id,
2215 line.shipment_priority_code,
2216 line.shippable_flag,
2217 line.schedule_ship_date,
2218 line.source_type_code,
2219 line.org_id,
2220 line.freight_terms_code,
2221 line.payment_term_id,
2222 line.shipping_method_code,
2223 line.item_identifier_type,
2224 line.ordered_item_id,
2225 line.top_model_line_id,
2226 line.unit_percent_base_price,
2227 line.preferred_grade,
2228 line.Blanket_number,
2229 line.minisite_id,
2230 line.blanket_line_number,
2231 line.transaction_phase_code,
2232 line.charge_periodicity_code,
2233 adj_line.offer_adjustment_line_id,
2234 adj_line.list_header_id,
2235 qp.orig_org_id offer_org_id,
2236 off.transaction_currency_code offer_currency,
2237 qpa.product_uom_code,
2238 lines.arithmetic_operator,
2239 lines.list_line_id,
2240 line.shipped_quantity,
2241 line.invoice_interface_status_code,
2242 line.invoiced_quantity,
2243 line.shipping_quantity_uom,
2244 line.shipping_quantity, -- Catch Weight ER
2245 line.shipping_quantity_uom2, -- Catch Weight ER
2246 line.shipping_quantity2, -- Catch Weight ER
2247 line.fulfillment_base -- Catch Weight ER
2248 FROM oe_order_lines_all line,
2249 ozf_adj_temp_eligibility temp,
2250 ozf_offer_adjustments_b adj,
2251 ozf_offer_adjustment_lines adj_line,
2252 ozf_offers off,
2253 qp_list_lines lines,
2254 qp_list_headers_all qp,
2255 qp_pricing_attributes qpa
2256 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)))
2257 BETWEEN decode(adj_line.created_from_adjustments, 'Y', TRUNC(nvl(lines.start_date_active, adj.effective_date)), adj.effective_date)
2258 AND decode(adj_line.created_from_adjustments, 'Y', TRUNC(
2259 CASE
2260 WHEN lines.end_date_active IS NOT NULL
2261 AND lines.end_date_active < adj.approved_date THEN lines.end_date_active
2262 ELSE adj.approved_date
2263 END), TRUNC(
2264 CASE
2265 WHEN adj.approved_date > nvl(lines.start_date_active, off.start_date) THEN nvl(lines.start_date_active, off.start_date)
2266 ELSE adj.approved_date
2267 END))
2268 AND line.booked_flag = 'Y'
2269 AND line.cancelled_flag = 'N'
2270 AND off.offer_type <> 'VOLUME_OFFER'
2271 AND temp.object_type <> 'FUND'
2272 AND line.inventory_item_id = temp.eligibility_id
2273 AND temp.offer_adjustment_line_id = adj_line.offer_adjustment_line_id
2274 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2275 AND qp.list_header_id = off.qp_list_header_id
2276 AND qpa.list_line_id = lines.list_line_id
2277 AND off.qp_list_header_id = adj.list_header_id
2278 AND off.qp_list_header_id = lines.list_header_id
2279 AND adj.list_header_id = lines.list_header_id
2280 AND lines.list_line_id IN
2281 (SELECT from_list_line_id
2282 FROM ozf_offer_adj_rltd_lines adjr START WITH adjr.from_list_line_id = adj_line.list_line_id
2283 AND adjr.offer_adjustment_id = adj_line.offer_adjustment_id CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
2284 UNION ALL
2285 SELECT list_line_id
2286 FROM ozf_offer_adjustment_lines)
2287 UNION ALL
2288 SELECT
2289 /*+ leading(temp) use_nl(temp line header) */ line.header_id,
2290 line.line_id,
2291 line.inventory_item_id,
2292 line.unit_list_price,
2293 line.unit_selling_price,
2294 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
2295 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
2296 line.invoice_to_org_id,
2297 line.sold_to_org_id,
2298 line.ship_to_org_id,
2299 line.line_category_code,
2300 line.reference_line_id,
2301 line.order_quantity_uom,
2302 line.pricing_quantity_uom,
2303 line.price_list_id,
2304 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2305 line.actual_shipment_date,
2306 line.request_date,
2307 line.fulfillment_date,
2308 line.line_type_id,
2309 line.end_customer_id,
2310 line.agreement_id,
2311 line.cust_po_number,
2312 line.ship_from_org_id,
2313 line.shipment_priority_code,
2314 line.shippable_flag,
2315 line.schedule_ship_date,
2316 line.source_type_code,
2317 line.org_id,
2318 line.freight_terms_code,
2319 line.payment_term_id,
2320 line.shipping_method_code,
2321 line.item_identifier_type,
2322 line.ordered_item_id,
2323 line.top_model_line_id,
2324 line.unit_percent_base_price,
2325 line.preferred_grade,
2326 line.Blanket_number,
2327 line.minisite_id,
2328 line.blanket_line_number,
2329 line.transaction_phase_code,
2330 line.charge_periodicity_code,
2331 orig_disc.offer_discount_line_id,
2332 off.qp_list_header_id,
2333 qp.orig_org_id offer_org_id,
2334 off.transaction_currency_code offer_currency,
2335 orig_disc.uom_code product_uom_code,
2336 orig_disc.discount_type arithmetic_operator,
2337 lines.list_line_id,
2338 line.shipped_quantity,
2339 line.invoice_interface_status_code,
2340 line.invoiced_quantity,
2341 line.shipping_quantity_uom,
2342 line.shipping_quantity, -- Catch Weight ER
2343 line.shipping_quantity_uom2, -- Catch Weight ER
2344 line.shipping_quantity2, -- Catch Weight ER
2345 line.fulfillment_base -- Catch Weight ER
2346 FROM oe_order_lines_all line,
2347 ozf_adj_temp_eligibility temp,
2348 ozf_offer_adjustments_b adj,
2349 ozf_offer_adjustment_tiers adj_line,
2350 ozf_offer_discount_lines orig_disc,
2351 ozf_offers off,
2352 qp_list_headers_all qp,
2353 ozf_qp_discounts map_lines,
2354 qp_list_lines lines
2355 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date))) BETWEEN adj.effective_date
2356 AND TRUNC(off.start_date) -- no new products for volume offer.
2357 AND line.booked_flag = 'Y'
2358 AND line.cancelled_flag = 'N'
2359 AND off.offer_type = 'VOLUME_OFFER'
2360 AND temp.object_type <> 'FUND'
2361 AND line.inventory_item_id = temp.eligibility_id
2362 AND temp.offer_adjustment_line_id = orig_disc.parent_discount_line_id
2363 AND adj_line.offer_discount_line_id = orig_disc.offer_discount_line_id
2364 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2365 AND orig_disc.offer_discount_line_id = map_lines.offer_discount_line_id
2366 AND qp.list_header_id = off.qp_list_header_id
2367 AND lines.list_line_id = map_lines.list_line_id
2368 AND off.qp_list_header_id = adj.list_header_id
2369 AND(lines.end_date_active IS NULL OR lines.end_date_active >= sysdate);
2370
2371
2372 CURSOR c_order_header4 IS
2373 SELECT
2374
2375 /*+ parallel(line) */ line.header_id,
2376 line.line_id,
2377 line.inventory_item_id,
2378 line.unit_list_price,
2379 line.unit_selling_price,
2380 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
2381 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
2382 line.invoice_to_org_id,
2383 line.sold_to_org_id,
2384 line.ship_to_org_id,
2385 line.line_category_code,
2386 line.reference_line_id,
2387 line.order_quantity_uom,
2388 line.pricing_quantity_uom,
2389 line.price_list_id,
2390 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2391 line.actual_shipment_date,
2392 line.request_date,
2393 line.fulfillment_date,
2394 line.line_type_id,
2395 line.end_customer_id,
2396 line.agreement_id,
2397 line.cust_po_number,
2398 line.ship_from_org_id,
2399 line.shipment_priority_code,
2400 line.shippable_flag,
2401 line.schedule_ship_date,
2402 line.source_type_code,
2403 line.org_id,
2404 line.freight_terms_code,
2405 line.payment_term_id,
2406 line.shipping_method_code,
2407 line.item_identifier_type,
2408 line.ordered_item_id,
2409 line.top_model_line_id,
2410 line.unit_percent_base_price,
2411 line.preferred_grade,
2412 line.Blanket_number,
2413 line.minisite_id,
2414 line.blanket_line_number,
2415 line.transaction_phase_code,
2416 line.charge_periodicity_code,
2417 adj_line.offer_adjustment_line_id,
2418 adj_line.list_header_id,
2419 qp.orig_org_id offer_org_id,
2420 off.transaction_currency_code offer_currency,
2421 qpa.product_uom_code,
2422 lines.arithmetic_operator,
2423 lines.list_line_id,
2424 line.shipped_quantity,
2425 line.invoice_interface_status_code,
2426 line.invoiced_quantity,
2427 line.shipping_quantity_uom,
2428 line.shipping_quantity, -- Catch Weight ER
2429 line.shipping_quantity_uom2, -- Catch Weight ER
2430 line.shipping_quantity2, -- Catch Weight ER
2431 line.fulfillment_base -- Catch Weight ER
2432 FROM oe_order_lines_all line,
2433 ozf_adj_temp_eligibility temp,
2434 ozf_offer_adjustments_b adj,
2435 ozf_offer_adjustment_lines adj_line,
2436 ozf_offers off,
2437 qp_list_lines lines,
2438 qp_list_headers_all qp,
2439 qp_pricing_attributes qpa
2440 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)))
2441 BETWEEN decode(adj_line.created_from_adjustments, 'Y', TRUNC(nvl(lines.start_date_active, adj.effective_date)), adj.effective_date)
2442 AND decode(adj_line.created_from_adjustments, 'Y', TRUNC(
2443 CASE
2444 WHEN lines.end_date_active IS NOT NULL
2445 AND lines.end_date_active < adj.approved_date THEN lines.end_date_active
2446 ELSE adj.approved_date
2447 END), TRUNC(
2448 CASE
2449 WHEN adj.approved_date > nvl(lines.start_date_active, off.start_date) THEN nvl(lines.start_date_active, off.start_date)
2450 ELSE adj.approved_date
2451 END))
2452 AND line.booked_flag = 'Y'
2453 AND line.cancelled_flag = 'N'
2454 AND off.offer_type <> 'VOLUME_OFFER'
2455 AND temp.object_type <> 'FUND'
2456 AND line.inventory_item_id = temp.eligibility_id
2457 AND temp.offer_adjustment_line_id = adj_line.offer_adjustment_line_id
2458 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2459 AND qp.list_header_id = off.qp_list_header_id
2460 AND qpa.list_line_id = lines.list_line_id
2461 AND off.qp_list_header_id = adj.list_header_id
2462 AND off.qp_list_header_id = lines.list_header_id
2463 AND adj.list_header_id = lines.list_header_id
2464 AND lines.list_line_id IN
2465 (SELECT from_list_line_id
2466 FROM ozf_offer_adj_rltd_lines adjr START WITH adjr.from_list_line_id = adj_line.list_line_id
2467 AND adjr.offer_adjustment_id = adj_line.offer_adjustment_id CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
2468 UNION ALL
2469 SELECT list_line_id
2470 FROM ozf_offer_adjustment_lines)
2471 UNION ALL
2472 SELECT
2473 /*+ parallel(line) */ line.header_id,
2474 line.line_id,
2475 line.inventory_item_id,
2476 line.unit_list_price,
2477 line.unit_selling_price,
2478 nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0)) quantity,
2479 nvl(line.pricing_quantity, nvl(line.shipped_quantity, nvl(line.ordered_quantity, 0))) pricing_quantity,
2480 line.invoice_to_org_id,
2481 line.sold_to_org_id,
2482 line.ship_to_org_id,
2483 line.line_category_code,
2484 line.reference_line_id,
2485 line.order_quantity_uom,
2486 line.pricing_quantity_uom,
2487 line.price_list_id,
2488 nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date)) pricing_date,
2489 line.actual_shipment_date,
2490 line.request_date,
2491 line.fulfillment_date,
2492 line.line_type_id,
2493 line.end_customer_id,
2494 line.agreement_id,
2495 line.cust_po_number,
2496 line.ship_from_org_id,
2497 line.shipment_priority_code,
2498 line.shippable_flag,
2499 line.schedule_ship_date,
2500 line.source_type_code,
2501 line.org_id,
2502 line.freight_terms_code,
2503 line.payment_term_id,
2504 line.shipping_method_code,
2505 line.item_identifier_type,
2506 line.ordered_item_id,
2507 line.top_model_line_id,
2508 line.unit_percent_base_price,
2509 line.preferred_grade,
2510 line.Blanket_number,
2511 line.minisite_id,
2512 line.blanket_line_number,
2513 line.transaction_phase_code,
2514 line.charge_periodicity_code,
2515 orig_disc.offer_discount_line_id,
2516 off.qp_list_header_id,
2517 qp.orig_org_id offer_org_id,
2518 off.transaction_currency_code offer_currency,
2519 orig_disc.uom_code product_uom_code,
2520 orig_disc.discount_type arithmetic_operator,
2521 lines.list_line_id,
2522 line.shipped_quantity,
2523 line.invoice_interface_status_code,
2524 line.invoiced_quantity,
2525 line.shipping_quantity_uom,
2526 line.shipping_quantity, -- Catch Weight ER
2527 line.shipping_quantity_uom2, -- Catch Weight ER
2528 line.shipping_quantity2, -- Catch Weight ER
2529 line.fulfillment_base -- Catch Weight ER
2530 FROM oe_order_lines_all line,
2531 ozf_adj_temp_eligibility temp,
2532 ozf_offer_adjustments_b adj,
2533 ozf_offer_adjustment_tiers adj_line,
2534 ozf_offer_discount_lines orig_disc,
2535 ozf_offers off,
2536 qp_list_headers_all qp,
2537 ozf_qp_discounts map_lines,
2538 qp_list_lines lines
2539 WHERE TRUNC(nvl(line.pricing_date, nvl(line.actual_shipment_date, line.fulfillment_date))) BETWEEN adj.effective_date
2540 AND TRUNC(off.start_date) -- no new products for volume offer.
2541 AND line.booked_flag = 'Y'
2542 AND line.cancelled_flag = 'N'
2543 AND off.offer_type = 'VOLUME_OFFER'
2544 AND temp.object_type <> 'FUND'
2545 AND line.inventory_item_id = temp.eligibility_id
2546 AND temp.offer_adjustment_line_id = orig_disc.parent_discount_line_id
2547 AND adj_line.offer_discount_line_id = orig_disc.offer_discount_line_id
2548 AND adj.offer_adjustment_id = adj_line.offer_adjustment_id
2549 AND orig_disc.offer_discount_line_id = map_lines.offer_discount_line_id
2550 AND qp.list_header_id = off.qp_list_header_id
2551 AND lines.list_line_id = map_lines.list_line_id
2552 AND off.qp_list_header_id = adj.list_header_id
2553 AND(lines.end_date_active IS NULL OR lines.end_date_active >= sysdate);
2554
2555 CURSOR order_header_csr(p_header_id IN NUMBER) IS
2556 SELECT org_id, transactional_curr_code, order_type_id, sold_to_org_id, invoice_to_org_id,
2557 ship_to_org_id, price_list_id, ordered_date, request_date, pricing_date,
2558 agreement_id, cust_po_number, ship_from_org_id, order_category_code,
2559 shipment_priority_code, freight_terms_code, payment_term_id, shipping_method_code,
2560 conversion_rate_date, conversion_rate, conversion_type_code, minisite_id,
2561 blanket_number
2562 FROM oe_order_headers_all
2563 WHERE header_id = p_header_id;
2564
2565 CURSOR c_customer_qualified(p_invoice_to_org_id IN NUMBER, p_ship_to_org_id IN NUMBER, p_party_id NUMBER, p_list_header_id NUMBER) IS
2566 SELECT 'Y', object_type, qp_qualifier_group
2567 FROM ozf_activity_customers
2568 WHERE (
2569 (site_use_id = p_invoice_to_org_id AND site_use_code = 'BILL_TO') OR
2570 (site_use_id = p_ship_to_org_id AND site_use_code = 'SHIP_TO') OR
2571 (party_id = p_party_id AND site_use_code IS NULL) OR
2572 (party_id = -1)
2573 )
2574 AND object_class = 'OFFR'
2575 AND object_id = p_list_header_id
2576 AND ROWNUM = 1;
2577
2578 CURSOR c_cust_acct_qualified(p_sold_to_org_id IN NUMBER, p_party_id NUMBER, p_list_header_id NUMBER) IS
2579 SELECT 'Y', object_type, qp_qualifier_group
2580 FROM ozf_activity_customers
2581 WHERE (
2582 (cust_account_id = p_sold_to_org_id) OR
2583 (party_id = p_party_id AND site_use_code IS NULL) OR
2584 (party_id = -1)
2585 )
2586 AND object_class = 'OFFR'
2587 AND object_id = p_list_header_id
2588 AND ROWNUM = 1;
2589
2590 CURSOR c_party_id(p_sold_to_org_id IN NUMBER) IS
2591 SELECT party_id
2592 FROM hz_cust_accounts
2593 WHERE cust_account_id = p_sold_to_org_id;
2594
2595
2596 CURSOR c_count_temp IS
2597 SELECT COUNT(eligibility_id)
2598 FROM ozf_adj_temp_eligibility;
2599
2600 CURSOR c_offer_info (p_list_header_id IN NUMBER) IS
2601 SELECT off.offer_id, qp.description, qp.NAME,
2602 nvl(off.transaction_currency_code,fund_request_curr_code) transaction_currency_code,
2603 off.reusable, off.offer_type,
2604 --kdass 09-DEC-2005 fix for bug 4872799
2605 trunc(off.start_date) start_date
2606 ,off.volume_offer_type
2607 ,qp.orig_org_id offer_org_id, off.transaction_currency_code offer_currency
2608 FROM qp_list_headers_all qp, ozf_offers off
2609 WHERE qp.list_header_id = p_list_header_id
2610 AND qp.list_header_id = off.qp_list_header_id;
2611
2612
2613 x_return_status VARCHAR2 (20);
2614 l_temp_count NUMBER;
2615 l_temp_data VARCHAR2 (2000) := NULL;
2616 l_msg_count NUMBER;
2617 l_msg_data VARCHAR2 (2000) := NULL;
2618 l_api_name VARCHAR2 (50) := 'adjust_backdated_offer';
2619 l_full_name CONSTANT VARCHAR2 (90) := g_pkg_name
2620 || '.'
2621 || l_api_name;
2622 l_api_version NUMBER := 1;
2623 l_index NUMBER := 1;
2624 l_justification VARCHAR2(50);
2625
2626
2627 TYPE orderCurrTbl IS TABLE OF oe_order_headers_all.transactional_curr_code%TYPE;
2628 TYPE lineCatCodeTbl IS TABLE OF oe_order_lines_all.line_category_code%TYPE;
2629 TYPE groupNosTbl IS TABLE OF VARCHAR2(256) INDEX BY BINARY_INTEGER;
2630 TYPE uomTbl IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
2631 TYPE pricingDateTbl IS TABLE OF oe_order_lines_all.pricing_date%TYPE;
2632 TYPE actualShipDateTbl IS TABLE OF oe_order_lines_all.actual_shipment_date%TYPE;
2633 TYPE requestDateTbl IS TABLE OF oe_order_lines_all.request_date%TYPE;
2634 TYPE fulfillmentDateTbl IS TABLE OF oe_order_lines_all.fulfillment_date%TYPE;
2635 TYPE offCurrTbl IS TABLE OF ozf_offers.transaction_currency_code%TYPE;
2636 TYPE arithOperTbl IS TABLE OF qp_list_lines.arithmetic_operator%TYPE;
2637
2638 TYPE custPONumberTbl IS TABLE OF oe_order_lines_all.cust_po_number%TYPE;
2639 TYPE shipmentPriorityCodeTbl IS TABLE OF oe_order_lines_all.shipment_priority_code%TYPE;
2640 TYPE shippableFlagTbl IS TABLE OF oe_order_lines_all.shippable_flag%TYPE;
2641 TYPE scheduleShipDateTbl IS TABLE OF oe_order_lines_all.schedule_ship_date%TYPE;
2642 TYPE sourceTypeCodeTbl IS TABLE OF oe_order_lines_all.source_type_code%TYPE;
2643 TYPE freightTermsCodeTbl IS TABLE OF oe_order_lines_all.freight_terms_code%TYPE;
2644 TYPE shippingMethodCodeTbl IS TABLE OF oe_order_lines_all.shipping_method_code%TYPE;
2645 TYPE itemIdentifierTypeTbl IS TABLE OF oe_order_lines_all.item_identifier_type%TYPE;
2646 TYPE unitPercentBasePriceTbl IS TABLE OF oe_order_lines_all.unit_percent_base_price%TYPE;
2647 TYPE preferredGradeTbl IS TABLE OF oe_order_lines_all.preferred_grade%TYPE;
2648 TYPE blanketNumberTbl IS TABLE OF oe_order_lines_all.Blanket_number%TYPE;
2649 TYPE blanketLineNumberTbl IS TABLE OF oe_order_lines_all.blanket_line_number%TYPE;
2650 TYPE transactionPhaseCodeTbl IS TABLE OF oe_order_lines_all.transaction_phase_code%TYPE;
2651 TYPE chargePeriodicityCodeTbl IS TABLE OF oe_order_lines_all.charge_periodicity_code%TYPE;
2652
2653 TYPE hdrRequestDateTbl IS TABLE OF oe_order_headers_all.request_date%TYPE;
2654 TYPE hdrPricingDateTbl IS TABLE OF oe_order_headers_all.pricing_date%TYPE;
2655 TYPE hdrOrderedDateTbl IS TABLE OF oe_order_headers_all.ordered_date%TYPE;
2656
2657 TYPE hdrCustPONumberTbl IS TABLE OF oe_order_headers_all.cust_po_number%TYPE;
2658 TYPE hdrOrderCategoryCodeTbl IS TABLE OF oe_order_headers_all.order_category_code%TYPE;
2659 TYPE hdrShipmentPriorityCodeTbl IS TABLE OF oe_order_headers_all.shipment_priority_code%TYPE;
2660 TYPE hdrFreightTermsCodeTbl IS TABLE OF oe_order_headers_all.freight_terms_code%TYPE;
2661 TYPE hdrShippingMethodCodeTbl IS TABLE OF oe_order_headers_all.shipping_method_code%TYPE;
2662 TYPE hdrConversionRateDateTbl IS TABLE OF oe_order_headers_all.conversion_rate_date%TYPE;
2663 TYPE hdrConversionRateTbl IS TABLE OF oe_order_headers_all.conversion_rate%TYPE;
2664 TYPE hdrConversionTypeCodeTbl IS TABLE OF oe_order_headers_all.conversion_type_code%TYPE;
2665 TYPE hdrBlanketNumberTbl IS TABLE OF oe_order_headers_all.blanket_number%TYPE;
2666 TYPE invoiceInterfaceStatusTbl IS TABLE OF oe_order_lines_all.invoice_interface_status_code%TYPE;
2667 TYPE shippingQuantityUomTbl IS TABLE OF oe_order_lines_all.shipping_quantity_uom%TYPE;
2668 -- Catch Weight ER
2669 TYPE shippingQuantityTbl IS TABLE OF oe_order_lines_all.shipping_quantity%TYPE;
2670 TYPE fulfillmentBaseTbl IS TABLE OF oe_order_lines_all.fulfillment_base%TYPE;
2671 -- Catch Weight ER
2672
2673 TYPE numberTblType IS TABLE OF NUMBER;
2674
2675 l_headerIdTbl numberTbl;
2676 l_lineIdTbl numberTbl;
2677 l_inventoryItemIdTbl numberTbl;
2678 l_unitListPriceTbl numberTbl;
2679 l_unitSellingPriceTbl numberTbl;
2680 l_quantityTbl numberTbl;
2681 l_pricingQuantityTbl numberTbl;
2682 l_invoiceToOrgIdTbl numberTbl;
2683 l_soldToOrgIdTbl numberTbl;
2684 l_shipToOrgIdTbl numberTbl;
2685 l_lineCatCodeTbl lineCatCodeTbl;
2686 l_refLineIdTbl numberTbl;
2687 l_orderNumberTbl numberTbl;
2688 l_group_nos groupNosTbl;
2689 l_orgIdTbl numberTbl;
2690 l_orderUomTbl uomTbl;
2691 l_pricingUomTbl uomTbl;
2692 l_priceListIdTbl numberTbl;
2693 l_pricingDateTbl pricingDateTbl;
2694 l_actualShipDateTbl actualShipDateTbl;
2695 l_requestDateTbl requestDateTbl;
2696 l_fulfillmentDateTbl fulfillmentDateTbl;
2697 l_offAdjLineIdTbl numberTbl;
2698 l_qpListHeaderIdTbl numberTbl;
2699 l_offOrgIdTbl numberTbl;
2700 l_offCurrTbl offCurrTbl;
2701 l_prodUomTbl uomTbl;
2702 l_arithOperTbl arithOperTbl;
2703 l_listLineIdTbl numberTbl;
2704 l_lineTypeIdTbl numberTbl;
2705 l_shippedQuantityTbl numberTbl;
2706 l_invoiceInterfaceStatusTbl invoiceInterfaceStatusTbl;
2707 l_invoicedQuantityTbl numberTbl;
2708 l_shippingQuantityUomTbl shippingQuantityUomTbl;
2709 -- Catch Weight ER
2710 l_shippingQuantityTbl shippingQuantityTbl;
2711 l_shippingQuantityUom2Tbl shippingQuantityUomTbl;
2712 l_shippingQuantity2Tbl shippingQuantityTbl;
2713 l_fulfillmentBaseTbl fulfillmentBaseTbl;
2714 -- Catch Weight ER
2715
2716 l_endCustomerIdTbl numberTbl;
2717 l_agreementIdTbl numberTbl;
2718 l_custPONumberTbl custPONumberTbl;
2719 l_shipFromOrgIdTbl numberTbl;
2720 l_shipmentPriorityCodeTbl shipmentPriorityCodeTbl;
2721 l_shippableFlagTbl shippableFlagTbl;
2722 l_scheduleShipDateTbl scheduleShipDateTbl;
2723 l_sourceTypeCodeTbl sourceTypeCodeTbl;
2724 l_freightTermsCodeTbl freightTermsCodeTbl;
2725 l_paymentTermIdTbl numberTbl;
2726 l_shippingMethodCodeTbl shippingMethodCodeTbl;
2727 l_itemIdentifierTypeTbl itemIdentifierTypeTbl;
2728 l_orderedItemIdTbl numberTbl;
2729 l_topModelLineIdTbl numberTbl;
2730 l_unitPercentBasePriceTbl unitPercentBasePriceTbl;
2731 l_preferredGradeTbl preferredGradeTbl;
2732 l_blanketNumberTbl blanketNumberTbl;
2733 l_minisiteIdTbl numberTbl;
2734 l_blanketLineNumberTbl blanketLineNumberTbl;
2735 l_transactionPhaseCodeTbl transactionPhaseCodeTbl;
2736 l_chargePeriodicityCodeTbl chargePeriodicityCodeTbl;
2737
2738 l_hdrOrgIdTbl numberTblType := numberTblType();
2739 l_orderCurrTbl orderCurrTbl := orderCurrTbl();
2740 l_orderTypeIdTbl numberTblType := numberTblType();
2741 l_hdrSoldToOrgIdTbl numberTblType := numberTblType();
2742 l_hdrInvoiceToOrgIdTbl numberTblType := numberTblType();
2743 l_hdrShipToOrgIdTbl numberTblType := numberTblType();
2744 l_hdrPriceListIdTbl numberTblType := numberTblType();
2745 l_hdrOrderedDateTbl hdrOrderedDateTbl := hdrOrderedDateTbl();
2746 l_hdrRequestDateTbl hdrRequestDateTbl := hdrRequestDateTbl();
2747 l_hdrPricingDateTbl hdrPricingDateTbl := hdrPricingDateTbl();
2748 l_hdrAgreementIdTbl numberTblType := numberTblType();
2749 l_hdrCustPONumberTbl hdrCustPONumberTbl := hdrCustPONumberTbl();
2750 l_hdrShipFromOrgIdTbl numberTblType := numberTblType();
2751 l_hdrOrderCategoryCodeTbl hdrOrderCategoryCodeTbl := hdrOrderCategoryCodeTbl();
2752 l_hdrShipmentPriorityCodeTbl hdrShipmentPriorityCodeTbl := hdrShipmentPriorityCodeTbl();
2753 l_hdrFreightTermsCodeTbl hdrFreightTermsCodeTbl := hdrFreightTermsCodeTbl();
2754 l_hdrPaymentTermIdTbl numberTblType := numberTblType();
2755 l_hdrShippingMethodCodeTbl hdrShippingMethodCodeTbl := hdrShippingMethodCodeTbl();
2756 l_hdrConversionRateDateTbl hdrConversionRateDateTbl := hdrConversionRateDateTbl();
2757 l_hdrConversionRateTbl hdrConversionRateTbl := hdrConversionRateTbl();
2758 l_hdrConversionTypeCodeTbl hdrConversionTypeCodeTbl := hdrConversionTypeCodeTbl();
2759 l_hdrMinisiteIdTbl numberTblType := numberTblType();
2760 l_hdrBlanketNumberTbl hdrBlanketNumberTbl := hdrBlanketNumberTbl();
2761
2762 /*----------*/
2763 TYPE tblOfNumTblType IS TABLE OF numberTbl INDEX BY BINARY_INTEGER;
2764
2765 l_adjLineIdTbl numberTbl;
2766 l_uniqueHeaderIdtbl numberTbl;
2767 l_lineIdTblByHdrId tblOfNumTblType;
2768 l_lineInfoTblByLineId numberTbl;
2769 l_tempLineIdTbl numberTbl;
2770 l_adjIdByListHdrId numberTbl;
2771
2772 l_hdrCounter NUMBER;
2773 l_lineCounter NUMBER;
2774
2775 l_hdrInfoTblByHeaderId numberTbl;
2776
2777 l_tempLineIdTbl_1 numberTbl;
2778
2779 /*----------*/
2780
2781 l_offer_info c_offer_info%ROWTYPE;
2782 l_adjusted_line_cur c_adjusted_line_cur%ROWTYPE;
2783
2784 l_end_date DATE;
2785 l_type VARCHAR2(7) := NULL;
2786
2787 TYPE offerAdjustmentIdTbl IS TABLE OF ozf_offer_adjustments_b.offer_adjustment_id%TYPE;
2788 TYPE listHeaderIdTbl IS TABLE OF ozf_offer_adjustments_b.list_header_id%TYPE;
2789 TYPE effectiveDateTbl IS TABLE OF ozf_offer_adjustments_b.effective_date%TYPE;
2790 TYPE approvedDateTbl IS TABLE OF ozf_offer_adjustments_b.approved_date%TYPE;
2791
2792 l_offerAdjustmentIdTbl offerAdjustmentIdTbl;
2793 l_listHeaderIdTbl listHeaderIdTbl;
2794 l_effectiveDateTbl effectiveDateTbl;
2795 l_approvedDateTbl approvedDateTbl;
2796
2797 l_stmt_denorm VARCHAR2(32000) := NULL;
2798 l_denorm_csr NUMBER;
2799 l_ignore NUMBER;
2800 l_product_stmt VARCHAR2(32000) := NULL;
2801 l_count_temp NUMBER;
2802 l_stmt_order VARCHAR2(32000) := NULL;
2803 l_control_rec QP_PREQ_GRP.CONTROL_RECORD_TYPE;
2804 l_org_match VARCHAR2(1);
2805 l_currency_match VARCHAR2(1);
2806 l_uom_match VARCHAR2(1);
2807 l_additional_qualifier_match VARCHAR2(1);
2808 l_customer_qualified VARCHAR2(1) := 'Y';
2809 l_group NUMBER;
2810 l_group_string VARCHAR2(256);
2811 l_party_id NUMBER;
2812 l_object_type VARCHAR2(20);
2813 l_uom_ratio NUMBER;
2814 l_tbl_index NUMBER := 1;
2815 l_return_status_code varchar2(240);
2816 l_price_return_msg varchar2(240);
2817 l_volume_offer VARCHAR2(1) := 'N';
2818 l_line_tbl OZF_Adjustment_ext_PVT.LINE_REC_TBL_TYPE;
2819 k NUMBER;
2820 l_order_count NUMBER;
2821 l_price_line_flag VARCHAR2(1) := 'N';
2822 l_request_id NUMBER;
2823
2824
2825
2826 G_LINE_INDEX_tbl QP_PREQ_GRP.pls_integer_type;
2827 G_LINE_TYPE_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2828 G_PRICING_EFFECTIVE_DATE_TBL QP_PREQ_GRP.DATE_TYPE ;
2829 G_ACTIVE_DATE_FIRST_TBL QP_PREQ_GRP.DATE_TYPE ;
2830 G_ACTIVE_DATE_FIRST_TYPE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2831 G_ACTIVE_DATE_SECOND_TBL QP_PREQ_GRP.DATE_TYPE ;
2832 G_ACTIVE_DATE_SECOND_TYPE_TBL QP_PREQ_GRP.VARCHAR_TYPE ;
2833 G_LINE_QUANTITY_TBL QP_PREQ_GRP.NUMBER_TYPE ;
2834 G_LINE_UOM_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2835 G_REQUEST_TYPE_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2836 G_PRICED_QUANTITY_TBL QP_PREQ_GRP.NUMBER_TYPE;
2837 G_PRICED_UOM_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2838 G_CURRENCY_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2839 G_UNIT_PRICE_TBL QP_PREQ_GRP.NUMBER_TYPE;
2840 G_PERCENT_PRICE_TBL QP_PREQ_GRP.NUMBER_TYPE;
2841 G_UOM_QUANTITY_TBL QP_PREQ_GRP.NUMBER_TYPE;
2842 G_ADJUSTED_UNIT_PRICE_TBL QP_PREQ_GRP.NUMBER_TYPE;
2843 G_UPD_ADJUSTED_UNIT_PRICE_TBL QP_PREQ_GRP.NUMBER_TYPE;
2844 G_PROCESSED_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2845 G_PRICE_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2846
2847 --mkothari 13-dec-2006
2848 G_LIST_PRICE_OVERRIDE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2849
2850 G_LINE_ID_TBL QP_PREQ_GRP.NUMBER_TYPE;
2851 G_PROCESSING_ORDER_TBL QP_PREQ_GRP.PLS_INTEGER_TYPE;
2852 G_PRICING_STATUS_CODE_tbl QP_PREQ_GRP.VARCHAR_TYPE;
2853 G_PRICING_STATUS_TEXT_tbl QP_PREQ_GRP.VARCHAR_TYPE;
2854 G_ROUNDING_FLAG_TBL QP_PREQ_GRP.FLAG_TYPE;
2855 G_ROUNDING_FACTOR_TBL QP_PREQ_GRP.PLS_INTEGER_TYPE;
2856 G_QUALIFIERS_EXIST_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2857 G_PRICING_ATTRS_EXIST_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2858 G_PRICE_LIST_ID_TBL QP_PREQ_GRP.NUMBER_TYPE;
2859 G_PL_VALIDATED_FLAG_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2860 G_PRICE_REQUEST_CODE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2861 G_USAGE_PRICING_TYPE_TBL QP_PREQ_GRP.VARCHAR_TYPE;
2862
2863 l_failedAjustmentIdTbl numberTbl;
2864 l_header_rec order_header_csr%rowtype;
2865
2866
2867 BEGIN
2868 g_debug_flag := p_debug ;
2869 write_conc_log (' /*************************** ADJUST BD START *************************/');
2870 fnd_msg_pub.initialize;
2871 SAVEPOINT adjust_backdated_offer;
2872 --Get All Active Backdated Offer where budget adjusted flag = 'N'
2873 g_offer_id_tbl.delete;
2874 l_adjIdByListLineId.delete;
2875 l_request_id := fnd_global.conc_request_id;
2876
2877 --SSD adjustment ER, this is moved here since we want all offers to be merged.
2878 EXECUTE IMMEDIATE 'DELETE FROM ozf_adj_temp_eligibility';
2879
2880 -- perform adjustment, this will work with old table because
2881 -- commit happens after all processing
2882 --only check what happens if out of multiple errors candidate for
2883 --perform_adjustment, one errors out.
2884 --commit may be per adj for perform_adj
2885 EXECUTE IMMEDIATE 'DELETE FROM ozf_temp_eligibility';
2886 l_volume_offer := 'N';
2887
2888
2889 OPEN c_adjusted_offer_cur;
2890 LOOP
2891
2892 FETCH c_adjusted_offer_cur BULK COLLECT INTO l_offerAdjustmentIdTbl, l_listHeaderIdTbl,
2893 l_effectiveDateTbl, l_approvedDateTbl
2894 LIMIT g_bulk_limit;
2895
2896 FOR i IN NVL(l_offerAdjustmentIdTbl.FIRST, 1) .. NVL(l_offerAdjustmentIdTbl.LAST, 0) LOOP
2897
2898 SAVEPOINT new_adjustment;
2899
2900 --get the offer id
2901 OPEN c_offer_info (l_listHeaderIdTbl(i));
2902 FETCH c_offer_info INTO l_offer_info;
2903 CLOSE c_offer_info;
2904
2905
2906 write_conc_log (
2907 '/******** '
2908 || 'Begin Adjusting For Offer NAME '''
2909 || l_offer_info.description
2910 || ''' SOURCE CODE '''
2911 || l_offer_info.NAME
2912 || ''' l_offerAdjustmentIdTbl(i) : '''
2913 || l_offerAdjustmentIdTbl(i)
2914 || '''******/'
2915 );
2916
2917 /*removed code for future dated adjustments since offers team will be taking care of this.
2918 original code in version 120.19 */
2919 x_return_status :=fnd_api.g_ret_sts_success;
2920
2921 -- Perform Adjustments for the already executed offer (for the orders raised between Effective Date and Approved Date)
2922 -- Fixed 10/23/2002 mpande
2923 IF l_offer_info.offer_type <> 'VOLUME_OFFER' THEN
2924
2925
2926 write_conc_log ( l_full_name || ' : ' || 'Perform Adjustment For ' || l_listHeaderIdTbl(i));
2927
2928 perform_adjustment(p_from_date=> l_effectiveDateTbl(i)
2929 ,p_to_date=> l_approvedDateTbl(i)
2930 ,p_qp_list_header_id=> l_listHeaderIdTbl(i)
2931 ,p_offer_adjustment_id=> l_offerAdjustmentIdTbl(i)
2932 ,x_return_status=> x_return_status
2933 ,x_msg_count=> l_msg_count
2934 ,x_msg_data=> l_msg_data
2935 );
2936
2937
2938 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2939 ozf_utility_pvt.write_conc_log ('/****** '
2940 || 'Offer Adjustment Failed For Offer'
2941 || l_offer_info.description
2942 || ' SOURCE CODE '
2943 || l_offer_info.NAME
2944 || '" Offer Adjustment Id "'
2945 || l_offerAdjustmentIdTbl(i)
2946 || ' with the following Errors *******/'
2947 );
2948 ozf_utility_pvt.write_conc_log;
2949 fnd_msg_pub.initialize;
2950 ROLLBACK TO new_adjustment;
2951 GOTO l_endofloop;
2952 ELSE
2953 --should be committed per adjustment
2954 COMMIT;
2955 END IF;
2956 ELSE
2957 l_volume_offer := 'Y';
2958 g_offer_id_tbl(l_index) := l_listHeaderIdTbl(i);
2959 l_index := l_index + 1;
2960
2961 volume_offer_adjustment(p_qp_list_header_id=> l_listHeaderIdTbl(i)
2962 ,p_vol_off_type =>l_offer_info.volume_offer_type
2963 ,x_return_status=> x_return_status
2964 ,x_msg_count=> l_msg_count
2965 ,x_msg_data=> l_msg_data
2966 );
2967
2968 IF x_return_status <> fnd_api.g_ret_sts_success THEN
2969 ozf_utility_pvt.write_conc_log ('volume adjustment Failed'
2970 || l_offer_info.description
2971 || ' SOURCE CODE '
2972 || l_offer_info.NAME
2973 || '" Offer Adjustment Id "'
2974 || l_offerAdjustmentIdTbl(i)
2975 || ' with the following Errors /'
2976 );
2977 ozf_utility_pvt.write_conc_log;
2978 fnd_msg_pub.initialize;
2979 ROLLBACK TO new_adjustment;
2980 GOTO l_endofloop;
2981 END IF;
2982 END IF;
2983
2984 l_adjIdByListHdrId(l_listHeaderIdTbl(i)) := l_offerAdjustmentIdTbl(i);
2985
2986 OPEN c_adjusted_line_cur (l_offerAdjustmentIdTbl(i));
2987 LOOP
2988 FETCH c_adjusted_line_cur INTO l_adjusted_line_cur;
2989 EXIT WHEN c_adjusted_line_cur%NOTFOUND;
2990
2991 write_conc_log ( l_full_name || ' : ' || ' Begin Inserting data into temp table for AdjustmentLineId ' || l_adjusted_line_cur.offer_adjustment_line_id );
2992
2993
2994 FND_DSQL.init;
2995 FND_DSQL.add_text('INSERT INTO ozf_adj_temp_eligibility(object_type, eligibility_id, offer_adjustment_line_id) ');
2996 FND_DSQL.add_text('(SELECT ''OFFR'', product_id, ' );
2997 FND_DSQL.add_text(l_adjusted_line_cur.offer_adjustment_line_id );
2998 FND_DSQL.add_text(' FROM ( ');
2999
3000 BEGIN
3001 SAVEPOINT refresh_prod;
3002
3003 ozf_offr_elig_prod_denorm_pvt.refresh_products(p_api_version => l_api_version
3004 ,p_init_msg_list => FND_API.G_FALSE
3005 ,p_commit => FND_API.G_FALSE
3006 ,p_list_header_id => l_listHeaderIdTbl(i)
3007 ,p_calling_from_den => 'N'
3008 ,x_return_status => x_return_status
3009 ,x_msg_count => l_msg_count
3010 ,x_msg_data => l_msg_data
3011 ,x_product_stmt => l_product_stmt
3012 ,p_lline_id => l_adjusted_line_cur.to_list_line_id
3013 );
3014
3015 FND_DSQL.add_text('))');
3016
3017 write_conc_log ('l_product_stmt1: ' || l_product_stmt);
3018
3019 l_denorm_csr := DBMS_SQL.open_cursor;
3020 FND_DSQL.set_cursor(l_denorm_csr);
3021 l_stmt_denorm := FND_DSQL.get_text(FALSE);
3022 DBMS_SQL.parse(l_denorm_csr, l_stmt_denorm, DBMS_SQL.native);
3023 FND_DSQL.do_binds;
3024 l_ignore := DBMS_SQL.execute(l_denorm_csr);
3025
3026 EXCEPTION
3027 WHEN OTHERS THEN
3028 ROLLBACK TO refresh_prod;
3029 x_return_status := Fnd_Api.g_ret_sts_unexp_error;
3030 write_conc_log ('unexpected exception in refresh_products');
3031 END;
3032
3033
3034 IF l_offer_info.offer_type <> 'VOLUME_OFFER' THEN
3035 l_adjIdByListLineId(l_adjusted_line_cur.to_list_line_id) := l_offerAdjustmentIdTbl(i);
3036 END IF;
3037
3038 END LOOP;
3039 CLOSE c_adjusted_line_cur;
3040
3041
3042 <<l_endofloop>>
3043 write_conc_log( 'Return Status After Inserting data into temp table for adjustmentId' || l_offerAdjustmentIdTbl(i) || ' IS ' || x_return_status);
3044
3045 END LOOP; -- FOR i IN NVL(l_offerAdjustmentIdTbl.FIRST, 1) .. NVL(l_offerAdjustmentIdTbl.LAST, 0) LOOP
3046 EXIT WHEN c_adjusted_offer_cur%NOTFOUND;
3047 END LOOP; -- bulk fetch loop for c_adjusted_offer_cur
3048
3049 l_count_temp := 0;
3050
3051 OPEN c_count_temp;
3052 FETCH c_count_temp INTO l_count_temp;
3053 CLOSE c_count_temp;
3054
3055 IF g_debug_flag = 'Y' THEN
3056 write_conc_log( 'l_volume_offer ' || l_volume_offer);
3057 write_conc_log( 'l_count_temp ' || l_count_temp);
3058 END IF;
3059
3060
3061 IF l_count_temp >= 6 AND l_volume_offer='N' THEN
3062 OPEN c_order_header2;
3063 ELSIF l_count_temp >= 6 AND l_volume_offer='Y' THEN
3064 OPEN c_order_header4;
3065 ELSIF l_count_temp < 6 AND l_volume_offer='N' THEN
3066 OPEN c_order_header1;
3067 ELSIF l_count_temp < 6 AND l_volume_offer='Y' THEN
3068 OPEN c_order_header3;
3069 END IF;
3070
3071 LOOP --bulk fetch header_ids
3072
3073 IF l_count_temp >= 6 AND l_volume_offer='N' THEN
3074 FETCH c_order_header2 BULK COLLECT INTO l_headerIdTbl,l_lineIdTbl,l_inventoryItemIdTbl,l_unitListPriceTbl,l_unitSellingPriceTbl,
3075 l_quantityTbl,l_pricingQuantityTbl, l_invoiceToOrgIdTbl,l_soldToOrgIdTbl,
3076 l_shipToOrgIdTbl,l_lineCatCodeTbl,l_refLineIdTbl,l_orderUomTbl,
3077 l_pricingUomTbl, l_priceListIdTbl,l_pricingDateTbl,l_actualShipDateTbl,
3078 l_requestDateTbl,l_fulfillmentDateTbl,l_lineTypeIdTbl,l_endCustomerIdTbl,l_agreementIdTbl,
3079 l_custPONumberTbl,l_shipFromOrgIdTbl,l_shipmentPriorityCodeTbl,l_shippableFlagTbl,
3080 l_scheduleShipDateTbl,l_sourceTypeCodeTbl,l_orgIdTbl,l_freightTermsCodeTbl,
3081 l_paymentTermIdTbl,l_shippingMethodCodeTbl,l_itemIdentifierTypeTbl,l_orderedItemIdTbl,
3082 l_topModelLineIdTbl,l_unitPercentBasePriceTbl,l_preferredGradeTbl,l_blanketNumberTbl,
3083 l_minisiteIdTbl,l_blanketLineNumberTbl,l_transactionPhaseCodeTbl,l_chargePeriodicityCodeTbl,
3084 l_offAdjLineIdTbl,l_qpListHeaderIdTbl,l_offOrgIdTbl,l_offCurrTbl,l_prodUomTbl,l_arithOperTbl,
3085 l_listLineIdTbl, l_shippedQuantityTbl, l_invoiceInterfaceStatusTbl,
3086 l_invoicedQuantityTbl, l_shippingQuantityUomTbl,
3087 l_shippingQuantityTbl, l_shippingQuantityUom2Tbl, l_shippingQuantity2Tbl, l_fulfillmentBaseTbl -- Catch Weight ER
3088 LIMIT g_bulk_limit;
3089 ELSIF l_count_temp >= 6 AND l_volume_offer='Y' THEN
3090 FETCH c_order_header4 BULK COLLECT INTO l_headerIdTbl,l_lineIdTbl,l_inventoryItemIdTbl,l_unitListPriceTbl,l_unitSellingPriceTbl,
3091 l_quantityTbl,l_pricingQuantityTbl, l_invoiceToOrgIdTbl,l_soldToOrgIdTbl,
3092 l_shipToOrgIdTbl,l_lineCatCodeTbl,l_refLineIdTbl,l_orderUomTbl,
3093 l_pricingUomTbl, l_priceListIdTbl,l_pricingDateTbl,l_actualShipDateTbl,
3094 l_requestDateTbl,l_fulfillmentDateTbl,l_lineTypeIdTbl,l_endCustomerIdTbl,l_agreementIdTbl,
3095 l_custPONumberTbl,l_shipFromOrgIdTbl,l_shipmentPriorityCodeTbl,l_shippableFlagTbl,
3096 l_scheduleShipDateTbl,l_sourceTypeCodeTbl,l_orgIdTbl,l_freightTermsCodeTbl,
3097 l_paymentTermIdTbl,l_shippingMethodCodeTbl,l_itemIdentifierTypeTbl,l_orderedItemIdTbl,
3098 l_topModelLineIdTbl,l_unitPercentBasePriceTbl,l_preferredGradeTbl,l_blanketNumberTbl,
3099 l_minisiteIdTbl,l_blanketLineNumberTbl,l_transactionPhaseCodeTbl,l_chargePeriodicityCodeTbl,
3100 l_offAdjLineIdTbl,l_qpListHeaderIdTbl,l_offOrgIdTbl,l_offCurrTbl,l_prodUomTbl,l_arithOperTbl,
3101 l_listLineIdTbl, l_shippedQuantityTbl, l_invoiceInterfaceStatusTbl,
3102 l_invoicedQuantityTbl, l_shippingQuantityUomTbl,
3103 l_shippingQuantityTbl, l_shippingQuantityUom2Tbl, l_shippingQuantity2Tbl, l_fulfillmentBaseTbl -- Catch Weight ER
3104 LIMIT g_bulk_limit;
3105 ELSIF l_count_temp < 6 AND l_volume_offer='N' THEN
3106 FETCH c_order_header1 BULK COLLECT INTO l_headerIdTbl,l_lineIdTbl,l_inventoryItemIdTbl,l_unitListPriceTbl,l_unitSellingPriceTbl,
3107 l_quantityTbl,l_pricingQuantityTbl, l_invoiceToOrgIdTbl,l_soldToOrgIdTbl,
3108 l_shipToOrgIdTbl,l_lineCatCodeTbl,l_refLineIdTbl,l_orderUomTbl,
3109 l_pricingUomTbl, l_priceListIdTbl,l_pricingDateTbl,l_actualShipDateTbl,
3110 l_requestDateTbl,l_fulfillmentDateTbl,l_lineTypeIdTbl,l_endCustomerIdTbl,l_agreementIdTbl,
3111 l_custPONumberTbl,l_shipFromOrgIdTbl,l_shipmentPriorityCodeTbl,l_shippableFlagTbl,
3112 l_scheduleShipDateTbl,l_sourceTypeCodeTbl,l_orgIdTbl,l_freightTermsCodeTbl,
3113 l_paymentTermIdTbl,l_shippingMethodCodeTbl,l_itemIdentifierTypeTbl,l_orderedItemIdTbl,
3114 l_topModelLineIdTbl,l_unitPercentBasePriceTbl,l_preferredGradeTbl,l_blanketNumberTbl,
3115 l_minisiteIdTbl,l_blanketLineNumberTbl,l_transactionPhaseCodeTbl,l_chargePeriodicityCodeTbl,
3116 l_offAdjLineIdTbl,l_qpListHeaderIdTbl,l_offOrgIdTbl,l_offCurrTbl,l_prodUomTbl,l_arithOperTbl,
3117 l_listLineIdTbl, l_shippedQuantityTbl, l_invoiceInterfaceStatusTbl,
3118 l_invoicedQuantityTbl, l_shippingQuantityUomTbl,
3119 l_shippingQuantityTbl, l_shippingQuantityUom2Tbl, l_shippingQuantity2Tbl, l_fulfillmentBaseTbl -- Catch Weight ER
3120 LIMIT g_bulk_limit;
3121 ELSIF l_count_temp < 6 AND l_volume_offer='Y' THEN
3122 FETCH c_order_header3 BULK COLLECT INTO l_headerIdTbl,l_lineIdTbl,l_inventoryItemIdTbl,l_unitListPriceTbl,l_unitSellingPriceTbl,
3123 l_quantityTbl,l_pricingQuantityTbl, l_invoiceToOrgIdTbl,l_soldToOrgIdTbl,
3124 l_shipToOrgIdTbl,l_lineCatCodeTbl,l_refLineIdTbl,l_orderUomTbl,
3125 l_pricingUomTbl, l_priceListIdTbl,l_pricingDateTbl,l_actualShipDateTbl,
3126 l_requestDateTbl,l_fulfillmentDateTbl,l_lineTypeIdTbl,l_endCustomerIdTbl,l_agreementIdTbl,
3127 l_custPONumberTbl,l_shipFromOrgIdTbl,l_shipmentPriorityCodeTbl,l_shippableFlagTbl,
3128 l_scheduleShipDateTbl,l_sourceTypeCodeTbl,l_orgIdTbl,l_freightTermsCodeTbl,
3129 l_paymentTermIdTbl,l_shippingMethodCodeTbl,l_itemIdentifierTypeTbl,l_orderedItemIdTbl,
3130 l_topModelLineIdTbl,l_unitPercentBasePriceTbl,l_preferredGradeTbl,l_blanketNumberTbl,
3131 l_minisiteIdTbl,l_blanketLineNumberTbl,l_transactionPhaseCodeTbl,l_chargePeriodicityCodeTbl,
3132 l_offAdjLineIdTbl,l_qpListHeaderIdTbl,l_offOrgIdTbl,l_offCurrTbl,l_prodUomTbl,l_arithOperTbl,
3133 l_listLineIdTbl, l_shippedQuantityTbl, l_invoiceInterfaceStatusTbl,
3134 l_invoicedQuantityTbl, l_shippingQuantityUomTbl,
3135 l_shippingQuantityTbl, l_shippingQuantityUom2Tbl, l_shippingQuantity2Tbl, l_fulfillmentBaseTbl -- Catch Weight ER
3136 LIMIT g_bulk_limit;
3137 END IF;
3138
3139 IF l_lineIdTbl.FIRST IS NULL THEN
3140 EXIT;
3141 END IF;
3142
3143
3144 write_conc_log( 'l_uniqueHeaderIdtbl ' || l_uniqueHeaderIdtbl.COUNT);
3145 write_conc_log( 'l_lineInfoTblByLineId ' || l_lineInfoTblByLineId.COUNT);
3146 write_conc_log( 'l_lineIdTblByHdrId ' || l_lineIdTblByHdrId.COUNT);
3147 write_conc_log( 'l_tempLineIdTbl ' || l_tempLineIdTbl.COUNT);
3148 write_conc_log( 'l_hdrInfoTblByHeaderId ' || l_hdrInfoTblByHeaderId.COUNT);
3149
3150 IF l_uniqueHeaderIdtbl.COUNT > 0 THEN
3151 l_uniqueHeaderIdtbl.DELETE;
3152 END IF;
3153
3154 IF l_lineInfoTblByLineId.COUNT > 0 THEN
3155 l_lineInfoTblByLineId.DELETE;
3156 END IF;
3157
3158 IF l_lineIdTblByHdrId.COUNT > 0 THEN
3159 l_lineIdTblByHdrId.DELETE;
3160 END IF;
3161
3162 IF l_tempLineIdTbl.COUNT > 0 THEN
3163 l_tempLineIdTbl.DELETE;
3164 END IF;
3165
3166 IF l_hdrInfoTblByHeaderId.COUNT > 0 THEN
3167 l_hdrInfoTblByHeaderId.DELETE;
3168 END IF;
3169
3170 l_hdrCounter := 1;
3171
3172 write_conc_log( 'No: Of Orders ' || l_lineIdTbl.COUNT);
3173
3174 IF l_hdrOrgIdTbl.EXISTS(1) THEN l_hdrOrgIdTbl.DELETE; END IF;
3175 IF l_orderCurrTbl.EXISTS(1) THEN l_orderCurrTbl.DELETE; END IF;
3176 IF l_orderTypeIdTbl.EXISTS(1) THEN l_orderTypeIdTbl.DELETE; END IF;
3177 IF l_hdrSoldToOrgIdTbl.EXISTS(1) THEN l_hdrSoldToOrgIdTbl.DELETE; END IF;
3178 IF l_hdrInvoiceToOrgIdTbl.EXISTS(1) THEN l_hdrInvoiceToOrgIdTbl.DELETE; END IF;
3179 IF l_hdrShipToOrgIdTbl.EXISTS(1) THEN l_hdrShipToOrgIdTbl.DELETE; END IF;
3180 IF l_hdrPriceListIdTbl.EXISTS(1) THEN l_hdrPriceListIdTbl.DELETE; END IF;
3181 IF l_hdrOrderedDateTbl.EXISTS(1) THEN l_hdrOrderedDateTbl.DELETE; END IF;
3182 IF l_hdrRequestDateTbl.EXISTS(1) THEN l_hdrRequestDateTbl.DELETE; END IF;
3183 IF l_hdrPricingDateTbl.EXISTS(1) THEN l_hdrPricingDateTbl.DELETE; END IF;
3184 IF l_hdrAgreementIdTbl.EXISTS(1) THEN l_hdrAgreementIdTbl.DELETE; END IF;
3185 IF l_hdrCustPONumberTbl.EXISTS(1) THEN l_hdrCustPONumberTbl.DELETE; END IF;
3186 IF l_hdrShipFromOrgIdTbl.EXISTS(1) THEN l_hdrShipFromOrgIdTbl.DELETE; END IF;
3187 IF l_hdrOrderCategoryCodeTbl.EXISTS(1) THEN l_hdrOrderCategoryCodeTbl.DELETE; END IF;
3188 IF l_hdrShipmentPriorityCodeTbl.EXISTS(1) THEN l_hdrShipmentPriorityCodeTbl.DELETE; END IF;
3189 IF l_hdrFreightTermsCodeTbl.EXISTS(1) THEN l_hdrFreightTermsCodeTbl.DELETE; END IF;
3190 IF l_hdrPaymentTermIdTbl.EXISTS(1) THEN l_hdrPaymentTermIdTbl.DELETE; END IF;
3191 IF l_hdrShippingMethodCodeTbl.EXISTS(1) THEN l_hdrShippingMethodCodeTbl.DELETE; END IF;
3192 IF l_hdrConversionRateDateTbl.EXISTS(1) THEN l_hdrConversionRateDateTbl.DELETE; END IF;
3193 IF l_hdrConversionRateTbl.EXISTS(1) THEN l_hdrConversionRateTbl.DELETE; END IF;
3194 IF l_hdrConversionTypeCodeTbl.EXISTS(1) THEN l_hdrConversionTypeCodeTbl.DELETE; END IF;
3195 IF l_hdrMinisiteIdTbl.EXISTS(1) THEN l_hdrMinisiteIdTbl.DELETE; END IF;
3196 IF l_hdrBlanketNumberTbl.EXISTS(1) THEN l_hdrBlanketNumberTbl.DELETE; END IF;
3197
3198 FOR j IN l_headerIdTbl.FIRST .. l_headerIdTbl.LAST
3199 LOOP
3200 write_conc_log( 'l_headerId ' || l_headerIdTbl(j) );
3201
3202 IF l_lineIdTblByHdrId.EXISTS(l_headerIdTbl(j)) = FALSE THEN
3203
3204 l_uniqueHeaderIdtbl(l_hdrCounter) := l_headerIdTbl(j);
3205 l_hdrInfoTblByHeaderId(l_headerIdTbl(j)) := l_hdrCounter;
3206
3207 write_conc_log( 'l_headerId IF' || l_hdrCounter);
3208
3209 l_hdrOrgIdTbl.EXTEND(1);
3210 l_orderCurrTbl.EXTEND(1);
3211 l_orderTypeIdTbl.EXTEND(1);
3212 l_hdrSoldToOrgIdTbl.EXTEND(1);
3213 l_hdrInvoiceToOrgIdTbl.EXTEND(1);
3214 l_hdrShipToOrgIdTbl.EXTEND(1);
3215 l_hdrPriceListIdTbl.EXTEND(1);
3216 l_hdrOrderedDateTbl.EXTEND(1);
3217 l_hdrRequestDateTbl.EXTEND(1);
3218 l_hdrPricingDateTbl.EXTEND(1);
3219 l_hdrAgreementIdTbl.EXTEND(1);
3220 l_hdrCustPONumberTbl.EXTEND(1);
3221 l_hdrShipFromOrgIdTbl.EXTEND(1);
3222 l_hdrOrderCategoryCodeTbl.EXTEND(1);
3223 l_hdrShipmentPriorityCodeTbl.EXTEND(1);
3224 l_hdrFreightTermsCodeTbl.EXTEND(1);
3225 l_hdrPaymentTermIdTbl.EXTEND(1);
3226 l_hdrShippingMethodCodeTbl.EXTEND(1);
3227 l_hdrConversionRateDateTbl.EXTEND(1);
3228 l_hdrConversionRateTbl.EXTEND(1);
3229 l_hdrConversionTypeCodeTbl.EXTEND(1);
3230 l_hdrMinisiteIdTbl.EXTEND(1);
3231 l_hdrBlanketNumberTbl.EXTEND(1);
3232
3233 -- get order_header_rec
3234 OPEN order_header_csr(l_headerIdTbl(j));
3235 FETCH order_header_csr INTO l_hdrOrgIdTbl(l_hdrCounter),l_orderCurrTbl(l_hdrCounter),
3236 l_orderTypeIdTbl(l_hdrCounter), l_hdrSoldToOrgIdTbl(l_hdrCounter),
3237 l_hdrInvoiceToOrgIdTbl(l_hdrCounter), l_hdrShipToOrgIdTbl(l_hdrCounter),
3238 l_hdrPriceListIdTbl(l_hdrCounter), l_hdrOrderedDateTbl(l_hdrCounter),
3239 l_hdrRequestDateTbl(l_hdrCounter), l_hdrPricingDateTbl(l_hdrCounter),
3240 l_hdrAgreementIdTbl(l_hdrCounter), l_hdrCustPONumberTbl(l_hdrCounter),
3241 l_hdrShipFromOrgIdTbl(l_hdrCounter), l_hdrOrderCategoryCodeTbl(l_hdrCounter),
3242 l_hdrShipmentPriorityCodeTbl(l_hdrCounter), l_hdrFreightTermsCodeTbl(l_hdrCounter),
3243 l_hdrPaymentTermIdTbl(l_hdrCounter), l_hdrShippingMethodCodeTbl(l_hdrCounter),
3244 l_hdrConversionRateDateTbl(l_hdrCounter), l_hdrConversionRateTbl(l_hdrCounter),
3245 l_hdrConversionTypeCodeTbl(l_hdrCounter), l_hdrMinisiteIdTbl(l_hdrCounter),
3246 l_hdrBlanketNumberTbl(l_hdrCounter);
3247 CLOSE order_header_csr;
3248
3249 l_hdrCounter := l_uniqueHeaderIdtbl.COUNT + 1;
3250
3251 write_conc_log( 'l_headerId IF END' );
3252 END IF;
3253
3254
3255
3256 IF g_debug_flag = 'Y' THEN
3257 write_conc_log( 'J ' || j);
3258 write_conc_log( 'Invoice To Org Id: ' || l_invoiceToOrgIdTbl(j));
3259 write_conc_log( 'Ship To Org Id: ' || l_shipToOrgIdTbl(j));
3260 write_conc_log( 'Sold To Org Id: ' || l_soldToOrgIdTbl(j));
3261 write_conc_log( 'Party Id: ' || l_party_id);
3262 write_conc_log( 'List Header Id: ' || l_qpListHeaderIdTbl(j));
3263 write_conc_log ('Offer UOM: ' || l_prodUomTbl(j));
3264 write_conc_log ('Order UOM: ' || l_orderUomTbl(j));
3265 write_conc_log ('Pricing UOM: ' || l_pricingUomTbl(j));
3266 write_conc_log ('arithmetic_operator ' || l_arithOperTbl(j));
3267 write_conc_log( 'l_offOrgIdTbl(j) ' || l_offOrgIdTbl(j));
3268 write_conc_log( 'l_headerIdTbl(j) ' || l_headerIdTbl(j));
3269 write_conc_log( 'l_offCurrTbl(j) ' || l_offCurrTbl(j));
3270 write_conc_log( 'l_hdrInfoTblByHeaderId(l_headerIdTbl(j)) ' || l_hdrInfoTblByHeaderId(l_headerIdTbl(j)));
3271 write_conc_log( 'l_hdrOrgIdTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))) ' || l_hdrOrgIdTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))));
3272 write_conc_log( 'l_orderCurrTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))) ' || l_orderCurrTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))));
3273 END IF;
3274
3275 l_org_match := 'Y';
3276 IF l_offOrgIdTbl(j) IS NOT NULL AND l_offOrgIdTbl(j) <> l_hdrOrgIdTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))) THEN
3277 l_org_match := 'N';
3278 END IF;
3279
3280 IF g_debug_flag = 'Y' THEN
3281 write_conc_log ('l_org_match: ' || l_org_match);
3282 END IF;
3283
3284 l_currency_match := 'Y';
3285 IF l_offCurrTbl(j) IS NOT NULL AND l_offCurrTbl(j) <> l_orderCurrTbl(l_hdrInfoTblByHeaderId(l_headerIdTbl(j))) THEN
3286 l_currency_match := 'N';
3287 END IF;
3288
3289 IF g_debug_flag = 'Y' THEN
3290 write_conc_log ('l_currency_match: ' || l_currency_match);
3291 END IF;
3292
3293 IF l_org_match = 'Y' AND l_currency_match = 'Y' THEN
3294
3295 OPEN c_party_id (l_soldToOrgIdTbl(j));
3296 FETCH c_party_id INTO l_party_id;
3297 CLOSE c_party_id;
3298
3299 l_customer_qualified := 'N';
3300 l_group := NULL;
3301 l_group_string := NULL;
3302
3303 IF g_debug_flag = 'Y' THEN
3304 write_conc_log ('l_party_id ' || l_party_id);
3305 END IF;
3306
3307 IF l_invoiceToOrgIdTbl(j) IS NULL AND l_shipToOrgIdTbl(j) IS NULL THEN
3308 OPEN c_cust_acct_qualified(l_soldToOrgIdTbl(j), l_party_id, l_qpListHeaderIdTbl(j));
3309 FETCH c_cust_acct_qualified INTO l_customer_qualified, l_object_type, l_group;
3310
3311 IF l_object_type = 'VOLUME_OFFER' AND l_group IS NOT NULL THEN
3312 l_group_string := l_group_string || ',' || l_group;
3313 END IF;
3314
3315 CLOSE c_cust_acct_qualified;
3316 ELSE
3317 OPEN c_customer_qualified(l_soldToOrgIdTbl(j), l_shipToOrgIdTbl(j), l_party_id, l_qpListHeaderIdTbl(j));
3318 FETCH c_customer_qualified INTO l_customer_qualified, l_object_type, l_group;
3319 IF l_object_type = 'VOLUME_OFFER' AND l_group IS NOT NULL THEN
3320 l_group_string := l_group_string || ',' || l_group;
3321 END IF;
3322 CLOSE c_customer_qualified;
3323 END IF;
3324
3325 IF l_group_string IS NOT NULL THEN
3326 l_group_nos(j) := substr(l_group_string,2); --remove first comma
3327 END IF;
3328
3329 END IF; --end of IF l_org_match = 'Y' AND l_currency_match = 'Y' THEN
3330
3331 IF g_debug_flag = 'Y' THEN
3332 write_conc_log ('l_object_type ' || l_object_type);
3333 write_conc_log ('l_group ' || l_group);
3334 write_conc_log ('l_customer_qualified ' || l_customer_qualified);
3335 write_conc_log ('l_inventoryItemIdTbl(j) ' || l_inventoryItemIdTbl(j));
3336 END IF;
3337
3338
3339 l_uom_match := 'Y';
3340 --Offers will no UOM will pick all Orders irrespective of Order UOM.
3341 --Offers with UOMs will pick up Orders with same Pricing UOMs.
3342 IF (l_prodUomTbl(j) IS NOT NULL) AND (l_prodUomTbl(j) <> l_pricingUomTbl(j)) THEN
3343 l_uom_match := 'N';
3344 ELSE
3345
3346 --UOM conversion is only valid for Amount and New Price discount and not for Percent and Lumpsum discounts
3347 IF (NVL(l_prodUomTbl(j),l_pricingUomTbl(j)) <> l_orderUomTbl(j)) AND (l_arithOperTbl(j) IN ('AMT', 'NEWPRICE')) THEN
3348
3349 l_uom_ratio := inv_convert.inv_um_convert(l_inventoryItemIdTbl(j)
3350 ,NULL
3351 ,1
3352 ,l_orderUomTbl(j)
3353 ,NVL(l_prodUomTbl(j),l_pricingUomTbl(j))
3354 ,NULL
3355 ,NULL
3356 );
3357
3358 IF (l_uom_ratio = -99999) THEN
3359 write_conc_log ('Error in UOM conversion');
3360 l_uom_match := 'N';
3361 END IF;
3362
3363 ELSE
3364 l_uom_ratio := 1;
3365 END IF;
3366
3367 write_conc_log ('UOM Ratio: ' || l_uom_ratio);
3368
3369 END IF;
3370
3371 l_additional_qualifier_match := 'Y';
3372 l_additional_qualifier_match := OZF_QP_QUAL_PVT.get_additional_qualifiers (l_headerIdTbl(j),
3373 l_lineIdTbl(j),
3374 l_qpListHeaderIdTbl(j),
3375 l_listLineIdTbl(j));
3376
3377 IF g_debug_flag = 'Y' THEN
3378 write_conc_log ('l_org_match ' || l_org_match);
3379 write_conc_log ('l_currency_match ' || l_currency_match);
3380 write_conc_log ('l_customer_qualified: ' || l_customer_qualified);
3381 write_conc_log ('l_uom_match: ' || l_uom_match);
3382 write_conc_log ('l_additional_qualifier_match: ' || l_additional_qualifier_match);
3383 END IF;
3384
3385 l_price_line_flag := 'N';
3386
3387 --filter orders based on 5 qualifiers
3388 IF l_customer_qualified = 'Y' AND l_org_match = 'Y' AND l_currency_match = 'Y'
3389 AND l_uom_match = 'Y' AND 'Y' = l_additional_qualifier_match THEN
3390
3391 -- If the order line qualifies for even one offer, it has to be send to pricing
3392 -- set l_price_line_flag as Yes.
3393 -- this will ensure that each line is send to pricing only once even if
3394 -- it qualifies for multiple offers.
3395
3396 l_price_line_flag := 'Y';
3397
3398 IF g_debug_flag = 'Y' THEN
3399 write_conc_log ('offer_org_id: ' || l_offOrgIdTbl(j));
3400 write_conc_log ('offer_currency ' || l_offCurrTbl(j));
3401 END IF;
3402
3403 END IF;
3404
3405 write_conc_log ('l_price_line_flag ' || l_price_line_flag);
3406
3407 IF l_lineIdTblByHdrId.EXISTS(l_headerIdTbl(j))
3408 AND l_lineInfoTblByLineId.EXISTS(l_lineIdTbl(j)) = FALSE
3409 AND 'Y' = l_price_line_flag THEN
3410
3411 l_tempLineIdTbl := l_lineIdTblByHdrId(l_headerIdTbl(j));
3412 l_tempLineIdTbl(l_tempLineIdTbl.COUNT + 1) := l_lineIdTbl(j);
3413 l_lineIdTblByHdrId(l_headerIdTbl(j)) := l_tempLineIdTbl;
3414 l_lineInfoTblByLineId(l_lineIdTbl(j)) := j;
3415
3416 write_conc_log( 'IF ' || l_lineIdTbl(j) );
3417
3418 ELSIF l_lineIdTblByHdrId.EXISTS(l_headerIdTbl(j)) = FALSE THEN
3419 IF 'Y' = l_price_line_flag THEN
3420 l_tempLineIdTbl.DELETE;
3421
3422 l_tempLineIdTbl(l_tempLineIdTbl.COUNT + 1) := l_lineIdTbl(j);
3423 l_lineIdTblByHdrId(l_headerIdTbl(j)) := l_tempLineIdTbl;
3424 l_lineInfoTblByLineId(l_lineIdTbl(j)) := j;
3425
3426 write_conc_log( 'ELSE ' || l_lineIdTbl(j) );
3427
3428 END IF;
3429 END IF;
3430 END LOOP; --end of l_headerIdTbl loop */
3431
3432
3433 IF g_debug_flag = 'Y' THEN
3434 write_conc_log( 'l_uniqueHeaderIdtbl COUNT: ' || l_uniqueHeaderIdtbl.COUNT);
3435 END IF;
3436
3437
3438 -- build the control record for pricing call. This will be same for all order headers
3439 l_control_rec.pricing_event := 'BATCH';
3440 l_control_rec.calculate_flag := 'Y';
3441 l_control_rec.simulation_flag := 'Y';
3442 l_control_rec.source_order_amount_flag := 'Y';
3443 l_control_rec.gsa_check_flag := 'N';
3444 l_control_rec.gsa_dup_check_flag := 'N';
3445 l_control_rec.temp_table_insert_flag := 'N';
3446 l_control_rec.request_type_code := 'ONT';
3447 l_control_rec.rounding_flag := 'Q';
3448
3449 FOR P IN l_uniqueHeaderIdtbl.FIRST .. l_uniqueHeaderIdtbl.LAST
3450 LOOP
3451 IF g_debug_flag = 'Y' THEN
3452 write_conc_log( 'Print header Id');
3453 write_conc_log( 'HeaderId[' || P || ']' || l_uniqueHeaderIdtbl(P));
3454 END IF;
3455 IF l_lineIdTblByHdrId.EXISTS(l_uniqueHeaderIdtbl(P)) THEN
3456
3457 IF g_debug_flag = 'Y' THEN
3458 write_conc_log( 'l_lineTbl_1 COUNT: ' || l_lineIdTblByHdrId(l_uniqueHeaderIdtbl(P)).COUNT);
3459 END IF;
3460
3461 l_tbl_index := 1;
3462
3463 l_tempLineIdTbl_1 := l_lineIdTblByHdrId(l_uniqueHeaderIdtbl(P));
3464
3465 IF l_tempLineIdTbl_1.EXISTS(1) = FALSE THEN
3466 --suppose none of the lines qualified for any offer then skip all processing
3467 GOTO LABEL_FOR_NEXT_ITERATION;
3468 END IF;
3469
3470 IF l_line_tbl.EXISTS(1) THEN l_line_tbl.DELETE; END IF;
3471
3472 IF G_LINE_INDEX_tbl.EXISTS(1) THEN G_LINE_INDEX_tbl.DELETE; END IF;
3473 IF G_LINE_TYPE_CODE_TBL.EXISTS(1) THEN G_LINE_TYPE_CODE_TBL.DELETE; END IF;
3474 IF G_PRICING_EFFECTIVE_DATE_TBL.EXISTS(1) THEN G_PRICING_EFFECTIVE_DATE_TBL.DELETE; END IF;
3475 IF G_ACTIVE_DATE_FIRST_TBL.EXISTS(1) THEN G_ACTIVE_DATE_FIRST_TBL.DELETE; END IF;
3476 IF G_ACTIVE_DATE_FIRST_TYPE_TBL.EXISTS(1) THEN G_ACTIVE_DATE_FIRST_TYPE_TBL.DELETE; END IF;
3477 IF G_ACTIVE_DATE_SECOND_TBL.EXISTS(1) THEN G_ACTIVE_DATE_SECOND_TBL.DELETE; END IF;
3478 IF G_ACTIVE_DATE_SECOND_TYPE_TBL.EXISTS(1) THEN G_ACTIVE_DATE_SECOND_TYPE_TBL.DELETE; END IF;
3479 IF G_LINE_QUANTITY_TBL.EXISTS(1) THEN G_LINE_QUANTITY_TBL.DELETE; END IF;
3480 IF G_LINE_UOM_CODE_TBL.EXISTS(1) THEN G_LINE_UOM_CODE_TBL.DELETE; END IF;
3481 IF G_REQUEST_TYPE_CODE_TBL.EXISTS(1) THEN G_REQUEST_TYPE_CODE_TBL.DELETE; END IF;
3482 IF G_PRICED_QUANTITY_TBL.EXISTS(1) THEN G_PRICED_QUANTITY_TBL.DELETE; END IF;
3483 IF G_PRICED_UOM_CODE_TBL.EXISTS(1) THEN G_PRICED_UOM_CODE_TBL.DELETE; END IF;
3484 IF G_CURRENCY_CODE_TBL.EXISTS(1) THEN G_CURRENCY_CODE_TBL.DELETE; END IF;
3485 IF G_UNIT_PRICE_TBL.EXISTS(1) THEN G_UNIT_PRICE_TBL.DELETE; END IF;
3486 IF G_PERCENT_PRICE_TBL.EXISTS(1) THEN G_PERCENT_PRICE_TBL.DELETE; END IF;
3487 IF G_UOM_QUANTITY_TBL.EXISTS(1) THEN G_UOM_QUANTITY_TBL.DELETE; END IF;
3488 IF G_ADJUSTED_UNIT_PRICE_TBL.EXISTS(1) THEN G_ADJUSTED_UNIT_PRICE_TBL.DELETE; END IF;
3489 IF G_UPD_ADJUSTED_UNIT_PRICE_TBL.EXISTS(1) THEN G_UPD_ADJUSTED_UNIT_PRICE_TBL.DELETE; END IF;
3490 IF G_PROCESSED_FLAG_TBL.EXISTS(1) THEN G_PROCESSED_FLAG_TBL.DELETE; END IF;
3491 IF G_PRICE_FLAG_TBL.EXISTS(1) THEN G_PRICE_FLAG_TBL.DELETE; END IF;
3492 IF G_LIST_PRICE_OVERRIDE_TBL.EXISTS(1) THEN G_LIST_PRICE_OVERRIDE_TBL.DELETE; END IF;
3493 IF G_LINE_ID_TBL.EXISTS(1) THEN G_LINE_ID_TBL.DELETE; END IF;
3494 IF G_PROCESSING_ORDER_TBL.EXISTS(1) THEN G_PROCESSING_ORDER_TBL.DELETE; END IF;
3495 IF G_PRICING_STATUS_CODE_tbl.EXISTS(1) THEN G_PRICING_STATUS_CODE_tbl.DELETE; END IF;
3496 IF G_PRICING_STATUS_TEXT_tbl.EXISTS(1) THEN G_PRICING_STATUS_TEXT_tbl.DELETE; END IF;
3497 IF G_ROUNDING_FLAG_TBL.EXISTS(1) THEN G_ROUNDING_FLAG_TBL.DELETE; END IF;
3498 IF G_ROUNDING_FACTOR_TBL.EXISTS(1) THEN G_ROUNDING_FACTOR_TBL.DELETE; END IF;
3499 IF G_QUALIFIERS_EXIST_FLAG_TBL.EXISTS(1) THEN G_QUALIFIERS_EXIST_FLAG_TBL.DELETE; END IF;
3500 IF G_PRICING_ATTRS_EXIST_FLAG_TBL.EXISTS(1) THEN G_PRICING_ATTRS_EXIST_FLAG_TBL.DELETE; END IF;
3501 IF G_PRICE_LIST_ID_TBL.EXISTS(1) THEN G_PRICE_LIST_ID_TBL.DELETE; END IF;
3502 IF G_PL_VALIDATED_FLAG_TBL.EXISTS(1) THEN G_PL_VALIDATED_FLAG_TBL.DELETE; END IF;
3503 IF G_PRICE_REQUEST_CODE_TBL.EXISTS(1) THEN G_PRICE_REQUEST_CODE_TBL.DELETE; END IF;
3504 IF G_USAGE_PRICING_TYPE_TBL.EXISTS(1) THEN G_USAGE_PRICING_TYPE_TBL.DELETE; END IF;
3505
3506 --build header
3507 oe_order_pub.g_hdr.header_id := l_uniqueHeaderIdtbl(P);
3508 oe_order_pub.g_hdr.order_type_id := l_orderTypeIdTbl(P);
3509 oe_order_pub.g_hdr.sold_to_org_id := l_hdrSoldToOrgIdTbl(P);
3510 oe_order_pub.g_hdr.invoice_to_org_id := l_hdrInvoiceToOrgIdTbl(P);
3511 oe_order_pub.g_hdr.ship_to_org_id := l_hdrShipToOrgIdTbl(P);
3512 oe_order_pub.g_hdr.price_list_id := l_hdrPriceListIdTbl(P);
3513 oe_order_pub.g_hdr.ordered_date := l_hdrOrderedDateTbl(P); --check if ordered_date exists in oe header table
3514 oe_order_pub.g_hdr.request_date := l_hdrRequestDateTbl(P); --check if ordered_date exists in oe header table
3515 oe_order_pub.g_hdr.pricing_date := l_hdrPricingDateTbl(P);
3516
3517 oe_order_pub.g_hdr.agreement_id := l_hdrAgreementIdTbl(P);
3518 oe_order_pub.g_hdr.cust_po_number := l_hdrCustPONumberTbl(P);
3519 oe_order_pub.g_hdr.ship_from_org_id := l_hdrShipFromOrgIdTbl(P);
3520 oe_order_pub.g_hdr.order_category_code := l_hdrOrderCategoryCodeTbl(P);
3521 oe_order_pub.g_hdr.shipment_priority_code := l_hdrShipmentPriorityCodeTbl(P);
3522 oe_order_pub.g_hdr.freight_terms_code := l_hdrFreightTermsCodeTbl(P);
3523 oe_order_pub.g_hdr.payment_term_id := l_hdrPaymentTermIdTbl(P);
3524 oe_order_pub.g_hdr.shipping_method_code := l_hdrShippingMethodCodeTbl(P);
3525 -- fix for bug 13579540 l_hdrShippingMethodCodeTbl (varchar2(30) was being assigned
3526 -- to transactional_curr_code varchar2(15) causing ORA-06502: PL/SQL: numeric or value error
3527 oe_order_pub.g_hdr.transactional_curr_code := l_orderCurrTbl(P);
3528 -- end of fix for bug 13579540
3529 oe_order_pub.g_hdr.org_id := l_hdrOrgIdTbl(P);
3530 oe_order_pub.g_hdr.conversion_rate_date := l_hdrConversionRateDateTbl(P);
3531 oe_order_pub.g_hdr.conversion_rate := l_hdrConversionRateTbl(P);
3532 oe_order_pub.g_hdr.conversion_type_code := l_hdrConversionTypeCodeTbl(P);
3533 oe_order_pub.g_hdr.minisite_id := l_hdrMinisiteIdTbl(P);
3534 oe_order_pub.g_hdr.BLANKET_NUMBER := l_hdrBlanketNumberTbl(P);
3535
3536 G_LINE_INDEX_TBL(l_tbl_index) := l_tbl_index;
3537 G_LINE_TYPE_CODE_TBL(l_tbl_index):= OZF_ORDER_PRICE_PVT.G_ORDER_HEADER_TYPE;
3538 G_PRICING_EFFECTIVE_DATE_TBL(l_tbl_index):= l_hdrPricingDateTbl(P);
3539 G_ACTIVE_DATE_FIRST_TBL(l_tbl_index):= l_hdrOrderedDateTbl(P);
3540 G_ACTIVE_DATE_FIRST_TYPE_TBL(l_tbl_index):= 'ORD';
3541 G_ACTIVE_DATE_SECOND_TBL(l_tbl_index):= l_hdrOrderedDateTbl(P);
3542 G_ACTIVE_DATE_SECOND_TYPE_TBL(l_tbl_index) := 'ORD';
3543 G_LINE_QUANTITY_TBL(l_tbl_index):= null;
3544 G_LINE_UOM_CODE_TBL(l_tbl_index):= null;
3545 G_REQUEST_TYPE_CODE_TBL(l_tbl_index):= 'ONT';
3546 G_PRICED_QUANTITY_TBL(l_tbl_index):= null; --l_order_line_rec.pricing_quantity;
3547 G_PRICED_UOM_CODE_TBL(l_tbl_index):= null; --l_order_line_rec.pricing_quantity_uom;
3548 G_CURRENCY_CODE_TBL(l_tbl_index):= l_orderCurrTbl(P);
3549 G_UNIT_PRICE_TBL(l_tbl_index):= null; --l_order_line_rec.unit_selling_price;
3550 G_PERCENT_PRICE_TBL(l_tbl_index):= null;
3551 G_UOM_QUANTITY_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).UOM_QUANTITY;
3552 G_ADJUSTED_UNIT_PRICE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ADJUSTED_UNIT_PRICE;
3553 G_UPD_ADJUSTED_UNIT_PRICE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).UPD_ADJUSTED_UNIT_PRICE;
3554 G_PROCESSED_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PROCESSED_FLAG;
3555 G_PRICE_FLAG_TBL(l_tbl_index):= 'Y';
3556 G_LIST_PRICE_OVERRIDE_TBL(l_tbl_index):= 'Y';
3557 G_LINE_ID_TBL(l_tbl_index):= null;
3558 G_PROCESSING_ORDER_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PROCESSING_ORDER;
3559 G_PRICING_STATUS_CODE_tbl(l_tbl_index):= QP_PREQ_GRP.G_STATUS_UNCHANGED;
3560 G_PRICE_LIST_ID_TBL(l_tbl_index):= l_hdrPriceListIdTbl(P);
3561 G_PRICING_STATUS_TEXT_tbl(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PRICING_STATUS_TEXT;
3562 G_ROUNDING_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ROUNDING_FLAG;
3563 G_ROUNDING_FACTOR_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ROUNDING_FACTOR;
3564 G_QUALIFIERS_EXIST_FLAG_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).QUALIFIERS_EXIST_FLAG;
3565 G_PRICING_ATTRS_EXIST_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PRICING_ATTRS_EXIST_FLAG;
3566 G_PL_VALIDATED_FLAG_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PL_VALIDATED_FLAG;
3567 G_PRICE_REQUEST_CODE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PRICE_REQUEST_CODE;
3568 G_USAGE_PRICING_TYPE_tbl(l_tbl_index):= null; --l_line_tbl(l_tbl_index).USAGE_PRICING_TYPE;
3569
3570 -- build summary line to be used when processing pricing results.
3571
3572 l_line_tbl(l_tbl_index).line_index := l_tbl_index;
3573 l_line_tbl(l_tbl_index).line_id := NULL;
3574 l_line_tbl(l_tbl_index).line_type_code := OZF_ORDER_PRICE_PVT.G_ORDER_HEADER_TYPE;
3575 l_line_tbl(l_tbl_index).pricing_effective_date := l_hdrPricingDateTbl(P);
3576 l_line_tbl(l_tbl_index).active_date_first := l_hdrOrderedDateTbl(P);
3577 l_line_tbl(l_tbl_index).active_date_first_type := 'ORD'; -- Change because of ONT QP order 'NO TYPE';
3578 l_line_tbl(l_tbl_index).active_date_second := l_hdrOrderedDateTbl(P);
3579 l_line_tbl(l_tbl_index).active_date_second_type := 'ORD'; -- change because of ONT QP order 'NO TYPE';
3580 l_line_tbl(l_tbl_index).request_type_code := 'ONT';
3581 l_line_tbl(l_tbl_index).currency_code := l_orderCurrTbl(P);
3582 l_line_tbl(l_tbl_index).transactional_curr_code := l_orderCurrTbl(P); -- nepanda : Fix for bug # 14521452
3583 l_line_tbl(l_tbl_index).price_list_id := l_hdrPriceListIdTbl(P);
3584 l_line_tbl(l_tbl_index).price_flag := 'Y';
3585 l_line_tbl(l_tbl_index).header_id := l_uniqueHeaderIdtbl(P);
3586 l_line_tbl(l_tbl_index).org_id := l_hdrOrgIdTbl(P);
3587
3588 --Not needed for this flow
3589 --l_line_tbl(k).list_price_override_flag := l_list_price_override_flag;
3590 l_line_tbl(l_tbl_index).pricing_status_code := QP_PREQ_GRP.G_STATUS_UNCHANGED;
3591
3592
3593 QP_Attr_Mapping_PUB.Build_Contexts(
3594 p_request_type_code => 'ONT',
3595 p_line_index => l_tbl_index,
3596 p_pricing_type_code =>'H'
3597 );
3598
3599
3600
3601 FOR Q IN l_tempLineIdTbl_1.FIRST .. l_tempLineIdTbl_1.LAST
3602 LOOP
3603 IF g_debug_flag = 'Y' THEN
3604 write_conc_log( 'l_lineTbl[' || Q || ']' || l_tempLineIdTbl_1(Q));
3605 END IF;
3606
3607 l_tbl_index := l_tbl_index + 1;
3608
3609 IF g_debug_flag = 'Y' THEN
3610 write_conc_log( 'l_tbl_index' || l_tbl_index);
3611 END IF;
3612
3613 l_lineCounter := l_lineInfoTblByLineId(l_tempLineIdTbl_1(Q));
3614
3615 IF g_debug_flag = 'Y' THEN
3616 write_conc_log( 'l_lineCounter' || l_lineCounter);
3617 END IF;
3618
3619 oe_order_pub.g_line.line_id := l_lineIdTbl(l_lineCounter);
3620 oe_order_pub.g_line.line_type_id := l_lineTypeIdTbl(l_lineCounter);
3621 oe_order_pub.g_line.inventory_item_id := l_inventoryItemIdTbl(l_lineCounter);
3622 oe_order_pub.g_line.ordered_quantity := l_quantityTbl(l_lineCounter);
3623 oe_order_pub.g_line.order_quantity_uom := l_orderUomTbl(l_lineCounter);
3624 oe_order_pub.g_line.invoice_to_org_id := l_invoiceToOrgIdTbl(l_lineCounter);
3625 oe_order_pub.g_line.ship_to_org_id := l_shipToOrgIdTbl(l_lineCounter);
3626 oe_order_pub.g_line.sold_to_org_id := l_soldToOrgIdTbl(l_lineCounter);
3627 oe_order_pub.g_line.price_list_id := l_priceListIdTbl(l_lineCounter);
3628 oe_order_pub.g_line.request_date := l_requestDateTbl(l_lineCounter);
3629 oe_order_pub.g_line.actual_shipment_date := l_actualShipDateTbl(l_lineCounter);
3630 oe_order_pub.g_line.pricing_date := l_pricingDateTbl(l_lineCounter);
3631
3632
3633 oe_order_pub.g_line.header_id := l_uniqueHeaderIdtbl(P);
3634 oe_order_pub.g_line.end_customer_id := l_endCustomerIdTbl(l_lineCounter);
3635 oe_order_pub.g_line.agreement_id := l_agreementIdTbl(l_lineCounter);
3636 oe_order_pub.g_line.cust_po_number := l_custPONumberTbl(l_lineCounter);
3637 oe_order_pub.g_line.ship_from_org_id := l_shipFromOrgIdTbl(l_lineCounter);
3638 oe_order_pub.g_line.line_category_code := l_lineCatCodeTbl(l_lineCounter);
3639 oe_order_pub.g_line.shipment_priority_code := l_shipmentPriorityCodeTbl (l_lineCounter);
3640 oe_order_pub.g_line.shippable_flag := l_shippableFlagTbl(l_lineCounter);
3641 oe_order_pub.g_line.schedule_ship_date := l_scheduleShipDateTbl(l_lineCounter);
3642 oe_order_pub.g_line.source_type_code := l_sourceTypeCodeTbl(l_lineCounter);
3643 oe_order_pub.g_line.org_id := l_orgIdTbl(l_lineCounter);
3644 oe_order_pub.g_line.freight_terms_code := l_freightTermsCodeTbl(l_lineCounter);
3645 oe_order_pub.g_line.payment_term_id := l_paymentTermIdTbl(l_lineCounter);
3646 oe_order_pub.g_line.shipping_method_code := l_shippingMethodCodeTbl(l_lineCounter);
3647 oe_order_pub.g_line.item_identifier_type := l_itemIdentifierTypeTbl(l_lineCounter);
3648 oe_order_pub.g_line.ordered_item_id := l_orderedItemIdTbl(l_lineCounter);
3649 oe_order_pub.g_line.top_model_line_id := l_topModelLineIdTbl(l_lineCounter);
3650 oe_order_pub.g_line.unit_percent_base_price := l_unitPercentBasePriceTbl(l_lineCounter);
3651 oe_order_pub.g_line.preferred_grade := l_preferredGradeTbl (l_lineCounter);
3652 oe_order_pub.g_line.Blanket_number := l_blanketNumberTbl(l_lineCounter);
3653 oe_order_pub.g_line.minisite_id := l_minisiteIdTbl(l_lineCounter);
3654 oe_order_pub.g_line.blanket_line_number := l_blanketLineNumberTbl(l_lineCounter);
3655 oe_order_pub.g_line.transaction_phase_code := l_transactionPhaseCodeTbl(l_lineCounter);
3656 oe_order_pub.g_line.charge_periodicity_code := l_chargePeriodicityCodeTbl(l_lineCounter);
3657
3658 QP_Attr_Mapping_PUB.Build_Contexts(
3659 p_request_type_code => 'ONT',
3660 p_line_index => l_tbl_index,
3661 p_pricing_type_code =>'L'
3662 );
3663 IF g_debug_flag = 'Y' THEN
3664 write_conc_log( 'l_tbl_index>' || l_tbl_index);
3665 END IF;
3666 G_LINE_INDEX_TBL(l_tbl_index) := l_tbl_index;
3667 G_LINE_TYPE_CODE_TBL(l_tbl_index):= OZF_ORDER_PRICE_PVT.G_ORDER_LINE_TYPE;
3668 G_PRICING_EFFECTIVE_DATE_TBL(l_tbl_index):= l_pricingDateTbl(l_lineCounter);
3669
3670 G_ACTIVE_DATE_FIRST_TYPE_TBL(l_tbl_index):= 'ORD';
3671 IF l_hdrRequestDateTbl(P) IS NULL THEN
3672 G_ACTIVE_DATE_FIRST_TBL(l_tbl_index):= sysdate;
3673 ELSE
3674 G_ACTIVE_DATE_FIRST_TBL(l_tbl_index):= l_hdrRequestDateTbl(P);
3675 END IF;
3676
3677 G_ACTIVE_DATE_SECOND_TYPE_TBL(l_tbl_index) := 'ORD';
3678 IF l_actualShipDateTbl(l_lineCounter) IS NULL THEN
3679 G_ACTIVE_DATE_SECOND_TBL(l_tbl_index):= NVL(l_fulfillmentDateTbl(l_lineCounter),sysdate);
3680 ELSE
3681 G_ACTIVE_DATE_SECOND_TBL(l_tbl_index):= l_actualShipDateTbl(l_lineCounter);
3682 END IF;
3683
3684 G_LINE_QUANTITY_TBL(l_tbl_index):= l_quantityTbl(l_lineCounter);
3685 G_LINE_UOM_CODE_TBL(l_tbl_index):= l_orderUomTbl(l_lineCounter);
3686 G_REQUEST_TYPE_CODE_TBL(l_tbl_index):= 'ONT';
3687 G_PRICED_QUANTITY_TBL(l_tbl_index):= l_pricingQuantityTbl(l_lineCounter);
3688 G_PRICED_UOM_CODE_TBL(l_tbl_index):= l_pricingUomTbl(l_lineCounter);
3689 G_CURRENCY_CODE_TBL(l_tbl_index):= l_orderCurrTbl(P);
3690 G_UNIT_PRICE_TBL(l_tbl_index):= l_unitSellingPriceTbl(l_lineCounter);
3691 G_PERCENT_PRICE_TBL(l_tbl_index):= null;
3692 G_UOM_QUANTITY_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).UOM_QUANTITY;
3693 G_ADJUSTED_UNIT_PRICE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ADJUSTED_UNIT_PRICE;
3694 G_UPD_ADJUSTED_UNIT_PRICE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).UPD_ADJUSTED_UNIT_PRICE;
3695 G_PROCESSED_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PROCESSED_FLAG;
3696 G_PRICE_FLAG_TBL(l_tbl_index):= 'Y';
3697 G_LIST_PRICE_OVERRIDE_TBL(l_tbl_index):= 'Y';
3698 G_LINE_ID_TBL(l_tbl_index):= l_lineIdTbl(l_lineCounter);
3699 G_PROCESSING_ORDER_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PROCESSING_ORDER;
3700 G_PRICING_STATUS_CODE_tbl(l_tbl_index):= QP_PREQ_GRP.G_STATUS_UNCHANGED;
3701 G_PRICE_LIST_ID_TBL(l_tbl_index):= l_priceListIdTbl(l_lineCounter);
3702 G_PRICING_STATUS_TEXT_tbl(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PRICING_STATUS_TEXT;
3703 G_ROUNDING_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ROUNDING_FLAG;
3704 G_ROUNDING_FACTOR_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).ROUNDING_FACTOR;
3705 G_QUALIFIERS_EXIST_FLAG_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).QUALIFIERS_EXIST_FLAG;
3706 G_PRICING_ATTRS_EXIST_FLAG_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PRICING_ATTRS_EXIST_FLAG;
3707 G_PL_VALIDATED_FLAG_TBL(l_tbl_index):= null; -- l_line_tbl(l_tbl_index).PL_VALIDATED_FLAG;
3708 G_PRICE_REQUEST_CODE_TBL(l_tbl_index):= null; --l_line_tbl(l_tbl_index).PRICE_REQUEST_CODE;
3709 G_USAGE_PRICING_TYPE_tbl(l_tbl_index):= null; --l_line_tbl(l_tbl_index).USAGE_PRICING_TYPE;
3710
3711 IF g_debug_flag = 'Y' THEN
3712 write_conc_log( 'l_tbl_index>>' || l_tbl_index);
3713 END IF;
3714
3715 l_line_tbl(l_tbl_index).line_index := l_tbl_index;
3716 l_line_tbl(l_tbl_index).line_id := l_lineIdTbl(l_lineCounter);
3717 l_line_tbl(l_tbl_index).line_type_code := OZF_ORDER_PRICE_PVT.G_ORDER_LINE_TYPE;
3718 l_line_tbl(l_tbl_index).pricing_effective_date := l_pricingDateTbl(l_lineCounter);
3719 l_line_tbl(l_tbl_index).active_date_first := l_hdrRequestDateTbl(P);
3720 l_line_tbl(l_tbl_index).active_date_first_type := 'ORD';
3721 l_line_tbl(l_tbl_index).active_date_second := NVL(l_actualShipDateTbl(l_lineCounter),NVL(l_fulfillmentDateTbl(l_lineCounter),sysdate));
3722 l_line_tbl(l_tbl_index).active_date_second_type := 'SHIP';
3723 l_line_tbl(l_tbl_index).line_quantity := ABS(l_quantityTbl(l_lineCounter)); -- BUG 4581928
3724 l_line_tbl(l_tbl_index).line_uom_code := l_orderUomTbl(l_lineCounter);
3725 l_line_tbl(l_tbl_index).request_type_code := 'ONT';
3726 l_line_tbl(l_tbl_index).currency_code := l_orderCurrTbl(P);
3727 l_line_tbl(l_tbl_index).transactional_curr_code := l_orderCurrTbl(P); -- nepanda : Fix for bug # 14521452
3728 IF l_priceListIdTbl(l_lineCounter) IS NOT NULL THEN
3729 l_line_tbl(l_tbl_index).price_list_id := l_priceListIdTbl(l_lineCounter);
3730 END IF;
3731 l_line_tbl(l_tbl_index).price_flag := 'Y';
3732 --l_line_tbl(l_tbl_index).list_price_override_flag := l_list_price_override_flag;
3733 l_line_tbl(l_tbl_index).pricing_status_code := QP_PREQ_GRP.G_STATUS_UNCHANGED;
3734 l_line_tbl(l_tbl_index).header_id := l_uniqueHeaderIdtbl(P);
3735 l_line_tbl(l_tbl_index).org_id := l_hdrOrgIdTbl(P);
3736 l_line_tbl(l_tbl_index).inventory_item_id := l_inventoryItemIdTbl(l_lineCounter);
3737 l_line_tbl(l_tbl_index).line_category_code := l_lineCatCodeTbl(l_lineCounter);
3738 l_line_tbl(l_tbl_index).reference_line_id := l_refLineIdTbl(l_lineCounter);
3739 write_conc_log( 'l_tbl_index>>>' || l_tbl_index);
3740
3741 --kdass: bug 15877269 - added following colums to l_line_tbl which is passed to Process_Pricing_Result
3742 --and used in API Process_VO_Result
3743 l_line_tbl(l_tbl_index).line_category_code := l_lineCatCodeTbl(l_lineCounter);
3744 l_line_tbl(l_tbl_index).shipped_quantity := l_shippedQuantityTbl(l_lineCounter);
3745 l_line_tbl(l_tbl_index).actual_shipment_date := l_actualShipDateTbl(l_lineCounter);
3746 l_line_tbl(l_tbl_index).invoice_interface_status_code := l_invoiceInterfaceStatusTbl(l_lineCounter);
3747 l_line_tbl(l_tbl_index).invoiced_quantity := l_invoicedQuantityTbl(l_lineCounter);
3748 l_line_tbl(l_tbl_index).sold_to_org_id := l_soldToOrgIdTbl(l_lineCounter);
3749 l_line_tbl(l_tbl_index).ship_to_org_id := l_shipToOrgIdTbl(l_lineCounter);
3750 l_line_tbl(l_tbl_index).invoice_to_org_id := l_invoiceToOrgIdTbl(l_lineCounter);
3751 l_line_tbl(l_tbl_index).shipping_quantity_uom := l_shippingQuantityUomTbl(l_lineCounter);
3752 -- Catch Weight ER
3753 l_line_tbl(l_tbl_index).shipping_quantity := l_shippingQuantityTbl(l_lineCounter);
3754 l_line_tbl(l_tbl_index).shipping_quantity_uom2 := l_shippingQuantityUom2Tbl(l_lineCounter);
3755 l_line_tbl(l_tbl_index).shipping_quantity2 := l_shippingQuantity2Tbl(l_lineCounter);
3756 l_line_tbl(l_tbl_index).fulfillment_base := l_fulfillmentBaseTbl(l_lineCounter);
3757 -- Catch Weight ER
3758 l_line_tbl(l_tbl_index).selling_price := l_unitSellingPriceTbl(l_lineCounter);
3759
3760 /* consider this when coding for volume offer IF l_group_string IS NOT NULL THEN
3761 x_order_line_tbl(l_tbl_index).group_nos := l_group_nos(i);
3762 END IF;*/
3763
3764
3765 IF g_debug_flag = 'Y' THEN
3766 write_conc_log( 'l_tbl_index>>>>' || l_tbl_index);
3767 END IF;
3768
3769 END LOOP; --end of l_tempLineIdTbl_1 loop
3770
3771 IF g_debug_flag = 'Y' THEN
3772 write_conc_log( 'l_tbl_index>>>>>' || l_tbl_index);
3773 write_conc_log ('G_LINE_INDEX_TBL.COUNT ' || G_LINE_INDEX_TBL.COUNT);
3774 write_conc_log ('l_tbl_index> >' || l_tbl_index);
3775 END IF;
3776
3777
3778
3779 --l_tbl_index := l_tbl_index + 1;
3780
3781
3782
3783 QP_PREQ_GRP.INSERT_LINES2
3784 (p_LINE_INDEX => G_LINE_INDEX_TBL,
3785 p_LINE_TYPE_CODE => G_LINE_TYPE_CODE_TBL,
3786 p_PRICING_EFFECTIVE_DATE =>G_PRICING_EFFECTIVE_DATE_TBL,
3787 p_ACTIVE_DATE_FIRST =>G_ACTIVE_DATE_FIRST_TBL,
3788 p_ACTIVE_DATE_FIRST_TYPE =>G_ACTIVE_DATE_FIRST_TYPE_TBL,
3789 p_ACTIVE_DATE_SECOND =>G_ACTIVE_DATE_SECOND_TBL,
3790 p_ACTIVE_DATE_SECOND_TYPE =>G_ACTIVE_DATE_SECOND_TYPE_TBL,
3791 p_LINE_QUANTITY => G_LINE_QUANTITY_TBL,
3792 p_LINE_UOM_CODE => G_LINE_UOM_CODE_TBL,
3793 p_REQUEST_TYPE_CODE => G_REQUEST_TYPE_CODE_TBL,
3794 p_PRICED_QUANTITY => G_PRICED_QUANTITY_TBL,
3795 p_PRICED_UOM_CODE => G_PRICED_UOM_CODE_TBL,
3796 p_CURRENCY_CODE => G_CURRENCY_CODE_TBL,
3797 p_UNIT_PRICE => G_UNIT_PRICE_TBL,
3798 p_PERCENT_PRICE => G_PERCENT_PRICE_TBL,
3799 p_UOM_QUANTITY => G_UOM_QUANTITY_TBL,
3800 p_ADJUSTED_UNIT_PRICE =>G_ADJUSTED_UNIT_PRICE_TBL,
3801 p_UPD_ADJUSTED_UNIT_PRICE =>G_UPD_ADJUSTED_UNIT_PRICE_TBL,
3802 p_PROCESSED_FLAG =>G_PROCESSED_FLAG_TBL,
3803 p_PRICE_FLAG =>G_PRICE_FLAG_TBL,
3804 p_LINE_ID =>G_LINE_ID_TBL,
3805 p_PROCESSING_ORDER =>G_PROCESSING_ORDER_TBL,
3806 p_PRICING_STATUS_CODE =>G_PRICING_STATUS_CODE_tbl,
3807 p_PRICING_STATUS_TEXT =>G_PRICING_STATUS_TEXT_tbl,
3808 p_ROUNDING_FLAG =>G_ROUNDING_FLAG_TBL,
3809 p_ROUNDING_FACTOR =>G_ROUNDING_FACTOR_TBL,
3810 p_QUALIFIERS_EXIST_FLAG => G_QUALIFIERS_EXIST_FLAG_TBL,
3811 p_PRICING_ATTRS_EXIST_FLAG =>G_PRICING_ATTRS_EXIST_FLAG_TBL,
3812 p_PRICE_LIST_ID => G_PRICE_LIST_ID_TBL,
3813 p_VALIDATED_FLAG => G_PL_VALIDATED_FLAG_TBL,
3814 p_PRICE_REQUEST_CODE => G_PRICE_REQUEST_CODE_TBL,
3815 p_USAGE_PRICING_TYPE =>G_USAGE_PRICING_TYPE_tbl,
3816 p_LIST_PRICE_OVERRIDE_FLAG =>G_LIST_PRICE_OVERRIDE_TBL,
3817 -- p_line_category =>G_LINE_CATEGORY_tbl,
3818 x_status_code =>l_return_status_code,
3819 x_status_text => l_price_return_msg);
3820
3821 IF g_debug_flag = 'Y' THEN
3822 write_conc_log ('l_return_status_code ' || l_return_status_code);
3823 write_conc_log ('l_price_return_msg ' || l_price_return_msg);
3824 END IF;
3825
3826 IF l_return_status_code <> FND_API.G_RET_STS_SUCCESS THEN
3827 IF FND_MSG_PUB.check_msg_level(FND_MSG_PUB.g_msg_lvl_error) THEN
3828 FND_MESSAGE.set_name('OZF', 'OZF_ORDER_INSERT_ERR');
3829 FND_MSG_PUB.add;
3830 dbms_output.put_line(l_price_return_msg);
3831 END IF;
3832 RAISE FND_API.G_EXC_ERROR;
3833 END IF;
3834
3835
3836 -- Call qp price engine
3837 QP_PREQ_PUB.PRICE_REQUEST
3838 (p_control_rec => l_control_rec,
3839 x_return_status => x_return_status,
3840 x_return_status_text => l_msg_data);
3841
3842 IF g_debug_flag = 'Y' THEN
3843 write_conc_log ('x_return_status ' || x_return_status);
3844 write_conc_log ('l_msg_data ' || l_msg_data);
3845 END IF;
3846
3847 IF x_return_status = FND_API.g_ret_sts_error THEN
3848 write_conc_log('in error'|| l_msg_data);
3849 RAISE FND_API.g_exc_error;
3850 ELSIF x_return_status = FND_API.g_ret_sts_unexp_error THEN
3851 write_conc_log('in un'|| l_msg_data);
3852 RAISE FND_API.g_exc_unexpected_error;
3853 END IF;
3854
3855 Process_Pricing_Result(
3856 p_header_id => l_uniqueHeaderIdtbl(P),
3857 p_line_tbl => l_line_tbl,
3858 p_adjIdByListHdrId => l_adjIdByListHdrId,
3859 x_return_status => x_return_status);
3860
3861 IF x_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3862 write_conc_log('Process_Pricing_Result '|| x_return_status);
3863 END IF;
3864 write_conc_log( '--------------------------------------------------------');
3865 COMMIT;
3866 <<LABEL_FOR_NEXT_ITERATION>>
3867 NULL;
3868 END IF; --l_lineIdTblByHdrId.EXISTS(l_uniqueHeaderIdtbl(P))
3869 END LOOP; -- end of l_uniqueHeaderIdtbl LOOP
3870
3871
3872
3873 IF l_count_temp >= 6 AND l_volume_offer='N' THEN
3874 EXIT WHEN c_order_header2%NOTFOUND;
3875 ELSIF l_count_temp >= 6 AND l_volume_offer='Y' THEN
3876 EXIT WHEN c_order_header4%NOTFOUND;
3877 ELSIF l_count_temp < 6 AND l_volume_offer='N' THEN
3878 EXIT WHEN c_order_header1%NOTFOUND;
3879 ELSIF l_count_temp < 6 AND l_volume_offer='Y' THEN
3880 EXIT WHEN c_order_header3%NOTFOUND;
3881 END IF;
3882 END LOOP; -- end of bulk fetch of header_id loop
3883
3884 IF l_count_temp >= 6 AND l_volume_offer='N' THEN
3885 CLOSE c_order_header2;
3886 ELSIF l_count_temp >= 6 AND l_volume_offer='Y' THEN
3887 CLOSE c_order_header4;
3888 ELSIF l_count_temp < 6 AND l_volume_offer='N' THEN
3889 CLOSE c_order_header1;
3890 ELSIF l_count_temp < 6 AND l_volume_offer='Y' THEN
3891 CLOSE c_order_header3;
3892 END IF;
3893
3894 --exists clause makes sure that an adjustment which didn't get processed
3895 --at all i.e. not even on record got created should not be closed
3896 --consider the scenarion, where none of the order lines qualified
3897 --for that offer. Then the adjustment should not be closed.
3898 --later on the qualification issue can be fixed and FAE can be executed again.
3899
3900 -- Suppose customer forgot to run refresh concurrent program
3901 -- the adjustment will get closed w/o any util.
3902 --The code below will make sur ethe adjustment remains open
3903
3904 --bug 14811824 move update statement out of the
3905 --loop of orders qualified for backdated adjustment
3906 -- If only regular adjustment is processed successfully.
3907 --adjustment should get closed.
3908
3909 --IF x_return_status = fnd_api.g_ret_sts_success THEN
3910
3911 -- handle TP Orders distinctly as backdated adjustment is not supported.
3912
3913 IF g_debug_flag = 'Y' THEN
3914 write_conc_log ('Closing adjustments ' );
3915 END IF;
3916
3917 FORALL t_i IN INDICES OF l_adjIdByListHdrId
3918 UPDATE ozf_offer_adjustments_b b
3919 SET budget_adjusted_flag = 'Y',
3920 object_version_number = object_version_number + 1,
3921 status_code = 'CLOSED'
3922 WHERE offer_adjustment_id = l_adjidbylisthdrid(t_i)
3923 AND EXISTS
3924 (SELECT 1
3925 FROM ozf_funds_utilized_all_b
3926 WHERE request_id = l_request_id
3927 AND plan_id = b.list_header_id
3928 UNION ALL
3929 SELECT 1
3930 FROM ozf_funds_utilized_all_b ofuab,
3931 ozf_resale_adjustments ora
3932 WHERE ofuab.plan_id = b.list_header_id
3933 AND ora.list_header_id = b.list_header_id
3934 AND ofuab.utilization_type = 'ACCRUAL'
3935 AND ofuab.object_type = 'TP_ORDER');
3936
3937 x_retcode := 0;
3938 x_errbuf := l_msg_data;
3939
3940 --END IF;
3941
3942
3943
3944 write_conc_log (' /*************************** ADJUST BD END *************************/');
3945 EXCEPTION
3946 WHEN FND_API.G_EXC_ERROR THEN
3947 ROLLBACK TO adjust_backdated_offer;
3948 x_retcode := 1;
3949 x_errbuf := l_msg_data;
3950 ozf_utility_pvt.write_conc_log;
3951 ozf_utility_pvt.write_conc_log (x_errbuf);
3952 write_conc_log( 'G_EXC_ERROR'||sqlerrm );
3953 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3954 ROLLBACK TO adjust_backdated_offer;
3955 x_retcode := 1;
3956 x_errbuf := l_msg_data;
3957 ozf_utility_pvt.write_conc_log;
3958 ozf_utility_pvt.write_conc_log (x_errbuf);
3959 write_conc_log( 'G_EXC_UNEXPECTED_ERROR'||sqlerrm );
3960 WHEN OTHERS THEN
3961 ROLLBACK TO adjust_backdated_offer;
3962 x_retcode := 1;
3963 x_errbuf := l_msg_data;
3964 ozf_utility_pvt.write_conc_log;
3965 ozf_utility_pvt.write_conc_log (x_errbuf);
3966 write_conc_log( 'OTHERS'||sqlerrm );
3967 END adjust_backdated_offer;
3968
3969
3970 ---------------------------------------------------------------------
3971 -- FUNCTION
3972 -- is_valid_offer
3973 --
3974 -- PURPOSE
3975 -- This procedure this offer should be accrued or not
3976 --
3977 -- PARAMETERS
3978 -- p_list_header_id
3979 --
3980 -- NOTES
3981 --------------------------------------------------------------------
3982 PROCEDURE Is_Valid_Offer(
3983 p_list_header_id IN NUMBER,
3984 p_list_line_id IN NUMBER,
3985 p_line_id IN NUMBER,
3986 p_object_type IN VARCHAR2,
3987 x_result OUT NOCOPY BOOLEAN,
3988 x_return_status OUT NOCOPY VARCHAR2
3989 )
3990 IS
3991 l_result VARCHAR2(30) := NULL;
3992 l_offer_id NUMBER;
3993 l_offer_type VARCHAR2(30) := NULL;
3994
3995 CURSOR omo_offer_csr IS
3996 SELECT offer_id, offer_type
3997 FROM ozf_offers
3998 WHERE qp_list_header_id = p_list_header_id;
3999
4000
4001 CURSOR line_adjustment_csr IS
4002 SELECT 1
4003 FROM oe_price_adjustments
4004 WHERE line_id = p_line_id
4005 AND list_header_id = p_list_header_id
4006 AND list_line_id IN (SELECT from_list_line_id
4007 FROM ozf_offer_adj_rltd_lines
4008 START WITH to_list_line_id = p_list_line_id
4009 CONNECT BY PRIOR from_list_line_id = to_list_line_id
4010 UNION ALL
4011 SELECT to_list_line_id FROM ozf_offer_adj_rltd_lines where to_list_line_id = p_list_line_id ) ;
4012
4013 --for volume offer, duplicate item cannot be added to the offer.
4014 CURSOR hdr_adjustment_csr IS
4015 SELECT 1
4016 FROM oe_price_adjustments
4017 WHERE line_id = p_line_id
4018 AND list_header_id = p_list_header_id;
4019
4020 BEGIN
4021 -- Initialize API return status to sucess
4022 x_return_status := FND_API.G_RET_STS_SUCCESS;
4023
4024 ozf_utility_pvt.write_conc_log('p_list_header_id '||p_list_header_id );
4025 ozf_utility_pvt.write_conc_log('p_list_line_id '||p_list_line_id);
4026 ozf_utility_pvt.write_conc_log('p_line_id '||p_line_id);
4027
4028 -- First it has to be an OMO offer
4029 OPEN omo_offer_csr;
4030 FETCH omo_offer_csr INTO l_offer_id, l_offer_type;
4031 CLOSE omo_offer_csr;
4032
4033 IF l_offer_id is not NULL THEN
4034
4035 x_result:= true;
4036
4037 IF g_debug_flag = 'Y' THEN
4038 ozf_utility_pvt.write_conc_log('Its a TM offer ');
4039 END IF;
4040 ELSE
4041 x_result:= false;
4042 END IF;
4043
4044
4045
4046
4047 l_result := null;
4048 IF x_result THEN
4049 -- Second it has not been accrued before
4050 IF l_offer_type <> 'VOLUME_OFFER' THEN
4051 OPEN line_adjustment_csr;
4052 FETCH line_adjustment_csr INTO l_result;
4053 CLOSE line_adjustment_csr;
4054 /* ELSE
4055 OPEN hdr_adjustment_csr;
4056 FETCH hdr_adjustment_csr INTO l_result;
4057 CLOSE hdr_adjustment_csr;*/
4058
4059 IF l_result is not NULL THEN
4060 x_result:= false;
4061 ELSE
4062 IF g_debug_flag = 'Y' THEN
4063 ozf_utility_pvt.write_conc_log('There are no records in oe_price_adjustment for this offer order combination');
4064 END IF;
4065 END IF;
4066 END IF;
4067 END IF;
4068
4069
4070 EXCEPTION
4071 WHEN FND_API.G_EXC_ERROR THEN
4072 x_return_status := FND_API.G_RET_STS_ERROR;
4073 WHEN OTHERS THEN
4074 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4075 IF g_debug_flag = 'Y' THEN
4076 ozf_utility_pvt.write_conc_log('Exception in is_valid_offer ');
4077 END IF;
4078 END is_valid_offer;
4079 ---------------------------------------------------------------------
4080 -- PROCEDURE
4081 -- Process_VO_Result
4082 --
4083 -- PURPOSE
4084 -- This procedure process the pricing call result for volume offer.
4085 -- It creates accruals based on the discount information.
4086 --
4087 -- PARAMETERS
4088 -- p_resale_batch_id IN NUMBER,
4089 -- p_line_tbl IN OZF_ORDER_PRICE_PVT.LINE_REC_TBL_TYPE,
4090 -- p_caller_type IN VARCHAR2,
4091 -- x_return_status OUT NOCOPY VARCHAR2
4092 --
4093 -- NOTES
4094 -- 1. Non-monetray accruals have not been considered. Should look INTO ldets.benefit_qty
4095 -- and ldets.benefit_uom for calculation.
4096 -- 2. We will not do third party accruals on tracing data
4097 --
4098 ---------------------------------------------------------------------
4099 PROCEDURE Process_VO_Result(
4100 p_line_rec IN OZF_Adjustment_ext_PVT.LINE_REC_TYPE,
4101 p_ldets_rec IN qp_ldets_v%rowtype,
4102 p_adjIdByListHdrId IN OUT NOCOPY numberTbl,
4103 p_vol_off_type IN VARCHAR2,
4104 x_return_status OUT NOCOPY VARCHAR2
4105 )
4106 IS
4107
4108 CURSOR c_invoice_date(p_line_id IN NUMBER, p_order_number IN VARCHAR2) IS
4109 SELECT cust.trx_date -- transaction(invoice) date
4110 FROM ra_customer_trx_all cust,
4111 ra_customer_trx_lines_all cust_lines
4112 WHERE cust.customer_trx_id = cust_lines.customer_trx_id
4113 AND cust_lines.sales_order = p_order_number -- added condition for partial index for bug fix 3917556
4114 AND cust_lines.interface_line_attribute6 = to_char(p_line_id);
4115
4116 CURSOR sales_transation_csr(p_line_id IN NUMBER) IS
4117 SELECT 1
4118 FROM dual
4119 WHERE EXISTS
4120 (SELECT 1
4121 FROM ozf_sales_transactions_all trx
4122 WHERE trx.line_id = p_line_id
4123 AND source_code = 'OM');
4124
4125 CURSOR party_id_csr(p_cust_account_id IN NUMBER) IS
4126 SELECT party_id
4127 FROM hz_cust_accounts
4128 WHERE cust_account_id = p_cust_account_id;
4129
4130 CURSOR c_apply_discount(p_offer_id IN NUMBER, p_line_id IN NUMBER) IS
4131 SELECT nvl(apply_discount_flag, 'N')
4132 FROM ozf_order_group_prod
4133 WHERE offer_id = p_offer_id
4134 AND order_line_id = p_line_id;
4135
4136 CURSOR c_offer_info(p_list_header_id IN NUMBER) IS
4137 SELECT nvl(transaction_currency_code, fund_request_curr_code) offer_currency_code,
4138 transaction_currency_code,
4139 beneficiary_account_id,
4140 offer_id
4141 FROM ozf_offers
4142 WHERE qp_list_header_id = p_list_header_id;
4143
4144 CURSOR c_cust_number(p_header_id IN NUMBER) IS
4145 SELECT cust.cust_account_id
4146 FROM hz_cust_acct_sites_all acct_site,
4147 hz_cust_site_uses_all site_use,
4148 hz_cust_accounts cust,
4149 oe_order_headers_all header
4150 WHERE header.header_id = p_header_id
4151 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
4152 AND acct_site.cust_account_id = cust.cust_account_id
4153 AND site_use.site_use_id = header.invoice_to_org_id;
4154
4155 CURSOR c_get_group(p_order_line_id IN NUMBER, p_list_header_id IN NUMBER) IS
4156 SELECT group_no,
4157 pbh_line_id,
4158 include_volume_flag
4159 FROM ozf_order_group_prod
4160 WHERE order_line_id = p_order_line_id
4161 AND qp_list_header_id = p_list_header_id;
4162
4163 CURSOR c_market_option(p_list_header_id IN NUMBER, p_group_id IN NUMBER) IS
4164 SELECT opt.retroactive_flag
4165 FROM ozf_offr_market_options opt
4166 WHERE opt.group_number = p_group_id
4167 AND opt.qp_list_header_id = p_list_header_id;
4168
4169 CURSOR c_discount_header(p_discount_line_id IN NUMBER) IS
4170 SELECT discount_type,
4171 volume_type
4172 FROM ozf_offer_discount_lines
4173 WHERE offer_discount_line_id = p_discount_line_id
4174 AND tier_type = 'PBH';
4175
4176 CURSOR party_site_id_csr(p_account_site_id IN NUMBER) IS
4177 SELECT a.party_site_id
4178 FROM hz_cust_acct_sites_all a,
4179 hz_cust_site_uses_all b
4180 WHERE b.site_use_id = p_account_site_id
4181 AND b.cust_acct_site_id = a.cust_acct_site_id;
4182
4183 --nirprasa,12.2 replace amount by plan_curr_amount
4184 CURSOR c_order_adjustment_amt(p_object_id IN NUMBER,
4185 p_order_line_id IN NUMBER, p_prod_id IN NUMBER,
4186 p_list_header_id IN NUMBER) IS
4187 SELECT SUM(plan_curr_amount)
4188 FROM ozf_funds_utilized_all_b
4189 WHERE plan_type = 'OFFR'
4190 AND plan_id = p_list_header_id
4191 AND object_type = 'ORDER'
4192 AND object_id = p_object_id
4193 AND order_line_id = p_order_line_id
4194 AND product_level_type = 'PRODUCT'
4195 AND product_id = p_prod_id;
4196 -- AND utilization_type IN ('ADJUSTMENT', 'LEAD_ADJUSTMENT')
4197 -- AND adjustment_type_id in(-4,-5,-1);
4198
4199 CURSOR c_exchange_rate_type(p_org_id IN NUMBER) IS
4200 SELECT exchange_rate_type
4201 FROM ozf_sys_parameters_all
4202 WHERE org_id = p_org_id;
4203
4204
4205 l_api_name CONSTANT VARCHAR2(30) := 'Process_VO_Result';
4206 l_full_name CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
4207 l_return_status VARCHAR2(30);
4208
4209 l_order_gl_phase CONSTANT VARCHAR2 (15) := NVL(fnd_profile.VALUE ('OZF_ORDER_GLPOST_PHASE'), 'SHIPPED');
4210 l_sales_transaction_rec OZF_SALES_TRANSACTIONS_PVT.SALES_TRANSACTION_REC_TYPE;
4211 l_offer_info c_offer_info%ROWTYPE;
4212 l_sales_trans NUMBER;
4213 l_sales_transaction_id NUMBER;
4214 l_cust_number NUMBER;
4215 l_gl_date DATE;
4216 l_group_id NUMBER;
4217 l_pbh_line_id NUMBER;
4218 l_included_vol_flag VARCHAR2(1);
4219 l_retroactive VARCHAR2(1) ;
4220 l_discount_type VARCHAR2(30);
4221 l_volume_type VARCHAR2(30);
4222 l_msg_data VARCHAR2 (2000) := NULL;
4223 l_msg_count NUMBER;
4224 l_apply_discount VARCHAR2(1);
4225 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
4226 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
4227 l_adj_amount NUMBER;
4228 l_utilization_amount NUMBER;
4229 l_act_budget_id NUMBER;
4230 l_conv_type ozf_funds_utilized_all_b.exchange_rate_type%TYPE;
4231 -- Catch Weight ER
4232 l_cw_quantity NUMBER;
4233 l_cw_quantity_uom VARCHAR2(30);
4234 l_fulfillment_base VARCHAR2(1);
4235 -- Catch Weight ER
4236 BEGIN
4237 -- Debug Message
4238 IF g_debug_flag = 'Y' THEN
4239 OZF_UTILITY_PVT.write_conc_log(l_full_name||': start');
4240 END IF;
4241
4242 x_return_status := FND_API.G_RET_STS_SUCCESS;
4243
4244 SAVEPOINT PROC_VO_RESULT;
4245
4246 --Since, pricing call is already made, removed the simulation of pricing call.
4247 --Seeded TM API OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value,
4248 --will be called and ozf_order_group_prod table will be populated.
4249 -- Kept this code on purpose, to make the calculation changes more clear
4250
4251 /*--fix for bug # 5944862
4252 OPEN c_offer_info (p_list_header_id);
4253 FETCH c_offer_info INTO l_offer_info;
4254 CLOSE c_offer_info;
4255 -- -----
4256 write_conc_log('p_list_header_id: '||p_list_header_id);
4257 write_conc_log('l_order_line_tbl(j).inventory_item_id '||l_order_line_tbl(j).inventory_item_id);
4258
4259 OPEN c_get_items_type(p_list_header_id,l_order_line_tbl(j).inventory_item_id);
4260 FETCH c_get_items_type INTO l_prod_attr, l_prod_attr_val;
4261 CLOSE c_get_items_type;
4262
4263 write_conc_log('l_prod_attr: '||l_prod_attr);
4264 write_conc_log('l_prod_attr_val: '||l_prod_attr_val);
4265
4266 OPEN c_get_cond_id_column(l_prod_attr);
4267 FETCH c_get_cond_id_column INTO l_cond_id_column;
4268 CLOSE c_get_cond_id_column;
4269
4270 write_conc_log('l_cond_id_column: '||l_cond_id_column);
4271 -- fix for bug 5767748
4272
4273 IF l_prod_attr_val IS NULL THEN -- if not item category
4274
4275 l_prod_attr_val :=l_order_line_tbl(j).inventory_item_id;
4276 IF l_cond_id_column IS NOT NULL THEN --if product context
4277
4278 l_stmt := 'select ' || l_cond_id_column ||
4279 ' from mtl_system_items where ORGANIZATION_ID = FND_PROFILE.VALUE(''QP_ORGANIZATION_ID'') and inventory_item_id =:1 and rownum = 1';
4280 write_conc_log(l_stmt);
4281
4282 OPEN l_product_val_cursor FOR l_stmt using l_prod_attr_val;
4283 LOOP
4284 FETCH l_product_val_cursor INTO l_prod_attr_val;
4285 EXIT WHEN l_product_val_cursor%NOTFOUND;
4286 END LOOP;
4287
4288 --ELSE -- if inventory item
4289 --l_prod_attr_val :=l_order_line_tbl(j).inventory_item_id;
4290 END IF;
4291 END IF;
4292
4293 write_conc_log('l_prod_attr_val: '||l_prod_attr_val);
4294 write_conc_log('l_offer_info.offer_id: '||l_offer_info.offer_id);
4295
4296
4297 OPEN c_list_line (l_offer_info.offer_id,l_prod_attr_val);
4298 FETCH c_list_line INTO l_list_line_id,l_prod_attr,l_prod_attr_val;
4299 CLOSE c_list_line;
4300
4301
4302 write_conc_log('l_list_line_id: '||l_list_line_id);
4303 write_conc_log('l_prod_attr: '||l_prod_attr);
4304 write_conc_log('ll_prod_attr_val: '||l_prod_attr_val);
4305 -- -----
4306
4307
4308 l_index := 1;
4309 -- product
4310 l_req_line_attrs_tbl(l_index).line_index := 1;
4311 l_req_line_attrs_tbl(l_index).attribute_type := 'PRODUCT';
4312 l_req_line_attrs_tbl(l_index).context := NULL;
4313 l_req_line_attrs_tbl(l_index).attribute := l_prod_attr;
4314 l_req_line_attrs_tbl(l_index).value := l_prod_attr_val; -- inventory_item_id
4315 l_req_line_attrs_tbl(l_index).grouping_no := NULL;
4316
4317
4318 l_cntr := 0;
4319 l_last_pos := 0;
4320 l_first_pos := 1;
4321 l_num_chars := 0;
4322
4323 write_conc_log ('l_order_line_tbl(j).group_nos: ' || l_order_line_tbl(j).group_nos);
4324
4325 IF l_order_line_tbl(j).group_nos IS NOT NULL THEN
4326
4327 --loop to get individual group number from the comma seperated list
4328 l_string := l_order_line_tbl(j).group_nos;
4329 LOOP
4330 l_last_pos := INSTR(l_string,',',1,l_cntr+1);
4331 l_num_chars := l_last_pos - l_first_pos;
4332 IF l_last_pos = 0 THEN
4333 l_value := SUBSTR(l_string, l_first_pos);
4334 ELSE
4335 l_value := substr(l_string, l_first_pos,l_num_chars);
4336 l_first_pos := l_last_pos + 1;
4337 END IF;
4338 l_cntr := l_cntr + 1;
4339
4340 -- qualifier
4341 l_index := l_index + 1;
4342 l_req_line_attrs_tbl(l_index).line_index := 1;
4343 l_req_line_attrs_tbl(l_index).attribute_type := 'QUALIFIER';
4344 l_req_line_attrs_tbl(l_index).context := NULL;
4345 l_req_line_attrs_tbl(l_index).attribute := NULL;
4346 l_req_line_attrs_tbl(l_index).value := NULL;
4347 l_req_line_attrs_tbl(l_index).grouping_no := l_value;
4348
4349 write_conc_log('group no: ' || l_value);
4350
4351 IF l_last_pos = 0 THEN
4352 EXIT;
4353 END IF;
4354 END LOOP;
4355
4356 END IF;
4357
4358
4359
4360 write_conc_log('l_list_line_id: ' || l_list_line_id);
4361 write_conc_log('calling OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value');
4362
4363 --simulation of pricing engine call while booking order
4364 l_dummy := OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value
4365 (p_list_line_id => l_list_line_id
4366 ,p_list_line_no => NULL
4367 ,p_order_header_id => l_order_line_tbl(j).order_header_id
4368 ,p_order_line_id => l_order_line_tbl(j).order_line_id
4369 ,p_price_effective_date => NULL
4370 ,p_req_line_attrs_tbl => l_req_line_attrs_tbl
4371 ,p_accum_rec => NULL
4372 );
4373
4374 write_conc_log('calling OZF_VOLUME_CALCULATION_PUB.get_numeric_attribute_value returns: ' || l_dummy);*/
4375
4376 l_gl_date := NULL;
4377
4378 /*OPEN c_order_line_details (l_order_line_tbl(j).order_line_id);
4379 FETCH c_order_line_details into l_shipment_date, l_shipped_qty, l_flow_status_code, l_invoice_status_code,
4380 l_invoiced_quantity, l_sold_to_org_id, l_invoice_to_org_id, l_ship_to_org_id,
4381 l_shipping_quantity_uom, l_order_quantity_uom, l_unit_selling_price, l_org_id, l_ordered_qty;
4382 CLOSE c_order_line_details;*/
4383
4384 write_conc_log ('order org: ' || p_line_rec.org_id);
4385
4386 -- Catch Weight ER
4387 /*OZF_UTILITY_PVT.get_catch_weight_quantity (
4388 p_inventory_item_id => p_line_rec.inventory_item_id,
4389 p_order_line_id => p_line_rec.line_id,
4390 x_return_status => l_return_status,
4391 x_cw_quantity => l_cw_quantity,
4392 x_cw_quantity_uom => l_cw_quantity_uom ); */
4393
4394 -- getting fulfillment_base from OE API. In case of performance issue can think of using fulfillment_base from existing cursor
4395 l_fulfillment_base := OE_DUAL_UOM_UTIL.get_fulfillment_base(p_line_rec.line_id) ;
4396
4397 --IF p_line_rec.fulfillment_base = 'S' THEN
4398 IF l_fulfillment_base = 'S' THEN
4399 l_cw_quantity := p_line_rec.shipping_quantity;
4400 l_cw_quantity_uom := p_line_rec.shipping_quantity_uom;
4401 ELSE
4402 l_cw_quantity := NVL(p_line_rec.shipping_quantity2, p_line_rec.shipping_quantity);
4403 l_cw_quantity_uom := NVL(p_line_rec.shipping_quantity_uom2, p_line_rec.shipping_quantity_uom);
4404 END IF;
4405
4406 -- Catch Weight ER
4407
4408 --ninarasi: bug 15877269 - When the order is shipped and invoiced the flow_status_code can be 'POST BILLING ACCEPTANCE'.
4409 --So for this status the following check will not work. So commented the flow_status_code check below (refer QP bug 14785197)
4410 IF ( l_order_gl_phase = 'SHIPPED' AND p_line_rec.line_category_code <> 'RETURN' AND
4411 NVL(p_line_rec.shipped_quantity,0) <> 0 ) THEN
4412 --AND p_line_rec.flow_status_code = 'SHIPPED'
4413
4414 l_gl_date := p_line_rec.actual_shipment_date;
4415 IF G_DEBUG THEN
4416 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.shipped_quantity = '|| p_line_rec.shipped_quantity);
4417 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.shipping_quantity = '|| p_line_rec.shipping_quantity);
4418 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.shipping_quantity_uom = '|| p_line_rec.shipping_quantity_uom);
4419 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.shipping_quantity2 = '|| p_line_rec.shipping_quantity2);
4420 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.shipping_quantity_uom2 = '|| p_line_rec.shipping_quantity_uom2);
4421 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.fulfillment_base = '|| p_line_rec.fulfillment_base);
4422 END IF;
4423
4424 l_sales_transaction_rec.quantity := NVL(l_cw_quantity, p_line_rec.shipped_quantity); -- catch weight ER
4425 l_sales_transaction_rec.uom_code:= NVL(l_cw_quantity_uom, p_line_rec.line_uom_code);
4426 l_sales_transaction_rec.transfer_type := 'IN';
4427
4428 write_conc_log('gl date is shipment date: ' || l_gl_date);
4429
4430 END IF;
4431
4432 IF l_gl_date IS NULL THEN
4433 IF (p_line_rec.invoice_interface_status_code = 'YES' OR NVL(p_line_rec.invoiced_quantity,0) <> 0) THEN
4434 OPEN c_invoice_date(p_line_rec.line_id, p_line_rec.order_number);
4435 FETCH c_invoice_date INTO l_gl_date;
4436 CLOSE c_invoice_date;
4437
4438 write_conc_log('gl date is invoice date: ' || l_gl_date);
4439
4440 IF l_gl_date IS NULL THEN
4441 l_gl_date := sysdate;
4442 write_conc_log('gl date is sysdate: ' || l_gl_date);
4443 END IF;
4444
4445 IF G_DEBUG THEN
4446 ozf_utility_pvt.write_conc_log('Catch Weight VO p_line_rec.invoiced_quantity = '|| p_line_rec.invoiced_quantity);
4447 END IF;
4448 l_sales_transaction_rec.quantity := p_line_rec.invoiced_quantity;
4449 l_sales_transaction_rec.uom_code:= NVL(p_line_rec.shipping_quantity_uom, p_line_rec.line_uom_code);
4450
4451 END IF;
4452 END IF;
4453
4454 write_conc_log('gl date: ' || l_gl_date);
4455 write_conc_log('line id: ' || p_line_rec.line_id);
4456
4457 --kdass: bug 15877269 - l_gl_date is always NULL since p_line_rec colume used in logic below are not passed from
4458 --adjust_backdated_offer. Added these columns to p_line_rec in adjust_backdated_offer API
4459 IF l_gl_date IS NOT NULL THEN
4460 OPEN sales_transation_csr(p_line_rec.line_id);
4461 FETCH sales_transation_csr INTO l_sales_trans;
4462 CLOSE sales_transation_csr;
4463
4464 write_conc_log('l_sales_trans: ' || l_sales_trans);
4465
4466 l_sales_transaction_rec.sold_to_cust_account_id := p_line_rec.sold_to_org_id;
4467
4468 OPEN party_id_csr(l_sales_transaction_rec.sold_to_cust_account_id);
4469 FETCH party_id_csr INTO l_sales_transaction_rec.sold_to_party_id;
4470 CLOSE party_id_csr;
4471
4472 OPEN party_site_id_csr(p_line_rec.invoice_to_org_id);
4473 FETCH party_site_id_csr INTO l_sales_transaction_rec.sold_to_party_site_id;
4474 CLOSE party_site_id_csr;
4475
4476 l_sales_transaction_rec.ship_to_site_use_id := p_line_rec.ship_to_org_id;
4477 l_sales_transaction_rec.bill_to_site_use_id := p_line_rec.invoice_to_org_id;
4478 --l_sales_transaction_rec.uom_code:= NVL(p_line_rec.shipping_quantity_uom, p_line_rec.line_uom_code); -- Catch Weight ER : Moved this piece of code up
4479 l_sales_transaction_rec.amount := p_line_rec.selling_price * l_sales_transaction_rec.quantity;
4480 l_sales_transaction_rec.currency_code := p_line_rec.transactional_curr_code;
4481 l_sales_transaction_rec.inventory_item_id := p_line_rec.inventory_item_id;
4482 l_sales_transaction_rec.header_id := p_line_rec.header_id;
4483 l_sales_transaction_rec.line_id := p_line_rec.line_id;
4484 l_sales_transaction_rec.source_code := 'OM';
4485
4486 IF p_line_rec.line_category_code <> 'RETURN' THEN
4487 l_sales_transaction_rec.transfer_type := 'IN';
4488 ELSE
4489 l_sales_transaction_rec.transfer_type := 'OUT';
4490 END IF;
4491
4492 l_sales_transaction_rec.transaction_date := l_gl_date;
4493 l_sales_transaction_rec.org_id := p_line_rec.org_id;
4494 l_sales_transaction_rec.qp_list_header_id := p_ldets_rec.list_header_id;
4495
4496 write_conc_log('calling Create_Transaction');
4497
4498 OZF_SALES_TRANSACTIONS_PVT.Create_Transaction(p_api_version => 1.0
4499 ,p_init_msg_list => FND_API.G_FALSE
4500 ,p_commit => FND_API.G_FALSE
4501 ,p_validation_level => FND_API.G_VALID_LEVEL_FULL
4502 ,p_transaction_rec => l_sales_transaction_rec
4503 ,x_sales_transaction_id => l_sales_transaction_id
4504 ,x_return_status => x_return_status
4505 ,x_msg_data => l_msg_data
4506 ,x_msg_count => l_msg_count
4507 );
4508
4509 write_conc_log('Create_Transaction returns: ' || x_return_status);
4510 write_conc_log('l_sales_transaction_id: ' || l_sales_transaction_id);
4511
4512 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4513 RETURN;
4514 END IF;
4515 END IF; --IF l_gl_date IS NOT NULL THEN
4516
4517 --fix for bug # 5944862
4518 OPEN c_offer_info (p_ldets_rec.list_header_id);
4519 FETCH c_offer_info INTO l_offer_info;
4520 CLOSE c_offer_info;
4521
4522 --OPEN c_apply_discount(l_offer_info.offer_id, l_order_line_tbl(j).inventory_item_id);
4523 --changed this cursor to ozf_order_group_prod, since we have data inserted there due to pricing call.
4524 --TEST This for denorm queries
4525 OPEN c_apply_discount(l_offer_info.offer_id, p_line_rec.line_id);
4526 FETCH c_apply_discount INTO l_apply_discount;
4527 CLOSE c_apply_discount;
4528
4529 IF l_apply_discount = 'N' THEN
4530 write_conc_log('no discount since apply discount flag is unchecked: '|| p_line_rec.inventory_item_id);
4531 RETURN;
4532 END IF;
4533
4534 l_act_budgets_rec.act_budget_used_by_id := p_ldets_rec.list_header_id;
4535 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
4536 l_act_budgets_rec.budget_source_type := 'OFFR';
4537 l_act_budgets_rec.budget_source_id := p_ldets_rec.list_header_id;
4538 --nirprasa,12.2 If condition to handle null currency offers
4539 --else will work fine for Arrow's case as well.
4540 IF l_offer_info.transaction_currency_code IS NULL THEN
4541 l_act_budgets_rec.request_currency := p_line_rec.transactional_curr_code;
4542 l_act_budgets_rec.approved_in_currency := p_line_rec.transactional_curr_code;
4543 l_act_util_rec.plan_currency_code := p_line_rec.transactional_curr_code;
4544 ELSE
4545 l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
4546 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
4547 l_act_util_rec.plan_currency_code := p_line_rec.transactional_curr_code;
4548 END IF;
4549 --ninarasi: bug 15877269 - l_offer_info.transaction_currency_code will be NULL in case of a NULL currency offer.
4550 --So, changed it to offer_currency_code which is basically fund_request_curr_code from ozf_offers.
4551 l_act_util_rec.fund_request_currency_code := l_offer_info.offer_currency_code;
4552 --nirprasa,12.2
4553
4554 l_act_util_rec.list_line_id := p_ldets_rec.list_line_id;
4555 l_act_budgets_rec.request_date := SYSDATE;
4556 l_act_budgets_rec.status_code := 'APPROVED';
4557 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
4558 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
4559
4560 l_act_budgets_rec.approval_date := SYSDATE;
4561 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
4562 l_act_budgets_rec.justification := 'Offer adjustment before offer start date';
4563 l_act_budgets_rec.transfer_type := 'UTILIZED';
4564
4565 l_act_util_rec.utilization_type :='ADJUSTMENT';
4566 l_act_util_rec.product_level_type := 'PRODUCT';
4567 l_act_util_rec.adjustment_date := SYSDATE;
4568 --kdass: bug 15877269 - pass gl date since volume offer adjustment calculation is based on the gl date
4569 --which should be shipped or invoiced date of the order
4570 l_act_util_rec.gl_date := l_gl_date;
4571 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
4572 l_act_util_rec.ship_to_site_use_id := l_sales_transaction_rec.ship_to_site_use_id;
4573 l_act_util_rec.bill_to_site_use_id := l_sales_transaction_rec.bill_to_site_use_id;
4574
4575 l_act_util_rec.product_id := p_line_rec.inventory_item_id;
4576 l_act_util_rec.object_type :='ORDER';
4577 l_act_util_rec.object_id := p_line_rec.header_id;
4578 l_act_util_rec.order_line_id := p_line_rec.line_id;
4579 l_act_util_rec.price_adjustment_id := -1;
4580 l_act_util_rec.org_id := p_line_rec.org_id; --nirprasa, added for bug 7030415
4581
4582 OPEN c_cust_number (p_line_rec.header_id);
4583 FETCH c_cust_number INTO l_cust_number;
4584 CLOSE c_cust_number;
4585
4586 l_act_util_rec.billto_cust_account_id := l_cust_number;
4587
4588 IF l_offer_info.beneficiary_account_id IS NULL THEN
4589 l_act_util_rec.cust_account_id := l_cust_number;
4590 END IF;
4591
4592 --For booked orders get the total volume and the discount based on the
4593 --tiers then create the utilization
4594
4595 OPEN c_get_group(p_line_rec.line_id,p_ldets_rec.list_header_id);
4596 FETCH c_get_group INTO l_group_id,l_pbh_line_id,l_included_vol_flag;
4597 CLOSE c_get_group;
4598
4599 IF G_DEBUG THEN
4600 ozf_utility_pvt.debug_message(' l_group_id: '|| l_group_id );
4601 ozf_utility_pvt.debug_message(' l_pbh_line_id: '|| l_pbh_line_id );
4602 ozf_utility_pvt.debug_message(' l_included_vol_flag: '|| l_included_vol_flag );
4603 END IF;
4604 write_conc_log(' l_group_id: '|| l_group_id );
4605 write_conc_log(' l_pbh_line_id: '|| l_pbh_line_id );
4606 write_conc_log(' l_included_vol_flag: '|| l_included_vol_flag );
4607
4608 IF l_group_id is NULL OR l_pbh_line_id is NULL THEN
4609 RETURN;
4610 END IF;
4611
4612 OPEN c_market_option(p_ldets_rec.list_header_id,l_group_id);
4613 FETCH c_market_option INTO l_retroactive;
4614 CLOSE c_market_option;
4615
4616 OPEN c_discount_header(l_pbh_line_id);
4617 FETCH c_discount_header INTO l_discount_type,l_volume_type;
4618 CLOSE c_discount_header;
4619
4620 write_conc_log('l_retroactive: '||l_retroactive);
4621 write_conc_log('p_ldets_rec.list_header_id: '|| p_ldets_rec.list_header_id);
4622 write_conc_log('p_ldets_rec.list_line_id '|| p_ldets_rec.list_line_id);
4623 write_conc_log('p_line_rec.line_id: '|| p_line_rec.line_id);
4624 write_conc_log('p_line_rec.inventory_item_id '|| p_line_rec.inventory_item_id);
4625 write_conc_log('p_line_rec.header_id '|| p_line_rec.header_id);
4626
4627 OPEN c_order_adjustment_amt (p_line_rec.header_id, p_line_rec.line_id,
4628 p_line_rec.inventory_item_id, p_ldets_rec.list_header_id);
4629 FETCH c_order_adjustment_amt INTO l_adj_amount;
4630 CLOSE c_order_adjustment_amt;
4631
4632 write_conc_log('l_adj_amount : '||l_adj_amount);
4633 --12.2, multi-currency enhancement. added for Arrow's case
4634 /* IF l_offer_info.transaction_currency_code IS NOT NULL
4635 AND l_offer_info.transaction_currency_code <> p_line_rec.transactional_curr_code THEN
4636
4637 --Added for bug 7030415
4638 OPEN c_exchange_rate_type(p_line_rec.org_id);
4639 FETCH c_exchange_rate_type INTO l_conv_type;
4640 CLOSE c_exchange_rate_type;
4641
4642 ozf_utility_pvt.write_conc_log('order curr: ' || p_line_rec.transactional_curr_code);
4643 ozf_utility_pvt.write_conc_log('offer curr: ' || l_offer_info.transaction_currency_code);
4644 ozf_utility_pvt.write_conc_log('selling price: ' || p_line_rec.selling_price);
4645 ozf_utility_pvt.write_conc_log('l_conv_type: ' || l_conv_type);
4646
4647 --Since it is increased earned always so no change for
4648 ozf_utility_pvt.convert_currency (x_return_status => l_return_status
4649 ,p_conv_type => l_conv_type --7030415
4650 ,p_conv_date => OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
4651 ,p_from_currency => p_line_rec.transactional_curr_code
4652 ,p_to_currency => l_offer_info.transaction_currency_code
4653 ,p_from_amount => p_line_rec.unit_selling_price
4654 ,x_to_amount => l_conv_price
4655 ,x_rate => l_rate
4656 );
4657
4658 IF l_return_status = fnd_api.g_ret_sts_error THEN
4659 RAISE fnd_api.g_exc_error;
4660 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4661 RAISE fnd_api.g_exc_unexpected_error;
4662 END IF;
4663
4664 l_unit_selling_price := l_conv_price;
4665 write_conc_log ('selling price after currency conversion: ' || l_unit_selling_price);
4666
4667 END IF;
4668 --12.2 end*/
4669 ozf_utility_pvt.write_conc_log('CWWWWWWWWWWWWWWWW VOOOOO--> l_utilization_amount = '|| l_utilization_amount);
4670 ozf_utility_pvt.write_conc_log('CWWWWWWWWWWWWWWWW VOOOOO--> p_ldets_rec.order_qty_adj_amt = '|| p_ldets_rec.order_qty_adj_amt);
4671 ozf_utility_pvt.write_conc_log('CWWWWWWWWWWWWWWWW VOOOOO--> p_line_rec.priced_quantity = '|| p_line_rec.priced_quantity);
4672 ozf_utility_pvt.write_conc_log('CWWWWWWWWWWWWWWWW VOOOOO--> p_line_rec.line_quantity = '|| p_line_rec.line_quantity);
4673 ozf_utility_pvt.write_conc_log('CWWWWWWWWWWWWWWWW VOOOOO--> p_line_rec.shipping_quantity_uom = '|| p_line_rec.shipping_quantity_uom);
4674
4675 l_utilization_amount := p_ldets_rec.order_qty_adj_amt
4676 * NVL(p_line_rec.priced_quantity, ABS(p_line_rec.line_quantity))
4677 * SIGN(p_line_rec.line_quantity);
4678
4679 l_utilization_amount := - l_utilization_amount;
4680
4681 IF p_line_rec.line_category_code ='RETURN' THEN
4682 l_utilization_amount := - l_utilization_amount;
4683 END IF;
4684 --nirprasa 12.2 ER 8399134
4685 l_act_util_rec.plan_currency_code := l_act_budgets_rec.request_currency;
4686
4687 l_utilization_amount := NVL(l_utilization_amount,0) - NVL(l_adj_amount,0);
4688
4689 write_conc_log('l_utilization_amount : '||l_utilization_amount);
4690
4691 l_act_budgets_rec.request_amount := l_utilization_amount;
4692 l_act_budgets_rec.approved_amount := l_utilization_amount;
4693 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
4694
4695 IF l_utilization_amount > 0 THEN
4696 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
4697 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
4698 --nirprasa,ER 8399134
4699 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
4700 ELSE
4701 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
4702 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
4703 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
4704 END IF;
4705
4706 ----end of booked orders
4707
4708 write_conc_log('calling ozf_fund_adjustment_pvt.process_act_budgets');
4709
4710 IF l_utilization_amount <> 0 THEN
4711 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
4712 ,x_msg_count => l_msg_count
4713 ,x_msg_data => l_msg_data
4714 ,p_act_budgets_rec => l_act_budgets_rec
4715 ,p_act_util_rec => l_act_util_rec
4716 ,x_act_budget_id => l_act_budget_id
4717 );
4718
4719 write_conc_log('process_act_budgets returns: ' || x_return_status);
4720
4721 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4722 ROLLBACK TO PROC_VO_RESULT;
4723 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
4724 write_conc_log('Adjustment creation failed for offer: ' || p_ldets_rec.list_header_id);
4725 RETURN;
4726 ELSE
4727 volume_offer_adjustment(p_qp_list_header_id=> p_ldets_rec.list_header_id
4728 ,p_vol_off_type =>p_vol_off_type
4729 ,x_return_status=> x_return_status
4730 ,x_msg_count=> l_msg_count
4731 ,x_msg_data=> l_msg_data
4732 );
4733
4734 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4735 ozf_utility_pvt.write_conc_log ('volume adjustment Failed'
4736 || p_ldets_rec.list_header_id
4737 || ' SOURCE CODE '
4738 || p_adjIdByListHdrId(p_ldets_rec.list_header_id)
4739 || ' with the following Errors /'
4740 );
4741 ozf_utility_pvt.write_conc_log;
4742 fnd_msg_pub.initialize;
4743 RETURN;
4744 END IF;
4745 END IF;
4746 END IF;
4747
4748
4749
4750 x_return_status := l_return_status;
4751
4752 IF g_debug_flag = 'Y' THEN
4753 OZF_UTILITY_PVT.write_conc_log(l_full_name||': end');
4754 END IF;
4755
4756 EXCEPTION
4757 WHEN FND_API.G_EXC_ERROR THEN
4758 ROLLBACK TO PROC_VO_RESULT;
4759 x_return_status := FND_API.G_RET_STS_ERROR;
4760 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4761 ROLLBACK TO PROC_VO_RESULT;
4762 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4763 WHEN OTHERS THEN
4764 ROLLBACK TO PROC_VO_RESULT;
4765 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
4766 END Process_VO_Result;
4767
4768 ---------------------------------------------------------------------
4769 -- PROCEDURE
4770 -- Process_SSD_Result
4771 --
4772 -- PURPOSE
4773 -- This procedure process the pricing call result for SSD offer.
4774 -- It creates accruals based on the discount information.
4775 --
4776 -- PARAMETERS
4777 -- p_resale_batch_id IN NUMBER,
4778 -- p_line_tbl IN OZF_ORDER_PRICE_PVT.LINE_REC_TBL_TYPE,
4779 -- p_caller_type IN VARCHAR2,
4780 -- x_return_status OUT NOCOPY VARCHAR2
4781 --
4782 -- NOTES
4783 -- 1. Non-monetray accruals have not been considered. Should look INTO ldets.benefit_qty
4784 -- and ldets.benefit_uom for calculation.
4785 -- 2. We will not do third party accruals on tracing data
4786 --
4787 ---------------------------------------------------------------------
4788 PROCEDURE Process_SSD_Result(
4789 p_line_rec IN OZF_Adjustment_ext_PVT.LINE_REC_TYPE,
4790 p_ldets_rec IN qp_ldets_v%rowtype,
4791 p_adjIdByListHdrId IN OUT NOCOPY numberTbl,
4792 x_return_status OUT NOCOPY VARCHAR2
4793 )
4794 IS
4795
4796 CURSOR c_offer_info(p_list_header_id IN NUMBER) IS
4797 SELECT nvl(transaction_currency_code, fund_request_curr_code) offer_currency_code,
4798 transaction_currency_code,
4799 beneficiary_account_id,
4800 autopay_party_attr,
4801 autopay_party_id,
4802 description
4803 FROM ozf_offers off, qp_list_headers_all qp
4804 WHERE off.qp_list_header_id = p_list_header_id
4805 AND off.qp_list_header_id = qp.list_header_id;
4806
4807 CURSOR c_adj_info(p_list_line_id IN NUMBER) IS
4808 SELECT created_from_adjustments
4809 FROM ozf_offer_adjustment_lines
4810 WHERE list_line_id = p_list_line_id;
4811
4812 CURSOR c_cust_number(p_header_id IN NUMBER) IS
4813 SELECT cust.cust_account_id
4814 FROM hz_cust_acct_sites_all acct_site,
4815 hz_cust_site_uses_all site_use,
4816 hz_cust_accounts cust,
4817 oe_order_headers_all header
4818 WHERE header.header_id = p_header_id
4819 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
4820 AND acct_site.cust_account_id = cust.cust_account_id
4821 AND site_use.site_use_id = header.invoice_to_org_id;
4822
4823 CURSOR c_orig_order_adj_amt(p_order_line_id IN NUMBER,
4824 p_list_header_id IN NUMBER) IS
4825 SELECT SUM(plan_curr_amount)
4826 FROM ozf_funds_utilized_all_b
4827 WHERE plan_type = 'OFFR'
4828 AND plan_id = p_list_header_id
4829 AND order_line_id = p_order_line_id;
4830
4831 CURSOR c_order_line(p_order_line_id IN NUMBER) IS
4832 SELECT nvl(invoiced_quantity, nvl(shipped_quantity, 0)) quantity,
4833 ship_to_org_id,
4834 invoice_to_org_id
4835 FROM oe_order_lines_all
4836 WHERE line_id = p_order_line_id;
4837
4838 CURSOR c_order_adjustment_amt(p_object_id IN NUMBER,
4839 p_order_line_id IN NUMBER,
4840 p_prod_id IN NUMBER,
4841 p_list_header_id IN NUMBER,
4842 p_list_line_id IN NUMBER) IS
4843 SELECT SUM(plan_curr_amount)
4844 FROM ozf_funds_utilized_all_b
4845 WHERE plan_type = 'OFFR'
4846 AND plan_id = p_list_header_id
4847 AND list_line_id IN (SELECT from_list_line_id
4848 FROM ozf_offer_adj_rltd_lines
4849 START WITH to_list_line_id = p_list_line_id
4850 CONNECT BY PRIOR from_list_line_id = to_list_line_id
4851 UNION ALL
4852 SELECT to_list_line_id FROM ozf_offer_adj_rltd_lines WHERE to_list_line_id =p_list_line_id)
4853 AND object_type = 'ORDER'
4854 AND object_id = p_object_id
4855 AND order_line_id = p_order_line_id
4856 AND product_level_type = 'PRODUCT'
4857 AND product_id = p_prod_id
4858 AND utilization_type IN ('ADJUSTMENT', 'LEAD_ADJUSTMENT')
4859 AND adjustment_type_id in(-4,-5,-1);
4860
4861 -- get sites org id type
4862 CURSOR c_org_id(p_site_use_id IN NUMBER) IS
4863 SELECT org_id
4864 FROM hz_cust_site_uses_all
4865 WHERE site_use_id = p_site_use_id;
4866
4867 CURSOR c_sd_request_header_id(p_list_header_id IN NUMBER) IS
4868 SELECT request_header_id
4869 FROM ozf_sd_request_headers_all_b
4870 WHERE offer_id = p_list_header_id;
4871
4872 -- added for bug 7030415 get conversion type
4873 CURSOR c_get_conversion_type(p_org_id IN NUMBER) IS
4874 SELECT exchange_rate_type
4875 FROM ozf_sys_parameters_all
4876 WHERE org_id = p_org_id;
4877
4878
4879 l_api_name CONSTANT VARCHAR2(30) := 'Process_SSD_Result';
4880 l_full_name CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
4881 l_return_status VARCHAR2(30);
4882 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
4883 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
4884 l_offer_info c_offer_info%ROWTYPE;
4885 l_created_from_adjustments VARCHAR2(2);
4886 l_cust_number NUMBER;
4887 l_util_amount NUMBER;
4888 l_conv_util_amount NUMBER;
4889 l_orig_util_amount NUMBER;
4890 l_orig_order_qty NUMBER;
4891 l_ship_to_org_id NUMBER;
4892 l_invoice_to_org_id NUMBER;
4893 l_adj_amount NUMBER := 0;
4894 l_org_id NUMBER; -- site's lorg id
4895 l_order_org_id NUMBER;
4896 l_column_name VARCHAR2(15);
4897 l_stmt VARCHAR2(3000);
4898 c_purchase_price purchase_price_cursor_type;
4899 l_cost_price NUMBER := 0;
4900 l_exchange_rate_type VARCHAR2(30) := FND_API.G_MISS_CHAR;
4901 l_justification VARCHAR2(50);
4902 l_rate NUMBER;
4903 l_msg_count NUMBER;
4904 l_msg_data VARCHAR2 (2000) := NULL;
4905 l_act_budget_id NUMBER;
4906 -- Catch Weight ER
4907 l_cw_quantity NUMBER;
4908 l_cw_quantity_uom VARCHAR2(30);
4909 l_line_quantity NUMBER;
4910 l_fulfillment_base VARCHAR2(1);
4911 -- Catch Weight ER
4912 BEGIN
4913 -- Debug Message
4914 IF g_debug_flag = 'Y' THEN
4915 OZF_UTILITY_PVT.debug_message(l_full_name||': start');
4916 END IF;
4917
4918 x_return_status := FND_API.G_RET_STS_SUCCESS;
4919
4920 SAVEPOINT PROC_SSD_RESULT;
4921
4922 OPEN c_offer_info(p_ldets_rec.list_header_id);
4923 FETCH c_offer_info INTO l_offer_info;
4924 CLOSE c_offer_info;
4925
4926 l_act_budgets_rec.act_budget_used_by_id := p_ldets_rec.list_header_id;
4927 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
4928 l_act_budgets_rec.budget_source_type := 'OFFR';
4929 l_act_budgets_rec.budget_source_id := p_ldets_rec.list_header_id;
4930 l_act_util_rec.fund_request_currency_code := l_offer_info.offer_currency_code;
4931 l_act_budgets_rec.request_date := SYSDATE;
4932 l_act_budgets_rec.status_code := 'APPROVED';
4933 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
4934 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
4935
4936 l_act_budgets_rec.approval_date := SYSDATE;
4937 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
4938
4939 OPEN c_adj_info(p_ldets_rec.list_line_id);
4940 FETCH c_adj_info INTO l_created_from_adjustments;
4941 CLOSE c_adj_info;
4942
4943 IF l_created_from_adjustments = 'Y' THEN
4944 l_justification := 'Offer adjustment for new product';
4945 ELSE
4946 l_justification := 'OOffer adjustment before offer start date';
4947 END IF;
4948
4949 l_act_budgets_rec.justification := l_justification;
4950 l_act_budgets_rec.transfer_type := 'UTILIZED';
4951
4952 l_act_util_rec.utilization_type :='ADJUSTMENT';
4953 l_act_util_rec.product_level_type := 'PRODUCT';
4954 --nirprasa,ER 8399134 replace sysdate by OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
4955 l_act_util_rec.adjustment_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
4956 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
4957
4958 IF g_debug_flag = 'Y' THEN
4959 write_conc_log('order header id: ' || p_ldets_rec.list_header_id);
4960 write_conc_log('order line id: ' || p_line_rec.line_id);
4961 write_conc_log('inventory item id: ' || p_line_rec.inventory_item_id);
4962 END IF;
4963
4964 l_act_util_rec.product_id := p_line_rec.inventory_item_id;
4965 l_act_util_rec.object_type :='ORDER';
4966 l_act_util_rec.object_id := p_line_rec.header_id;
4967 l_act_util_rec.order_line_id := p_line_rec.line_id;
4968
4969 OPEN c_cust_number (p_line_rec.header_id);
4970 FETCH c_cust_number INTO l_cust_number;
4971 CLOSE c_cust_number;
4972
4973 l_act_util_rec.billto_cust_account_id := l_cust_number;
4974
4975 IF l_offer_info.beneficiary_account_id IS NULL THEN
4976 l_act_util_rec.cust_account_id := l_cust_number;
4977 END IF;
4978
4979 -- IF g_debug_flag = 'Y' THEN
4980 write_conc_log ('CWWWWWWWWWWWW SSD billto_cust_account_id: ' || l_act_util_rec.billto_cust_account_id);
4981 write_conc_log ('CWWWWWWWWWWWW SSD cust_account_id: ' || l_act_util_rec.cust_account_id);
4982 write_conc_log ('CWWWWWWWWWWWW SSD unit_list_price: ' || p_line_rec.unit_price);
4983 write_conc_log ('CWWWWWWWWWWWW SSD quantity: ' || p_line_rec.line_quantity);
4984 write_conc_log ('CWWWWWWWWWWWW SSD quantity: ' || p_ldets_rec.line_quantity);
4985 write_conc_log ('CWWWWWWWWWWWW SSD p_modified_discount: ' || p_ldets_rec.operand_value);
4986 write_conc_log ('CWWWWWWWWWWWW SSD p_arithmetic_operator: ' || p_ldets_rec.operand_calculation_code);
4987 -- END IF;
4988
4989 -- 7030415 , get the order's org_id to get the exchange rate.
4990 write_conc_log ('l_order_org_id: ' || p_line_rec.org_id);
4991 l_act_util_rec.org_id := p_line_rec.org_id;
4992 l_order_org_id := p_line_rec.org_id;
4993
4994 IF l_act_util_rec.cust_account_id IS NULL THEN
4995 IF l_offer_info.beneficiary_account_id IS NOT NULL THEN
4996 IF l_offer_info.autopay_party_attr <> 'CUSTOMER' AND l_offer_info.autopay_party_attr IS NOT NULL THEN
4997 --Added c_org_id for bugfix 6278466
4998 OPEN c_org_id (l_offer_info.autopay_party_id);
4999 FETCH c_org_id INTO l_org_id;
5000 CLOSE c_org_id;
5001 l_act_util_rec.org_id := l_org_id;
5002 END IF;
5003 END IF;
5004 END IF;
5005
5006 -- Make sure this value is assigned before call to process_pricing_result. It should be same
5007 --as NVL commented below
5008
5009 --p_ldets_rec.line_quantity := NVL(p_line_rec.priced_quantity, ABS(p_line_rec.quantity));
5010 --p_ldets_rec.line_quantity := p_ldets_rec.line_quantity
5011 -- * SIGN(p_line_rec.quantity);
5012 l_util_amount := p_ldets_rec.order_qty_adj_amt
5013 * p_ldets_rec.line_quantity* SIGN(p_line_rec.line_quantity);
5014
5015 --nirprasa 12.2 ER 8399134
5016 l_act_util_rec.plan_currency_code := l_act_budgets_rec.request_currency;
5017
5018 /*
5019 If you enter 5 for discount, then the following would result for the various discount types
5020 Amount = $5.00 off the price per unit
5021 Percent = 5% off the price per unit
5022 New Price = the new price per unit is $5.00
5023 Lumpsum = a flat $5.00 off an order for that product regardless of quantity
5024 --we will rely on pricing calculation instead of doing our own calculation before the ER
5025 */
5026
5027 --nirprasa,ER 8399134 for null currency offer the transaction currency will be order currency
5028 --all other cases, it will be offer currency(Arrows case included)
5029 --write_conc_log ('null currency offer?: ' || l_offer_info.transaction_currency_code);
5030 --CURRENCY CONVERSION IS NOT NEEDED SINCE WE HAVE ONLY
5031 --FILTERED ORDERS THAT MATCHED THE OFFER"S CURRENCY */
5032
5033 IF l_offer_info.transaction_currency_code IS NULL THEN
5034 l_act_util_rec.plan_currency_code := p_line_rec.transactional_curr_code;
5035 l_act_budgets_rec.request_currency := p_line_rec.transactional_curr_code;
5036 l_act_budgets_rec.approved_in_currency := p_line_rec.transactional_curr_code;
5037 l_util_amount := ozf_utility_pvt.currround(l_util_amount, p_line_rec.transactional_curr_code);
5038 ELSE
5039 l_act_util_rec.plan_currency_code := l_offer_info.transaction_currency_code;
5040 l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
5041 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
5042 l_util_amount := ozf_utility_pvt.currround(l_util_amount, l_offer_info.transaction_currency_code);
5043 END IF;
5044 --end ER 8399134
5045
5046 l_act_util_rec.list_line_id := p_ldets_rec.list_line_id;
5047
5048 OPEN c_sd_request_header_id(p_ldets_rec.list_header_id);
5049 FETCH c_sd_request_header_id INTO l_act_util_rec.reference_id;
5050 CLOSE c_sd_request_header_id;
5051
5052 l_act_util_rec.reference_type := 'SD_REQUEST';
5053
5054 --Populate Discount Amount, Discount Type, Discount Currency for SDR Offers
5055 l_act_util_rec.discount_amount := p_ldets_rec.operand_value;
5056 l_act_util_rec.discount_type := p_ldets_rec.operand_calculation_code;
5057
5058 IF g_debug_flag = 'Y' THEN
5059 ozf_utility_pvt.write_conc_log('l_act_util_rec.discount_amount = ' || l_act_util_rec.discount_amount);
5060 ozf_utility_pvt.write_conc_log('l_act_util_rec.discount_type = ' || l_act_util_rec.discount_type);
5061 ozf_utility_pvt.write_conc_log('l_act_budgets_rec.request_currency = ' || l_act_budgets_rec.request_currency);
5062 END IF;
5063
5064 MO_GLOBAL.set_policy_context('S', l_order_org_id);
5065 l_column_name := FND_PROFILE.VALUE('OZF_ITEM_COST_COLUMN');
5066
5067 IF l_column_name IS NOT NULL AND l_column_name <> FND_API.G_MISS_CHAR THEN
5068 l_stmt := 'SELECT ' || l_column_name ||' FROM oe_order_lines_all WHERE line_id = :1 AND org_id = :2';
5069 IF g_debug_flag = 'Y' THEN
5070 ozf_utility_pvt.write_conc_log('Query to obtain purchase price '||l_stmt);
5071 END IF;
5072
5073 OPEN c_purchase_price FOR l_stmt using p_line_rec.line_id, l_order_org_id;
5074 FETCH c_purchase_price INTO l_cost_price;
5075 CLOSE c_purchase_price;
5076 END IF;
5077
5078
5079 IF (l_cost_price = -1) THEN
5080 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_debug_low) THEN
5081 fnd_message.set_name('OZF', 'OZF_COST_PRICE_NOT_FOUND');
5082 FND_MESSAGE.Set_Token('OFFR',l_offer_info.description); --OR LIST_HEADER_ID?
5083 FND_MESSAGE.Set_Token('ORDER',p_line_rec.header_id);
5084 FND_MESSAGE.Set_Token('ITEM',p_line_rec.inventory_item_id);
5085 FND_MESSAGE.Set_Token('TEXT',sqlerrm);
5086 fnd_msg_pub.add;
5087 END IF;
5088 RETURN;
5089 END IF;
5090
5091 IF G_DEBUG THEN
5092 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ l_cost_price = ' || l_cost_price);
5093 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_ldets_rec.line_quantity = ' || p_ldets_rec.line_quantity);
5094 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.line_quantity = ' || p_line_rec.line_quantity);
5095 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ l_arithmetic_operator = ' || l_act_util_rec.discount_type);
5096 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ l_operand = ' || p_ldets_rec.operand_value);
5097 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.priced_quantity = ' || p_line_rec.priced_quantity);
5098 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.order_quantity_uom = ' || p_line_rec.line_uom_code);
5099 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.shipping_quantity = ' || p_line_rec.shipping_quantity);
5100 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.shipping_quantity_uom = ' || p_line_rec.shipping_quantity_uom);
5101 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.shipping_quantity2 = ' || p_line_rec.shipping_quantity2);
5102 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.shipping_quantity_uom2 = ' || p_line_rec.shipping_quantity_uom2);
5103 ozf_utility_pvt.write_conc_log(' SSD D: adjust_accrual()_ p_line_rec.fulfillment_base = ' || p_line_rec.fulfillment_base);
5104 END IF;
5105
5106 -- Catch Weight ER - start
5107 -- Converting shipping quantity from shipping uom to order uom only when arithmatic op is not AMT, as in case of AMT, operand takes care of catch weight
5108 IF l_act_util_rec.discount_type <> 'AMT' THEN
5109
5110 /* OZF_UTILITY_PVT.get_catch_weight_quantity (
5111 p_inventory_item_id => p_line_rec.inventory_item_id,
5112 p_order_line_id => p_line_rec.line_id,
5113 x_return_status => l_return_status,
5114 x_cw_quantity => l_cw_quantity,
5115 x_cw_quantity_uom => l_cw_quantity_uom ); */
5116
5117 -- getting fulfillment_base from OE API. In case of performance issue can think of using fulfillment_base from existing cursor
5118 l_fulfillment_base := OE_DUAL_UOM_UTIL.get_fulfillment_base(p_line_rec.line_id) ;
5119
5120 --IF p_line_rec.fulfillment_base = 'S' THEN
5121 IF l_fulfillment_base = 'S' THEN
5122 l_cw_quantity := p_line_rec.shipping_quantity;
5123 l_cw_quantity_uom := p_line_rec.shipping_quantity_uom;
5124 ELSE
5125 l_cw_quantity := NVL(p_line_rec.shipping_quantity2, p_line_rec.shipping_quantity);
5126 l_cw_quantity_uom := NVL(p_line_rec.shipping_quantity_uom2, p_line_rec.shipping_quantity_uom);
5127 END IF;
5128
5129 -- Converting shipping quantity from shipping uom to order uom as cost price is as per order uom
5130 IF l_cw_quantity_uom IS NOT NULL AND l_cw_quantity_uom <> p_line_rec.line_uom_code THEN
5131 l_line_quantity := inv_convert.inv_um_convert(
5132 p_line_rec.inventory_item_id -- item_id
5133 ,NULL -- precision
5134 ,l_cw_quantity -- from_quantity
5135 ,l_cw_quantity_uom -- from_unit
5136 ,p_line_rec.line_uom_code -- to_unit
5137 ,NULL -- from_name
5138 ,NULL -- to_name
5139 );
5140 ozf_utility_pvt.write_conc_log(' Catch Weight D: adjust_accrual()_ l_line_quantity = ' || l_line_quantity);
5141 END IF;
5142 END IF;
5143 -- Catch Weight ER - end
5144 IF l_act_util_rec.discount_type = 'AMT' THEN
5145 l_act_util_rec.discount_amount_currency_code := l_act_budgets_rec.request_currency;
5146 l_util_amount := (NVL(p_ldets_rec.operand_value, 0)) * NVL(p_line_rec.priced_quantity, ABS(p_line_rec.line_quantity))
5147 * SIGN(p_line_rec.line_quantity);
5148 ELSIF l_act_util_rec.discount_type = '%' THEN
5149 l_util_amount := (NVL(p_ldets_rec.operand_value, 0)) * l_cost_price / 100 * (l_line_quantity -- (NVL(p_line_rec.priced_quantity, ABS(p_line_rec.line_quantity)) -- Catch Weight
5150 * SIGN(p_line_rec.line_quantity));
5151 ELSIF l_act_util_rec.discount_type = 'UNITPRICE' THEN
5152 l_act_util_rec.discount_amount_currency_code := l_act_budgets_rec.request_currency;
5153 l_util_amount := (l_cost_price - (NVL(p_ldets_rec.operand_value, 0))) * (l_line_quantity -- (NVL(p_line_rec.priced_quantity, ABS(p_line_rec.line_quantity)) -- Catch Weight
5154 * SIGN(p_line_rec.line_quantity));
5155 ELSIF l_act_util_rec.discount_type = 'LUMPSUM' THEN
5156 l_util_amount := NVL(p_ldets_rec.operand_value, 0);
5157 END IF;
5158
5159 write_conc_log ('adjustment amount: ' || l_util_amount);
5160
5161 --populate cost_price and cost_price_currency_code columns for SSD batch
5162 l_act_util_rec.cost_price := l_cost_price;
5163 l_act_util_rec.cost_price_currency_code := l_act_budgets_rec.request_currency;
5164
5165 l_ship_to_org_id := NULL;
5166 l_invoice_to_org_id := NULL;
5167
5168 -- handle RMA order to fix bug 5147399.
5169 --NOT SURE IF THIS CODE IS NEEDED ANYMORE
5170 -- Just negation should do AS WRITTEN AFTER THIS COMMENTED CODE*/
5171
5172 /*IF p_line_rec.line_category_code ='RETURN' THEN
5173 IF p_line_rec.reference_line_id is NOT NULL THEN
5174 OPEN c_orig_order_adj_amt (p_line_rec.reference_line_id,p_ldets_rec.list_header_id);
5175 FETCH c_orig_order_adj_amt INTO l_orig_util_amount;
5176 CLOSE c_orig_order_adj_amt;
5177
5178 --kdass 24-AUG-2006 fix for bug 5485172
5179 OPEN c_order_line (p_line_rec.reference_line_id);
5180 FETCH c_order_line INTO l_orig_order_qty,l_ship_to_org_id,
5181 l_invoice_to_org_id;
5182 CLOSE c_order_line;
5183
5184 write_conc_log ('l_orig_util_amount: ' || l_orig_util_amount);
5185 write_conc_log ('l_orig_order_qty: ' || l_orig_order_qty);
5186
5187 IF l_orig_order_qty = 0 THEN
5188 write_conc_log ('l_orig_order_qty is 0, exit loop');
5189 GOTO l_endoforderloop;
5190 END IF;
5191
5192 --calculate utilization amount in proportion of the number of items returned
5193 l_util_amount := l_orig_util_amount / l_orig_order_qty * p_line_rec.quantity;
5194
5195 write_conc_log ('l_util_amount: ' || l_util_amount);
5196
5197 IF l_util_amount > l_orig_util_amount THEN
5198 l_util_amount := l_orig_util_amount;
5199 write_conc_log ('greater than orig amount - l_util_amount: ' || l_util_amount);
5200 END IF;
5201
5202 END IF;
5203
5204 l_util_amount := - l_util_amount;
5205 write_conc_log ('adjustment amount for RMA: ' || l_util_amount);
5206
5207 END IF; -- l_order_line_tbl(j).line_category_code ='RETURN'*/
5208
5209 IF p_line_rec.line_category_code = 'RETURN' THEN
5210 IF g_debug_flag = 'Y' THEN
5211 ozf_utility_pvt.write_conc_log ( ' LINE IS RETURN ');
5212 END IF;
5213 l_util_amount := - l_util_amount;
5214 END IF;
5215
5216 l_ship_to_org_id := p_line_rec.ship_to_org_id;
5217 l_invoice_to_org_id := p_line_rec.invoice_to_org_id;
5218 IF l_ship_to_org_id IS NULL THEN
5219 OPEN c_order_line (p_line_rec.line_id);
5220 FETCH c_order_line INTO l_orig_order_qty, l_ship_to_org_id, l_invoice_to_org_id;
5221 CLOSE c_order_line;
5222 END IF;
5223
5224 l_act_util_rec.ship_to_site_use_id := l_ship_to_org_id;
5225 l_act_util_rec.bill_to_site_use_id := l_invoice_to_org_id;
5226
5227 --kdass 20-JUL-05 Bug 4489233 - gets the previous adjusted amount for the order line
5228 OPEN c_order_adjustment_amt (p_line_rec.header_id, p_line_rec.line_id, p_line_rec.inventory_item_id,
5229 p_ldets_rec.list_header_id,p_ldets_rec.list_line_id);
5230 FETCH c_order_adjustment_amt INTO l_adj_amount;
5231 CLOSE c_order_adjustment_amt;
5232
5233 write_conc_log ('l_adj_amount : '||l_adj_amount);
5234 l_util_amount := NVL(l_util_amount,0) - NVL(l_adj_amount,0);
5235 write_conc_log ('remaining adjustment amount: ' || l_util_amount);
5236
5237 IF l_util_amount > 0 THEN
5238 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
5239 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
5240 --nirprasa,ER 8399134
5241 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
5242 ELSE
5243 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
5244 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
5245 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
5246 END IF;
5247
5248
5249 IF l_util_amount <> 0 THEN
5250
5251 l_act_budgets_rec.request_amount := l_util_amount;
5252 l_act_budgets_rec.approved_amount := l_util_amount;
5253 write_conc_log(l_full_name || ': ozf_fund_adjustment_pvt.process_act_budgets');
5254
5255 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
5256 ,x_msg_count => l_msg_count
5257 ,x_msg_data => l_msg_data
5258 ,p_act_budgets_rec => l_act_budgets_rec
5259 ,p_act_util_rec => l_act_util_rec
5260 ,x_act_budget_id => l_act_budget_id
5261 );
5262
5263 write_conc_log('process_act_budgets returns: ' || x_return_status);
5264 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5265 ROLLBACK TO PROC_SSD_RESULT;
5266 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5267 write_conc_log('Adjustment creation failed for offer: ' || p_ldets_rec.list_header_id);
5268 RETURN;
5269 END IF;
5270 END IF;
5271 write_conc_log('Process_SSD_Result returns: ' || x_return_status);
5272 x_return_status := l_return_status;
5273
5274 IF g_debug_flag = 'Y' THEN
5275 OZF_UTILITY_PVT.write_conc_log(l_full_name||': end');
5276 END IF;
5277
5278 EXCEPTION
5279 WHEN FND_API.G_EXC_ERROR THEN
5280 ROLLBACK TO PROC_SSD_RESULT;
5281 x_return_status := FND_API.G_RET_STS_ERROR;
5282 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5283 ROLLBACK TO PROC_SSD_RESULT;
5284 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5285 WHEN OTHERS THEN
5286 ROLLBACK TO PROC_SSD_RESULT;
5287 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5288 END Process_SSD_Result;
5289 ---------------------------------------------------------------------
5290 -- PROCEDURE
5291 -- Process_Result
5292 --
5293 -- PURPOSE
5294 -- This procedure process the pricing call result for NON SSD/Volume offer.
5295 -- It creates accruals based on the discount information.
5296 --
5297 -- PARAMETERS
5298 -- p_resale_batch_id IN NUMBER,
5299 -- p_line_tbl IN OZF_ORDER_PRICE_PVT.LINE_REC_TBL_TYPE,
5300 -- p_caller_type IN VARCHAR2,
5301 -- x_return_status OUT NOCOPY VARCHAR2
5302 --
5303 -- NOTES
5304 -- 1. Non-monetray accruals have not been considered. Should look INTO ldets.benefit_qty
5305 -- and ldets.benefit_uom for calculation.
5306 -- 2. We will not do third party accruals on tracing data
5307 --
5308 ---------------------------------------------------------------------
5309 PROCEDURE Process_Result(
5310 p_line_rec IN OZF_Adjustment_ext_PVT.LINE_REC_TYPE,
5311 p_ldets_rec IN qp_ldets_v%rowtype,
5312 p_adjIdByListHdrId IN OUT NOCOPY numberTbl,
5313 x_return_status OUT NOCOPY VARCHAR2
5314 )
5315 IS
5316
5317 CURSOR c_offer_info(p_list_header_id IN NUMBER) IS
5318 SELECT nvl(transaction_currency_code, fund_request_curr_code) offer_currency_code,
5319 transaction_currency_code,
5320 beneficiary_account_id,
5321 autopay_party_attr,
5322 autopay_party_id
5323 FROM ozf_offers
5324 WHERE qp_list_header_id = p_list_header_id;
5325
5326 CURSOR c_adj_info(p_list_line_id IN NUMBER) IS
5327 SELECT created_from_adjustments
5328 FROM ozf_offer_adjustment_lines
5329 WHERE list_line_id = p_list_line_id;
5330
5331 CURSOR c_cust_number(p_header_id IN NUMBER) IS
5332 SELECT cust.cust_account_id
5333 FROM hz_cust_acct_sites_all acct_site,
5334 hz_cust_site_uses_all site_use,
5335 hz_cust_accounts cust,
5336 oe_order_headers_all header
5337 WHERE header.header_id = p_header_id
5338 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
5339 AND acct_site.cust_account_id = cust.cust_account_id
5340 AND site_use.site_use_id = header.invoice_to_org_id;
5341
5342 CURSOR c_orig_order_adj_amt(p_order_line_id IN NUMBER,
5343 p_list_header_id IN NUMBER) IS
5344 SELECT SUM(plan_curr_amount)
5345 FROM ozf_funds_utilized_all_b
5346 WHERE plan_type = 'OFFR'
5347 AND plan_id = p_list_header_id
5348 AND order_line_id = p_order_line_id;
5349
5350 CURSOR c_order_line(p_order_line_id IN NUMBER) IS
5351 SELECT nvl(invoiced_quantity, nvl(shipped_quantity, 0)) quantity,
5352 ship_to_org_id,
5353 invoice_to_org_id
5354 FROM oe_order_lines_all
5355 WHERE line_id = p_order_line_id;
5356
5357 CURSOR c_order_adjustment_amt(p_object_id IN NUMBER,
5358 p_order_line_id IN NUMBER,
5359 p_prod_id IN NUMBER,
5360 p_list_header_id IN NUMBER,
5361 p_list_line_id IN NUMBER) IS
5362 SELECT SUM(plan_curr_amount)
5363 FROM ozf_funds_utilized_all_b
5364 WHERE plan_type = 'OFFR'
5365 AND plan_id = p_list_header_id
5366 AND list_line_id IN (SELECT from_list_line_id
5367 FROM ozf_offer_adj_rltd_lines
5368 START WITH to_list_line_id = p_list_line_id
5369 CONNECT BY PRIOR from_list_line_id = to_list_line_id
5370 UNION ALL
5371 SELECT to_list_line_id FROM ozf_offer_adj_rltd_lines where to_list_line_id =p_list_line_id)
5372 AND object_type = 'ORDER'
5373 AND object_id = p_object_id
5374 AND order_line_id = p_order_line_id
5375 AND product_level_type = 'PRODUCT'
5376 AND product_id = p_prod_id
5377 AND utilization_type IN ('ADJUSTMENT', 'LEAD_ADJUSTMENT')
5378 AND adjustment_type_id in(-4,-5,-1);
5379
5380 -- get sites org id type
5381 CURSOR c_org_id(p_site_use_id IN NUMBER) IS
5382 SELECT org_id
5383 FROM hz_cust_site_uses_all
5384 WHERE site_use_id = p_site_use_id;
5385
5386
5387 l_api_name CONSTANT VARCHAR2(30) := 'Process_Result';
5388 l_full_name CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
5389 l_return_status VARCHAR2(30);
5390 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
5391 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
5392 l_offer_info c_offer_info%ROWTYPE;
5393 l_created_from_adjustments VARCHAR2(2);
5394 l_cust_number NUMBER;
5395 l_util_amount NUMBER;
5396 l_orig_util_amount NUMBER;
5397 l_orig_order_qty NUMBER;
5398 l_ship_to_org_id NUMBER;
5399 l_invoice_to_org_id NUMBER;
5400 l_adj_amount NUMBER := 0;
5401 l_org_id NUMBER; -- site's lorg id
5402 l_justification VARCHAR2(50);
5403 l_msg_count NUMBER;
5404 l_msg_data VARCHAR2 (2000) := NULL;
5405 l_act_budget_id NUMBER;
5406 BEGIN
5407 -- Debug Message
5408 IF g_debug_flag = 'Y' THEN
5409 OZF_UTILITY_PVT.debug_message(l_full_name||': start');
5410 END IF;
5411
5412 x_return_status := FND_API.G_RET_STS_SUCCESS;
5413
5414 SAVEPOINT PROC_RESULT;
5415
5416 IF g_debug_flag = 'Y' THEN
5417 write_conc_log('List header id: ' || p_ldets_rec.list_header_id);
5418 END IF;
5419
5420 OPEN c_offer_info(p_ldets_rec.list_header_id);
5421 FETCH c_offer_info INTO l_offer_info;
5422 CLOSE c_offer_info;
5423
5424 l_act_budgets_rec.act_budget_used_by_id := p_ldets_rec.list_header_id;
5425 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
5426 l_act_budgets_rec.budget_source_type := 'OFFR';
5427 l_act_budgets_rec.budget_source_id := p_ldets_rec.list_header_id;
5428 l_act_util_rec.fund_request_currency_code := l_offer_info.offer_currency_code;
5429 l_act_budgets_rec.request_date := SYSDATE;
5430 l_act_budgets_rec.status_code := 'APPROVED';
5431 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
5432 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
5433
5434 l_act_budgets_rec.approval_date := SYSDATE;
5435 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
5436
5437 OPEN c_adj_info(p_ldets_rec.list_line_id);
5438 FETCH c_adj_info INTO l_created_from_adjustments;
5439 CLOSE c_adj_info;
5440
5441 IF l_created_from_adjustments = 'Y' THEN
5442 l_justification := 'Offer adjustment for new product';
5443 ELSE
5444 l_justification := 'OOffer adjustment before offer start date';
5445 END IF;
5446
5447 l_act_budgets_rec.justification := l_justification;
5448 l_act_budgets_rec.transfer_type := 'UTILIZED';
5449
5450 l_act_util_rec.utilization_type :='ADJUSTMENT';
5451 l_act_util_rec.product_level_type := 'PRODUCT';
5452 --nirprasa,ER 8399134 replace sysdate by OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
5453 l_act_util_rec.adjustment_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
5454 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
5455
5456 IF g_debug_flag = 'Y' THEN
5457 write_conc_log('List header id: ' || p_ldets_rec.list_header_id);
5458 write_conc_log('order header id: ' || p_line_rec.header_id);
5459 write_conc_log('order line id: ' || p_line_rec.line_id);
5460 write_conc_log('inventory item id: ' || p_line_rec.inventory_item_id);
5461 END IF;
5462
5463 l_act_util_rec.product_id := p_line_rec.inventory_item_id;
5464 l_act_util_rec.object_type :='ORDER';
5465 l_act_util_rec.object_id := p_line_rec.header_id;
5466 l_act_util_rec.order_line_id := p_line_rec.line_id;
5467
5468 OPEN c_cust_number (p_line_rec.header_id);
5469 FETCH c_cust_number INTO l_cust_number;
5470 CLOSE c_cust_number;
5471
5472 l_act_util_rec.billto_cust_account_id := l_cust_number;
5473
5474 IF g_debug_flag = 'Y' THEN
5475 write_conc_log('l_cust_number: ' || l_cust_number);
5476 write_conc_log('l_offer_info.beneficiary_account_id: ' || l_offer_info.beneficiary_account_id);
5477 END IF;
5478
5479 IF l_offer_info.beneficiary_account_id IS NULL THEN
5480 l_act_util_rec.cust_account_id := l_cust_number;
5481 END IF;
5482
5483 -- IF g_debug_flag = 'Y' THEN
5484 write_conc_log ('CWWWWWWWWWWWWWWW AACR billto_cust_account_id: ' || l_act_util_rec.billto_cust_account_id);
5485 write_conc_log ('CWWWWWWWWWWWWWWW AACR cust_account_id: ' || l_act_util_rec.cust_account_id);
5486 write_conc_log ('CWWWWWWWWWWWWWWW AACR unit_list_price: ' || p_line_rec.unit_price);
5487 write_conc_log ('CWWWWWWWWWWWWWWW AACR selling_price: ' || p_line_rec.SELLING_PRICE);
5488 write_conc_log ('CWWWWWWWWWWWWWWW AACR quantity: ' || p_line_rec.line_quantity);
5489 write_conc_log ('CWWWWWWWWWWWWWWW AACR quantity: ' || p_ldets_rec.line_quantity);
5490 write_conc_log ('CWWWWWWWWWWWWWWW AACR p_modified_discount: ' || p_ldets_rec.operand_value);
5491 write_conc_log ('CWWWWWWWWWWWWWWW AACR p_modified_discount: ' || p_ldets_rec.operand_value);
5492 write_conc_log ('CWWWWWWWWWWWWWWW AACR order_qty_adj_amt: ' || p_ldets_rec.order_qty_adj_amt);
5493 -- END IF;
5494
5495 -- 7030415 , get the order's org_id to get the exchange rate.
5496 write_conc_log ('l_order_org_id: ' || p_line_rec.org_id);
5497 l_act_util_rec.org_id := p_line_rec.org_id;
5498
5499 IF l_act_util_rec.cust_account_id IS NULL THEN
5500 IF l_offer_info.beneficiary_account_id IS NOT NULL THEN
5501 IF l_offer_info.autopay_party_attr <> 'CUSTOMER' AND l_offer_info.autopay_party_attr IS NOT NULL THEN
5502 --Added c_org_id for bugfix 6278466
5503 OPEN c_org_id (l_offer_info.autopay_party_id);
5504 FETCH c_org_id INTO l_org_id;
5505 CLOSE c_org_id;
5506 l_act_util_rec.org_id := l_org_id;
5507 END IF;
5508 END IF;
5509 END IF;
5510
5511 --verify if its assigned? before call to process_pricing_results
5512 --p_ldets_rec.line_quantity := NVL(p_line_rec.priced_quantity, ABS(p_line_rec.quantity));
5513 --p_ldets_rec.line_quantity := p_ldets_rec.line_quantity
5514 -- * SIGN(p_line_rec.quantity);
5515 ozf_utility_pvt.write_conc_log('Catch Weight ADJ AACR --> p_ldets_rec.order_qty_adj_amt = '|| p_ldets_rec.order_qty_adj_amt);
5516 ozf_utility_pvt.write_conc_log('Catch Weight ADJ AACR --> p_line_rec.priced_quantity = '|| p_line_rec.priced_quantity);
5517 ozf_utility_pvt.write_conc_log('Catch Weight ADJ AACR --> p_line_rec.line_quantity = '|| p_line_rec.line_quantity);
5518 ozf_utility_pvt.write_conc_log('Catch Weight ADJ AACR --> p_line_rec.shipping_quantity_uom = '|| p_line_rec.shipping_quantity_uom);
5519 l_util_amount := p_ldets_rec.order_qty_adj_amt
5520 * NVL(p_line_rec.priced_quantity, ABS(p_line_rec.line_quantity))
5521 * SIGN(p_line_rec.line_quantity);
5522
5523 l_util_amount := - l_util_amount;
5524 --nirprasa 12.2 ER 8399134
5525 l_act_util_rec.plan_currency_code := l_act_budgets_rec.request_currency;
5526
5527 /*
5528 If you enter 5 for discount, then the following would result for the various discount types
5529 Amount = $5.00 off the price per unit
5530 Percent = 5% off the price per unit
5531 New Price = the new price per unit is $5.00
5532 Lumpsum = a flat $5.00 off an order for that product regardless of quantity
5533 --we will rely on pricing calculation instead of doing our own calculation before the ER
5534 */
5535
5536 --nirprasa,ER 8399134 for null currency offer the transaction currency will be order currency
5537 --all other cases, it will be offer currency(Arrows case included)
5538 write_conc_log ('null currency offer?: ' || l_offer_info.transaction_currency_code);
5539 --CURRENCY CONVERSION IS NOT NEEDED SINCE WE HAVE ONLY
5540 --FILTERED ORDERS THAT MATCHED THE OFFER"S CURRENCY
5541
5542 IF l_offer_info.transaction_currency_code IS NULL THEN
5543 l_act_util_rec.plan_currency_code := p_line_rec.transactional_curr_code;
5544 l_act_budgets_rec.request_currency := p_line_rec.transactional_curr_code;
5545 l_act_budgets_rec.approved_in_currency := p_line_rec.transactional_curr_code;
5546 l_util_amount := ozf_utility_pvt.currround(l_util_amount, p_line_rec.transactional_curr_code);
5547 ELSE
5548 l_act_util_rec.plan_currency_code := l_offer_info.transaction_currency_code;
5549 l_act_budgets_rec.request_currency := l_offer_info.transaction_currency_code;
5550 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
5551 l_util_amount := ozf_utility_pvt.currround(l_util_amount, l_offer_info.transaction_currency_code);
5552 END IF;
5553 --end ER 8399134
5554
5555 l_act_util_rec.list_line_id := p_ldets_rec.list_line_id;
5556
5557 write_conc_log ('adjustment amount: ' || l_util_amount);
5558
5559 l_ship_to_org_id := NULL;
5560 l_invoice_to_org_id := NULL;
5561
5562 -- handle RMA order to fix bug 5147399.
5563 --NOT SURE IF THIS CODE IS NEEDED ANYMORE
5564 -- Just negation should do AS WRITTEN AFTER THIS COMMENTED CODE
5565
5566 IF p_line_rec.line_category_code ='RETURN' THEN
5567
5568 IF g_debug_flag = 'Y' THEN
5569 ozf_utility_pvt.write_conc_log ( ' LINE IS RETURN ');
5570 END IF;
5571
5572 IF p_line_rec.reference_line_id is NOT NULL THEN
5573 OPEN c_orig_order_adj_amt (p_line_rec.reference_line_id,p_ldets_rec.list_header_id);
5574 FETCH c_orig_order_adj_amt INTO l_orig_util_amount;
5575 CLOSE c_orig_order_adj_amt;
5576
5577 --kdass 24-AUG-2006 fix for bug 5485172
5578 /*OPEN c_order_line (p_line_rec.reference_line_id);
5579 FETCH c_order_line INTO l_orig_order_qty,l_ship_to_org_id,
5580 l_invoice_to_org_id;
5581 CLOSE c_order_line;
5582
5583 write_conc_log ('l_orig_util_amount: ' || l_orig_util_amount);
5584 write_conc_log ('l_orig_order_qty: ' || l_orig_order_qty);
5585
5586 IF l_orig_order_qty = 0 THEN
5587 write_conc_log ('l_orig_order_qty is 0, exit loop');
5588 ROLLBACK TO PROC_RESULT;
5589 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5590 RETURN;
5591 END IF;
5592
5593 --calculate utilization amount in proportion of the number of items returned
5594 l_util_amount := l_orig_util_amount / l_orig_order_qty * p_line_rec.quantity;
5595
5596 write_conc_log ('l_util_amount: ' || l_util_amount);
5597
5598 IF l_util_amount > l_orig_util_amount THEN
5599 l_util_amount := l_orig_util_amount;
5600 write_conc_log ('greater than orig amount - l_util_amount: ' || l_util_amount);
5601 END IF;*/
5602
5603 END IF;
5604
5605 l_util_amount := - l_util_amount;
5606 write_conc_log ('adjustment amount for RMA: ' || l_util_amount);
5607
5608 END IF; -- l_order_line_tbl(j).line_category_code ='RETURN'
5609
5610 l_ship_to_org_id := p_line_rec.ship_to_org_id;
5611 l_invoice_to_org_id := p_line_rec.invoice_to_org_id;
5612 IF l_ship_to_org_id IS NULL THEN
5613 OPEN c_order_line (p_line_rec.line_id);
5614 FETCH c_order_line INTO l_orig_order_qty, l_ship_to_org_id, l_invoice_to_org_id;
5615 CLOSE c_order_line;
5616 END IF;
5617
5618 l_act_util_rec.ship_to_site_use_id := l_ship_to_org_id;
5619 l_act_util_rec.bill_to_site_use_id := l_invoice_to_org_id;
5620
5621 --kdass 20-JUL-05 Bug 4489233 - gets the previous adjusted amount for the order line
5622 OPEN c_order_adjustment_amt (p_line_rec.header_id, p_line_rec.line_id, p_line_rec.inventory_item_id,
5623 p_ldets_rec.list_header_id, p_ldets_rec.list_line_id);
5624 FETCH c_order_adjustment_amt INTO l_adj_amount;
5625 CLOSE c_order_adjustment_amt;
5626
5627
5628 write_conc_log ('l_adj_amount : '||l_adj_amount);
5629
5630 l_util_amount := NVL(l_util_amount,0) - NVL(l_adj_amount,0);
5631 write_conc_log ('remaining adjustment amount: ' || l_util_amount);
5632
5633 IF l_util_amount > 0 THEN
5634 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
5635 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
5636 --nirprasa,ER 8399134
5637 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
5638 ELSE
5639 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
5640 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
5641 l_act_util_rec.exchange_rate_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
5642 END IF;
5643
5644
5645
5646 IF l_util_amount <> 0 THEN
5647
5648 l_act_budgets_rec.request_amount := l_util_amount;
5649 l_act_budgets_rec.approved_amount := l_util_amount;
5650 write_conc_log(l_full_name || ': ozf_fund_adjustment_pvt.process_act_budgets');
5651
5652 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
5653 ,x_msg_count => l_msg_count
5654 ,x_msg_data => l_msg_data
5655 ,p_act_budgets_rec => l_act_budgets_rec
5656 ,p_act_util_rec => l_act_util_rec
5657 ,x_act_budget_id => l_act_budget_id
5658 );
5659
5660 write_conc_log('process_act_budgets returns: ' || x_return_status);
5661 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5662 ROLLBACK TO PROC_RESULT;
5663 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5664 write_conc_log('Adjustment creation failed for offer: ' || p_ldets_rec.list_header_id);
5665 RETURN;
5666 END IF;
5667 END IF;
5668
5669
5670 write_conc_log('Process_Result returns: ' || x_return_status);
5671
5672 x_return_status := l_return_status;
5673
5674 IF g_debug_flag = 'Y' THEN
5675 OZF_UTILITY_PVT.write_conc_log(l_full_name||': end');
5676 END IF;
5677
5678 EXCEPTION
5679 WHEN FND_API.G_EXC_ERROR THEN
5680 ROLLBACK TO PROC_RESULT;
5681 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5682 RETURN;
5683 x_return_status := FND_API.G_RET_STS_ERROR;
5684 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5685 ROLLBACK TO PROC_RESULT;
5686 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5687 RETURN;
5688 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5689 WHEN OTHERS THEN
5690 ROLLBACK TO PROC_RESULT;
5691 p_adjIdByListHdrId.DELETE(p_ldets_rec.list_header_id);
5692 RETURN;
5693 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5694 END Process_Result;
5695 ---------------------------------------------------------------------
5696 -- PROCEDURE
5697 -- process_pricing_result
5698 --
5699 -- PURPOSE
5700 -- This procedure process the pricing call result. It creates accruals based
5701 -- on the discount information.
5702 --
5703 -- PARAMETERS
5704 -- p_header_id IN NUMBER,
5705 -- p_line_tbl IN OZF_Adjustment_ext_PVT.LINE_REC_TBL_TYPE,
5706 -- x_return_status OUT NOCOPY VARCHAR2
5707 --
5708 -- NOTES
5709 -- 1. Non-monetray accruals have not been considered. Should look INTO ldets.benefit_qty
5710 -- and ldets.benefit_uom for calculation.
5711
5712 ---------------------------------------------------------------------
5713 PROCEDURE Process_Pricing_Result(
5714 p_header_id IN NUMBER,
5715 p_line_tbl IN OZF_Adjustment_ext_PVT.LINE_REC_TBL_TYPE,
5716 p_adjIdByListHdrId IN OUT NOCOPY numberTbl,
5717 x_return_status OUT NOCOPY VARCHAR2
5718 )
5719 IS
5720
5721 CURSOR c_offer_info (p_list_header_id IN NUMBER) IS
5722 SELECT offer_type, volume_offer_type,
5723 custom_setup_id
5724 FROM ozf_offers
5725 WHERE qp_list_header_id = p_list_header_id;
5726
5727 CURSOR line_ldets_tbl_csr(p_index IN NUMBER) IS
5728 SELECT *
5729 FROM qp_ldets_v
5730 WHERE line_index = p_index
5731 ORDER BY list_line_id asc;
5732 --ORDER BY pricing_group_sequence;
5733
5734 TYPE line_ldets_tbl_type IS TABLE OF line_ldets_tbl_csr%rowtype
5735 INDEX BY binary_integer;
5736
5737 l_ldets_tbl ozf_adjustment_ext_pvt.LDETS_TBL_TYPE;
5738 l_ldets_rec qp_ldets_v%rowtype;
5739 l_line_rec ozf_adjustment_ext_pvt.LINE_REC_TBL_TYPE;
5740 l_line_id NUMBER := NULL;
5741 l_offer_info c_offer_info%ROWTYPE;
5742 l_api_name CONSTANT VARCHAR2(30) := 'Process_Pricing_Result';
5743 l_full_name CONSTANT VARCHAR2(60) := G_PKG_NAME ||'.'|| l_api_name;
5744 l_return_status VARCHAR2(30);
5745 l_object_type VARCHAR2(30);
5746 l_has_error BOOLEAN := FALSE;
5747 l_is_valid_offer BOOLEAN;
5748 l_act_budgets_rec OZF_ACTBUDGETS_PVT.act_budgets_rec_type;
5749 l_act_util_rec OZF_ACTBUDGETS_PVT.act_util_rec_type;
5750
5751
5752 BEGIN
5753 -- Debug Message
5754 IF g_debug_flag = 'Y' THEN
5755 OZF_UTILITY_PVT.write_conc_log(l_full_name||': start');
5756 END IF;
5757
5758 x_return_status := FND_API.G_RET_STS_SUCCESS;
5759
5760 SAVEPOINT PROC_PRIC_RESULT;
5761
5762 -- First check whether the order result collection EXISTS or not
5763 IF p_line_tbl.EXISTS(1) THEN
5764
5765 -- LOOP through the result to find if there is an error in the result.
5766 FOR i in 1..p_line_tbl.LAST LOOP
5767 l_has_error := p_line_tbl(i).pricing_status_code <> QP_PREQ_PUB.G_STATUS_NEW AND
5768 p_line_tbl(i).pricing_status_code <> QP_PREQ_PUB.G_STATUS_UNCHANGED AND
5769 p_line_tbl(i).pricing_status_code <> QP_PREQ_PUB.G_STATUS_UPDATED;
5770
5771 EXIT WHEN l_has_error;
5772 END LOOP;
5773
5774 IF l_has_error THEN
5775 -- IF there is an error for a line or lines, we need to UPDATE the whole order as error;
5776 -- nothing to UPDATE if it's FROM line.
5777
5778 ozf_utility_pvt.write_conc_log('order fails');
5779
5780 RETURN;
5781
5782 ELSE
5783 -- There is no error in the resulting. We need to process the result one by one.
5784
5785 For i in 1..p_line_tbl.LAST LOOP
5786
5787 IF p_line_tbl(i).line_type_code = 'LINE' THEN
5788
5789 -- IF g_debug_flag = 'Y' THEN
5790 write_conc_log('order header id: ' || p_line_tbl(i).header_id);
5791 write_conc_log('order line id: ' || p_line_tbl(i).line_id);
5792 write_conc_log('inventory item id: ' || p_line_tbl(i).inventory_item_id);
5793 write_conc_log('Line Index: ' || p_line_tbl(i).line_index);
5794 write_conc_log('shipping_quantity_uom: ' || p_line_tbl(i).shipping_quantity_uom);
5795 -- END IF;
5796
5797
5798 -- clear up the temparory result PL/SQL table
5799 IF l_ldets_tbl.EXISTS(1) THEN
5800 l_ldets_tbl.DELETE;
5801 END IF;
5802
5803 OPEN line_ldets_tbl_csr(p_line_tbl(i).line_index);
5804 FETCH line_ldets_tbl_csr BULK COLLECT INTO l_ldets_tbl;
5805 CLOSE line_ldets_tbl_csr;
5806
5807 IF l_ldets_tbl.EXISTS(1) THEN
5808 FOR k IN 1..l_ldets_tbl.LAST LOOP
5809 l_act_budgets_rec := NULL;
5810 l_act_util_rec := NULL;
5811
5812 -- Look in to list_line_type_code in view or CREATED_FROM_LIST_LINE_TYPE in tbl = 'DIS'
5813 -- IF applied_flag= 'Y' OR
5814 -- applied_flag= 'N' AND accrual_flag = 'Y' AND automatic_flag ='Y'THEN
5815 -- create a util_rec and act_budet_rec based on the discount
5816 -- END IF;
5817 -- call budget api
5818 -- Create an accrual for this accrual, pass in l_header_id as a refrence.
5819 -- IF CREATED_FROM_LIST_LINE_TYPE = 'PBH' Then
5820 -- do the same thing for each child line
5821 -- END IF;
5822
5823
5824 IF g_debug_flag = 'Y' THEN
5825 ozf_utility_pvt.write_conc_log(l_api_name||' >> qp_ldets_v (+)');
5826 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').list_header_id = '|| l_ldets_tbl(k).list_header_id);
5827 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').list_line_type_code = '|| l_ldets_tbl(k).list_line_type_code);
5828 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').applied_flag = '|| l_ldets_tbl(k).applied_flag);
5829 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').accrual_flag = '|| l_ldets_tbl(k).accrual_flag);
5830 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').automatic_flag = '|| l_ldets_tbl(k).automatic_flag);
5831 ozf_utility_pvt.write_conc_log('p_line_tbl('||i||').line_id = '|| p_line_tbl(i).line_id);
5832 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').list_line_id = '|| l_ldets_tbl(k).list_line_id);
5833 ozf_utility_pvt.write_conc_log(l_api_name||' >> qp_ldets_v (-)');
5834 END IF;
5835
5836 IF l_ldets_tbl(k).list_line_type_code IN ('CIE', 'DIS', 'IUE', 'OID', 'PLL', 'PMR', 'TSN','PBH') THEN
5837 -- create utilization based on an offer
5838
5839 -- only accrue for 1) TM offers,
5840 -- 2) No record should be present in oe_price_adjustments - taken care by perform_adj API (regular adj)
5841 -- 3) has a valid active adjustment i.e. a record exists in p_adjIdByListHdrId
5842 IF (l_ldets_tbl(k).applied_flag = 'Y' AND
5843 l_ldets_tbl(k).accrual_flag = 'N'
5844 )
5845 OR
5846 (l_ldets_tbl(k).accrual_flag = 'Y' AND
5847 l_ldets_tbl(k).automatic_flag = 'Y'
5848 )
5849 THEN
5850
5851 Is_Valid_Offer(p_list_header_id => l_ldets_tbl(k).list_header_id,
5852 p_list_line_id => l_ldets_tbl(k).list_line_id,
5853 p_line_id => p_line_tbl(i).line_id,
5854 p_object_type => l_object_type,
5855 x_result => l_is_valid_offer,
5856 x_return_status => l_return_status
5857 );
5858 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5859 RAISE FND_API.G_EXC_ERROR;
5860 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5861 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5862 END IF;
5863
5864 --l_ldets_tbl(k).line_quantity := NVL(p_line_tbl(i).priced_quantity, ABS(p_line_tbl(i).quantity));
5865
5866 IF g_debug_flag = 'Y' THEN
5867 IF l_is_valid_offer AND p_adjIdByListHdrId.EXISTS(l_ldets_tbl(k).list_header_id) THEN
5868 ozf_utility_pvt.write_conc_log(l_api_name||' >> Accrual for TM OFFR (+)');
5869 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').list_header_id = '|| l_ldets_tbl(k).list_header_id);
5870 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').order_qty_adj_amt = '|| l_ldets_tbl(k).order_qty_adj_amt);
5871 ozf_utility_pvt.write_conc_log('l_ldets_tbl('||k||').line_quantity = '|| l_ldets_tbl(k).line_quantity);
5872 ozf_utility_pvt.write_conc_log('order line priced_quantity = '|| p_line_tbl(i).priced_quantity);
5873 IF l_ldets_tbl(k).list_line_type_code = 'PLL' THEN
5874 ozf_utility_pvt.debug_message('order line unit_price = '|| p_line_tbl(i).unit_price);
5875 END IF;
5876 ozf_utility_pvt.write_conc_log(l_api_name||' >> Accrual for TM OFFR or PLL adjustment (-)');
5877 ELSE
5878 IF g_debug_flag = 'Y' THEN
5879 ozf_utility_pvt.write_conc_log('Not a TM offer OR No valid adjustments: offer id: ' || l_ldets_tbl(k).list_header_id);
5880 END IF;
5881 GOTO LABEL_FOR_NEXT_ITERATION;
5882 END IF;
5883 END IF;
5884
5885
5886
5887 IF l_is_valid_offer AND p_adjIdByListHdrId.EXISTS(l_ldets_tbl(k).list_header_id) THEN
5888
5889 OPEN c_offer_info(l_ldets_tbl(k).list_header_id);
5890 FETCH c_offer_info INTO l_offer_info;
5891 CLOSE c_offer_info;
5892
5893 --Bug fix 13448056 (check for adjusted list_line_id instead of list_header_id)
5894 --i.e l_adjIdByListLineId.EXISTS(l_ldets_tbl(k).list_line_id)
5895
5896 IF l_offer_info.offer_type = 'VOLUME_OFFER' AND l_ldets_tbl(k).list_line_type_code = 'PBH' THEN
5897 Process_VO_Result( p_line_rec => p_line_tbl(i),
5898 p_ldets_rec => l_ldets_tbl(k),
5899 p_adjIdByListHdrId => p_adjIdByListHdrId,
5900 p_vol_off_type => l_offer_info.volume_offer_type,
5901 x_return_status => l_return_status);
5902
5903 ELSIF l_offer_info.custom_setup_id=118 AND l_adjIdByListLineId.EXISTS(l_ldets_tbl(k).list_line_id) THEN
5904 Process_SSD_Result( p_line_rec => p_line_tbl(i),
5905 p_ldets_rec => l_ldets_tbl(k),
5906 p_adjIdByListHdrId => p_adjIdByListHdrId,
5907 x_return_status => l_return_status);
5908 ELSIF l_offer_info.offer_type = 'DEAL' OR
5909 (l_offer_info.offer_type <> 'VOLUME_OFFER' AND l_adjIdByListLineId.EXISTS(l_ldets_tbl(k).list_line_id)) THEN
5910 Process_Result( p_line_rec => p_line_tbl(i),
5911 p_ldets_rec => l_ldets_tbl(k),
5912 p_adjIdByListHdrId => p_adjIdByListHdrId,
5913 x_return_status => l_return_status);
5914 END IF;
5915
5916
5917
5918 END IF; -- END is valid offer
5919 END IF; -- END accrual flag
5920 END IF; -- END list type
5921 <<LABEL_FOR_NEXT_ITERATION>> --ER9447673
5922 NULL; --ER9447673
5923 END LOOP; -- END LOOP through ldets_lines
5924 END IF; -- END if ldets_line has nothing
5925
5926 END IF; -- END if current record is a line
5927 END LOOP; -- END LOOP through lines
5928 END IF; -- END of checking error
5929 END IF; -- END of EXISTS
5930
5931 x_return_status := l_return_status;
5932
5933 IF g_debug_flag = 'Y' THEN
5934 OZF_UTILITY_PVT.write_conc_log(l_full_name||': end');
5935 END IF;
5936
5937 EXCEPTION
5938 WHEN FND_API.G_EXC_ERROR THEN
5939 ROLLBACK TO PROC_PRIC_RESULT;
5940 x_return_status := FND_API.G_RET_STS_ERROR;
5941 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5942 ROLLBACK TO PROC_PRIC_RESULT;
5943 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5944 WHEN OTHERS THEN
5945 ROLLBACK TO PROC_PRIC_RESULT;
5946 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5947 END process_pricing_result;
5948
5949
5950 ---------------------------------------------------------------------
5951 -- PROCEDURE
5952 --
5953 --
5954 -- PURPOSE
5955 --
5956 -- PARAMETERS
5957 -- p_from_date IN DATE
5958 -- p_to_Date IN DATE
5959 -- p_qp_list_header_id IN NUMBER
5960 -- NOTES
5961 -- HISTORY
5962 -- 4/18/2002 Mumu Pande Create.
5963 -- 11/11/2002 mkothari Updated to handle adjustments for
5964 -- Multi Tier (Accrual and Off Invoice)
5965 -- Prom Goods,Order Value,Volume Offer
5966 -- and Trade Deal.
5967 -- 07/05/2005 feliu fix following issues
5968 -- 1. change logic to calculate for adjustment. calculate the total adjustment based on
5969 -- new discount and original discount when utilization is created from accrual engine.
5970 -- 2. change the adjusmtent calculation for NEWPRICE.
5971 -- 3. Add adjustment for promotional offer.
5972 ----------------------------------------------------------------------
5973 PROCEDURE perform_adjustment (
5974 p_from_date IN DATE,
5975 p_to_date IN DATE,
5976 p_qp_list_header_id IN NUMBER,
5977 p_offer_adjustment_id IN NUMBER,
5978 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
5979 p_commit IN VARCHAR2 := fnd_api.g_false,
5980 x_return_status OUT NOCOPY VARCHAR2,
5981 x_msg_count OUT NOCOPY NUMBER,
5982 x_msg_data OUT NOCOPY VARCHAR2
5983 ) IS
5984 l_act_budget_id NUMBER;
5985 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
5986 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
5987 l_return_status VARCHAR2 (1);
5988 l_util_amount NUMBER;
5989 l_api_name VARCHAR2 (50) := 'perform_adjustment';
5990 l_full_name CONSTANT VARCHAR2 (90) := g_pkg_name
5991 || '.'
5992 || l_api_name;
5993 l_to_date DATE := p_to_date + 0.99999;
5994 l_org_id NUMBER; -- := TO_NUMBER (SUBSTRB (USERENV ('CLIENT_INFO'), 1, 10)) ;
5995
5996 --kpatro 31-JUL-2006 bug 5375224 SQL ID# 19125146 - removed trunc from adjustment_date
5997 --for all cursors and added it to index OZF_FUNDS_UTILIZED_ALL_B_N24 to decrease the cost
5998 --and shared memory of the queries
5999 --nirprasa, 12.2 enhancement, replace amount with plan_curr_amount column.
6000 CURSOR c_bdadj_all_types IS
6001 SELECT util.utilization_id,
6002 util.object_type,
6003 util.object_id,
6004 util.order_line_id,
6005 util.product_id,
6006 util.billto_cust_account_id,
6007 util.cust_account_id,
6008 util.fund_id,
6009 util.plan_currency_code,
6010 util.currency_code,
6011 util.price_adjustment_id,
6012 --NULL,
6013 DECODE (oe.arithmetic_operator,
6014 -- julou 03/30/2007 fix bug 5849584 "original discount = 0" causes "divisor is 0" exception
6015 'NEWPRICE', DECODE(oe.adjusted_amount_per_pqty, 0, (ol.unit_selling_price - adjl.modified_discount) * ol.pricing_quantity, ((oe.operand - adjl.modified_discount) * plan_curr_amount /-oe.adjusted_amount_per_pqty)),
6016 '%', DECODE(oe.operand, 0, adjl.modified_discount * ol.unit_selling_price * ol.pricing_quantity / 100, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6017 'AMT', DECODE(oe.operand, 0, adjl.modified_discount * ol.pricing_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6018 'LUMPSUM', DECODE(oe.operand, 0, adjl.modified_discount, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)
6019 -- 'NEWPRICE', ((oe.operand - adjl.modified_discount) * amount /-oe.adjusted_amount_per_pqty),
6020 -- ((adjl.modified_discount - oe.operand) * amount / oe.operand)
6021 ) plan_curr_amount
6022 ,util.org_id
6023 ,util.ship_to_site_use_id
6024 ,util.bill_to_site_use_id
6025 ,util.reference_type
6026 ,util.reference_id
6027 ,util.exchange_rate_type
6028 FROM ozf_funds_utilized_all_b util,
6029 ozf_temp_eligibility temp,
6030 ozf_offer_adjustment_lines adjl,
6031 oe_order_lines_all ol,
6032 oe_price_adjustments oe
6033 WHERE util.plan_type = 'OFFR'
6034 AND product_id IS NOT NULL
6035 AND util.plan_id = p_qp_list_header_id
6036 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6037 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6038 -- yzhao 01/13/2006 fix bug 4939453 offer adjustment creates new list_line_id
6039 -- AND adjl.list_line_id = oe.list_line_id
6040 AND oe.list_line_id IN (SELECT from_list_line_id
6041 FROM ozf_offer_adj_rltd_lines adjr
6042 START WITH adjr.from_list_line_id = adjl.list_line_id
6043 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6044 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6045 )
6046 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6047 AND util.object_type = 'ORDER'
6048 AND util.price_adjustment_id = oe.price_adjustment_id
6049 AND oe.list_line_type_code <> 'PBH'
6050 AND adjustment_date BETWEEN p_from_date AND l_to_date
6051 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6052 AND ol.line_id = oe.line_id
6053
6054 UNION ALL
6055 --for third party accrual.
6056 SELECT util.utilization_id,
6057 util.object_type,
6058 util.object_id,
6059 util.order_line_id,
6060 util.product_id,
6061 util.billto_cust_account_id,
6062 util.cust_account_id,
6063 util.fund_id,
6064 util.plan_currency_code,
6065 util.currency_code,
6066 util.price_adjustment_id,
6067 --NULL,
6068 -- nirprasa 10/10/2011 Fixed Bug#13061780 ,This cursor was not taking care of different operand_types and zero operand.
6069 DECODE (oe.operand_calculation_code,
6070 --bug 13322965 - corrected formula for new price
6071 /*
6072 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount) * oe.priced_quantity, (oe.operand - adjl.modified_discount) * plan_curr_amount /-oe.operand)),
6073 */
6074 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount) * oe.priced_quantity, (oe.operand - adjl.modified_discount) * oe.priced_quantity)),
6075 '%', (DECODE(oe.operand, 0,adjl.modified_discount * oe.calculated_price * oe.priced_quantity / 100, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)),
6076 'AMT', (DECODE(oe.operand, 0,adjl.modified_discount * oe.priced_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)),
6077 'LUMPSUM', (DECODE(oe.operand, 0,adjl.modified_discount, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand))
6078 ) plan_curr_amount
6079 ,util.org_id
6080 ,util.ship_to_site_use_id
6081 ,util.bill_to_site_use_id
6082 ,util.reference_type
6083 ,util.reference_id
6084 ,util.exchange_rate_type
6085 FROM ozf_funds_utilized_all_b util,
6086 ozf_temp_eligibility temp,
6087 ozf_offer_adjustment_lines adjl,
6088 OZF_RESALE_ADJUSTMENTS_ALL oe
6089 WHERE util.plan_type = 'OFFR'
6090 AND product_id IS NOT NULL
6091 AND util.plan_id = p_qp_list_header_id
6092 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6093 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6094 AND oe.list_line_id IN (SELECT from_list_line_id -- = oe.list_line_id : Fix for bug 12660466
6095 FROM ozf_offer_adj_rltd_lines adjr
6096 START WITH adjr.from_list_line_id = adjl.list_line_id
6097 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6098 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6099 )
6100 AND util.price_adjustment_id = oe.resale_adjustment_id
6101 AND adjustment_date BETWEEN p_from_date AND l_to_date
6102 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6103 -- yzhao 01/13/2006 fix bug 4939453 offer adjustment creates new list_line_id
6104 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6105 AND util.object_type = 'TP_ORDER';
6106 -- kdass 01/31/2005 fix for bug 4129759 - handle backdated adjustments for multi-tier discounts
6107 /*
6108 UNION ALL
6109 SELECT util.utilization_id,
6110 util.object_type,
6111 util.object_id,
6112 util.order_line_id,
6113 util.product_id,
6114 util.billto_cust_account_id,
6115 util.cust_account_id,
6116 util.fund_id,
6117 util.plan_currency_code,
6118 assocs.price_adjustment_id,
6119 --NULL,
6120 DECODE (oe.arithmetic_operator,
6121 'NEWPRICE', ((oe.operand - adjl.modified_discount) * amount /-oe.adjusted_amount_per_pqty),
6122 ((adjl.modified_discount - oe.operand) * amount / oe.operand)
6123 ) amount
6124 FROM ozf_funds_utilized_all_b util,
6125 oe_price_adj_assocs assocs,
6126 oe_price_adjustments oe,
6127 ozf_offer_adjustment_lines adjl,
6128 ozf_temp_eligibility temp
6129 WHERE util.plan_id = p_qp_list_header_id
6130 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6131 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6132 AND util.plan_type = 'OFFR'
6133 AND util.price_adjustment_id = assocs.price_adjustment_id
6134 AND oe.price_adjustment_id = assocs.rltd_price_adj_id
6135 AND oe.adjusted_amount IS NOT NULL
6136 AND oe.list_line_id = adjl.list_line_id
6137 AND oe.operand <> adjl.modified_discount
6138 AND adjustment_date BETWEEN p_from_date AND l_to_date
6139 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT');
6140 --- (-1) is inserted in ozf_temp_eligibility for 'ALL' items, refer query above and query below
6141 */
6142 CURSOR c_bdadj_trade_deal IS
6143 SELECT util.utilization_id,
6144 util.object_type,
6145 util.object_id,
6146 util.order_line_id,
6147 util.product_id,
6148 util.billto_cust_account_id, -- yzhao: 11.5.10 added billto_cust_account_id
6149 util.cust_account_id,
6150 util.fund_id,
6151 util.plan_currency_code,
6152 util.currency_code,
6153 util.price_adjustment_id,
6154 --NULL,
6155 DECODE (oe.arithmetic_operator,
6156 -- julou 03/30/2007 fix bug 5849584 "original discount = 0" causes "divisor is 0" exception
6157 'NEWPRICE', DECODE(oe.adjusted_amount_per_pqty, 0, (ol.unit_selling_price - adjl.modified_discount) * ol.pricing_quantity, ((oe.operand - adjl.modified_discount) * plan_curr_amount /-oe.adjusted_amount_per_pqty)),
6158 '%', DECODE(oe.operand, 0, adjl.modified_discount * ol.unit_selling_price * ol.pricing_quantity / 100, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6159 'AMT', DECODE(oe.operand, 0, adjl.modified_discount * ol.pricing_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6160 'LUMPSUM', DECODE(oe.operand, 0, adjl.modified_discount, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)
6161 -- 'NEWPRICE', ((oe.operand - adjl.modified_discount) * amount /-oe.adjusted_amount_per_pqty),
6162 -- ((adjl.modified_discount - oe.operand) * amount / oe.operand)
6163 ) plan_curr_amount
6164 ,util.org_id
6165 ,util.ship_to_site_use_id
6166 ,util.bill_to_site_use_id
6167 ,util.reference_type
6168 ,util.reference_id
6169 ,util.exchange_rate_type
6170 FROM ozf_funds_utilized_all_b util,
6171 ozf_temp_eligibility temp,
6172 ozf_offer_adjustment_lines adjl,
6173 oe_order_lines_all ol,
6174 oe_price_adjustments oe
6175 WHERE util.plan_type = 'OFFR'
6176 AND product_id IS NOT NULL
6177 AND util.plan_id = p_qp_list_header_id
6178 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6179 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6180 -- kdass 31-MAR-2006 fix bug 5101720 offer adjustment creates new list_line_id
6181 -- AND adjl.list_line_id = oe.list_line_id
6182 AND oe.list_line_id IN (SELECT from_list_line_id
6183 FROM ozf_offer_adj_rltd_lines adjr
6184 START WITH adjr.from_list_line_id = adjl.list_line_id
6185 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6186 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6187 )
6188 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6189 AND util.object_type = 'ORDER'
6190 AND util.price_adjustment_id = oe.price_adjustment_id
6191 AND adjustment_date BETWEEN p_from_date AND l_to_date
6192 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6193 AND ol.line_id = oe.line_id
6194 UNION ALL
6195 --for accrual in third party accrual.
6196 SELECT util.utilization_id,
6197 util.object_type,
6198 util.object_id,
6199 util.order_line_id,
6200 util.product_id,
6201 util.billto_cust_account_id,
6202 util.cust_account_id,
6203 util.fund_id,
6204 util.plan_currency_code,
6205 util.currency_code,
6206 util.price_adjustment_id,
6207 --NULL,
6208 DECODE (oe.operand_calculation_code,
6209 --bug 13322965 - corrected formula for new price
6210 /*
6211 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount_td) * oe.priced_quantity, (oe.operand - adjl.modified_discount_td) * plan_curr_amount /-oe.operand)),
6212 */
6213 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount_td) * oe.priced_quantity, (oe.operand - adjl.modified_discount_td) * oe.priced_quantity)),
6214 '%', (DECODE(oe.operand, 0,adjl.modified_discount_td * oe.calculated_price * oe.priced_quantity / 100, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand)),
6215 'AMT', (DECODE(oe.operand, 0,adjl.modified_discount_td * oe.priced_quantity, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand)),
6216 'LUMPSUM', (DECODE(oe.operand, 0,adjl.modified_discount_td, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand))
6217 ) plan_curr_amount
6218 ,util.org_id
6219 ,util.ship_to_site_use_id
6220 ,util.bill_to_site_use_id
6221 ,util.reference_type
6222 ,util.reference_id
6223 ,util.exchange_rate_type
6224 FROM ozf_funds_utilized_all_b util,
6225 ozf_temp_eligibility temp,
6226 ozf_offer_adjustment_lines adjl,
6227 OZF_RESALE_ADJUSTMENTS_ALL oe
6228 WHERE util.plan_type = 'OFFR'
6229 AND product_id IS NOT NULL
6230 AND util.plan_id = p_qp_list_header_id
6231 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6232 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6233 AND oe.list_line_id IN (SELECT from_list_line_id -- = oe.list_line_id : Fix for bug 12660466
6234 FROM ozf_offer_adj_rltd_lines adjr
6235 START WITH adjr.from_list_line_id = adjl.list_line_id_td
6236 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6237 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6238 )
6239 AND util.price_adjustment_id = oe.resale_adjustment_id
6240 AND adjustment_date BETWEEN p_from_date AND l_to_date
6241 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6242 -- yzhao 01/13/2006 fix bug 4939453 offer adjustment creates new list_line_id
6243 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6244 AND util.object_type = 'TP_ORDER'
6245
6246 UNION -- for off invoice in direct sales
6247 SELECT util.utilization_id,
6248 util.object_type,
6249 util.object_id,
6250 util.order_line_id,
6251 util.product_id,
6252 util.billto_cust_account_id, -- yzhao: 11.5.10 added billto_cust_account_id
6253 util.cust_account_id,
6254 util.fund_id,
6255 util.plan_currency_code,
6256 util.currency_code,
6257 util.price_adjustment_id,
6258 --NULL ,
6259 DECODE (oe.arithmetic_operator,
6260 -- julou 03/30/2007 fix bug 5849584 "original discount = 0" causes "divisor is 0" exception
6261 'NEWPRICE', DECODE(oe.adjusted_amount_per_pqty, 0, (ol.unit_selling_price - adjl.modified_discount_td) * ol.pricing_quantity, ((oe.operand - adjl.modified_discount_td) * plan_curr_amount /-oe.adjusted_amount_per_pqty)),
6262 '%', DECODE(oe.operand, 0, adjl.modified_discount_td * ol.unit_selling_price * ol.pricing_quantity / 100, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand),
6263 'AMT', DECODE(oe.operand, 0, adjl.modified_discount_td * ol.pricing_quantity, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand),
6264 'LUMPSUM', DECODE(oe.operand, 0, adjl.modified_discount_td, (adjl.modified_discount_td - oe.operand) * plan_curr_amount / oe.operand)
6265 -- 'NEWPRICE', ((oe.operand - adjl.modified_discount) * amount /-oe.adjusted_amount_per_pqty),
6266 -- ((adjl.modified_discount_td - oe.operand) * amount / oe.operand)
6267 ) plan_curr_amount
6268 ,util.org_id
6269 ,util.ship_to_site_use_id
6270 ,util.bill_to_site_use_id
6271 ,util.reference_type
6272 ,util.reference_id
6273 ,util.exchange_rate_type
6274 FROM ozf_funds_utilized_all_b util,
6275 ozf_temp_eligibility temp,
6276 ozf_offer_adjustment_lines adjl,
6277 oe_order_lines_all ol,
6278 oe_price_adjustments oe
6279 WHERE util.plan_type = 'OFFR'
6280 AND product_id IS NOT NULL
6281 AND util.plan_id = p_qp_list_header_id
6282 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6283 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6284 -- kdass 31-MAR-2006 fix bug 5101720 offer adjustment creates new list_line_id
6285 -- AND adjl.list_line_id = oe.list_line_id
6286 AND oe.list_line_id IN (SELECT from_list_line_id
6287 FROM ozf_offer_adj_rltd_lines adjr
6288 START WITH adjr.from_list_line_id = adjl.list_line_id
6289 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6290 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6291 )
6292 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6293 AND util.object_type = 'ORDER'
6294 AND util.price_adjustment_id = oe.price_adjustment_id
6295 AND adjustment_date BETWEEN p_from_date AND l_to_date
6296 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6297 AND ol.line_id = oe.line_id
6298
6299 UNION
6300 --for off invoice in third party accrual.
6301 SELECT util.utilization_id,
6302 util.object_type,
6303 util.object_id,
6304 util.order_line_id,
6305 util.product_id,
6306 util.billto_cust_account_id,
6307 util.cust_account_id,
6308 util.fund_id,
6309 util.plan_currency_code,
6310 util.currency_code,
6311 util.price_adjustment_id,
6312 --NULL,
6313 DECODE (oe.operand_calculation_code,
6314 --bug 13322965 - corrected formula for new price
6315 /*
6316 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount) * oe.priced_quantity, (oe.operand - adjl.modified_discount) * plan_curr_amount /-oe.operand)),
6317 */
6318 'NEWPRICE', (DECODE(oe.operand, 0, (oe.calculated_price - adjl.modified_discount) * oe.priced_quantity, (oe.operand - adjl.modified_discount) * oe.priced_quantity)),
6319 '%', (DECODE(oe.operand, 0,adjl.modified_discount * oe.calculated_price * oe.priced_quantity / 100, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)),
6320 'AMT', (DECODE(oe.operand, 0,adjl.modified_discount * oe.priced_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)),
6321 'LUMPSUM', (DECODE(oe.operand, 0,adjl.modified_discount, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand))
6322 ) plan_curr_amount
6323 ,util.org_id
6324 ,util.ship_to_site_use_id
6325 ,util.bill_to_site_use_id
6326 ,util.reference_type
6327 ,util.reference_id
6328 ,util.exchange_rate_type
6329 FROM ozf_funds_utilized_all_b util,
6330 ozf_temp_eligibility temp,
6331 ozf_offer_adjustment_lines adjl,
6332 OZF_RESALE_ADJUSTMENTS_ALL oe
6333 WHERE util.plan_type = 'OFFR'
6334 AND product_id IS NOT NULL
6335 AND util.plan_id = p_qp_list_header_id
6336 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6337 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6338 AND oe.list_line_id IN (SELECT from_list_line_id -- = oe.list_line_id : Fix for bug 12660466
6339 FROM ozf_offer_adj_rltd_lines adjr
6340 START WITH adjr.from_list_line_id = adjl.list_line_id
6341 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6342 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6343 )
6344 AND util.price_adjustment_id = oe.resale_adjustment_id
6345 AND adjustment_date BETWEEN p_from_date AND l_to_date
6346 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT')
6347 -- yzhao 01/13/2006 fix bug 4939453 offer adjustment creates new list_line_id
6348 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6349 AND util.object_type = 'TP_ORDER';
6350
6351
6352 CURSOR c_bdadj_order_value IS
6353 SELECT util.utilization_id,
6354 util.object_type,
6355 util.object_id,
6356 util.order_line_id,
6357 util.product_id,
6358 util.billto_cust_account_id, -- yzhao: 11.5.10 added billto_cust_account_id
6359 util.cust_account_id,
6360 util.fund_id,
6361 util.plan_currency_code,
6362 util.currency_code,
6363 util.price_adjustment_id,
6364 --NULL,
6365 DECODE(oe.operand, 0, adjl.modified_discount * ol.pricing_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand) plan_curr_amount
6366 ,util.org_id
6367 ,util.ship_to_site_use_id
6368 ,util.bill_to_site_use_id
6369 ,util.reference_type
6370 ,util.reference_id
6371 ,util.exchange_rate_type
6372 FROM ozf_funds_utilized_all_b util,
6373 ozf_offer_adjustment_lines adjl,
6374 oe_order_lines_all ol,
6375 oe_price_adjustments oe
6376 WHERE util.plan_type = 'OFFR'
6377 AND util.plan_id = p_qp_list_header_id
6378 -- kdass 31-MAR-2006 fix bug 5101720 offer adjustment creates new list_line_id
6379 -- AND adjl.list_line_id = oe.list_line_id
6380 AND oe.list_line_id IN (SELECT from_list_line_id
6381 FROM ozf_offer_adj_rltd_lines adjr
6382 START WITH adjr.from_list_line_id = adjl.list_line_id
6383 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6384 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6385 )
6386 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6387 AND util.object_type = 'ORDER'
6388 AND util.price_adjustment_id = oe.price_adjustment_id
6389 AND adjustment_date BETWEEN p_from_date AND l_to_date
6390 AND oe.line_id = ol.line_id
6391 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT');
6392
6393 CURSOR c_bdadj_promotion_value IS
6394 SELECT util.utilization_id,
6395 util.object_type,
6396 util.object_id,
6397 util.order_line_id,
6398 util.product_id,
6399 util.billto_cust_account_id,
6400 util.cust_account_id,
6401 util.fund_id,
6402 util.plan_currency_code,
6403 util.currency_code,
6404 util.price_adjustment_id,
6405 --NULL,
6406 DECODE (oe.arithmetic_operator,
6407 -- julou 03/30/2007 fix bug 5849584 "original discount = 0" causes "divisor is 0" exception
6408 'NEWPRICE', DECODE(oe.adjusted_amount_per_pqty, 0, (ol.unit_selling_price - adjl.modified_discount) * ol.pricing_quantity, ((oe.operand - adjl.modified_discount) * plan_curr_amount /-oe.adjusted_amount_per_pqty)),
6409 '%', DECODE(oe.operand, 0, adjl.modified_discount * ol.unit_selling_price * oe.range_break_quantity / 100, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6410 'AMT', DECODE(oe.operand, 0, adjl.modified_discount * oe.range_break_quantity, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand),
6411 'LUMPSUM', DECODE(oe.operand, 0, adjl.modified_discount, (adjl.modified_discount - oe.operand) * plan_curr_amount / oe.operand)
6412 -- 'NEWPRICE', ((oe.operand - adjl.modified_discount) * amount /-oe.adjusted_amount_per_pqty),
6413 -- (adjl.modified_discount * oe.range_break_quantity - oe.operand * oe.range_break_quantity) * amount / (oe.operand *oe.range_break_quantity)
6414 ) plan_curr_amount
6415 ,util.org_id
6416 ,util.ship_to_site_use_id
6417 ,util.bill_to_site_use_id
6418 ,util.reference_type
6419 ,util.reference_id
6420 ,util.exchange_rate_type
6421 FROM ozf_funds_utilized_all_b util,
6422 ozf_temp_eligibility temp,
6423 ozf_offer_adjustment_lines adjl,
6424 oe_order_lines_all ol,
6425 oe_price_adjustments oe
6426 WHERE util.plan_type = 'OFFR'
6427 AND product_id IS NOT NULL
6428 AND util.plan_id = p_qp_list_header_id
6429 AND util.product_id = DECODE (temp.eligibility_id, -1, util.product_id, temp.eligibility_id)
6430 AND temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
6431 -- kdass 31-MAR-2006 fix bug 5101720 offer adjustment creates new list_line_id
6432 -- AND adjl.list_line_id = oe.list_line_id
6433 AND oe.list_line_id IN (SELECT from_list_line_id
6434 FROM ozf_offer_adj_rltd_lines adjr
6435 START WITH adjr.from_list_line_id = adjl.list_line_id
6436 AND adjr.offer_adjustment_id = adjl.offer_adjustment_id
6437 CONNECT BY PRIOR adjr.from_list_line_id = adjr.to_list_line_id
6438 )
6439 AND adjl.offer_adjustment_id = p_offer_adjustment_id
6440 AND util.object_type = 'ORDER'
6441 AND util.price_adjustment_id = oe.price_adjustment_id
6442 AND adjustment_date BETWEEN p_from_date AND l_to_date
6443 AND oe.line_id = ol.line_id
6444 AND util.utilization_type NOT IN('ADJUSTMENT','LEAD_ADJUSTMENT');
6445
6446 TYPE backdate_adj_rec_type IS RECORD
6447 (
6448 utilization_id NUMBER,
6449 object_type VARCHAR2(20),
6450 object_id NUMBER,
6451 order_line_id NUMBER,
6452 product_id NUMBER,
6453 billto_cust_account_id NUMBER,
6454 cust_account_id NUMBER,
6455 fund_id NUMBER,
6456 --nirprasa, 12.1.1 enhancement, replace amount with plan_curr_amount
6457 plan_currency_code VARCHAR2(15),--nirprasa, query plan_curr_amount
6458 currency_code VARCHAR2(15),
6459 price_adjustment_id NUMBER,
6460 --volume_offer_tiers_id NUMBER,
6461 plan_curr_amount NUMBER := 0,
6462 org_id NUMBER
6463 ,ship_to_site_use_id NUMBER
6464 ,bill_to_site_use_id NUMBER
6465 ,reference_type VARCHAR2(20)
6466 ,reference_id NUMBER
6467 ,exchange_rate_type VARCHAR2(30)
6468 );
6469
6470 TYPE backdate_adj_rec_tbl IS TABLE OF backdate_adj_rec_type INDEX BY BINARY_INTEGER;
6471
6472 backdate_adj_rec backdate_adj_rec_tbl;
6473
6474 CURSOR c_offer_info IS
6475 SELECT nvl(transaction_currency_code,fund_request_curr_code) transaction_currency_code,
6476 reusable,
6477 offer_type
6478 FROM ozf_offers
6479 WHERE qp_list_header_id = p_qp_list_header_id;
6480
6481 -- added by feliu to fix bug 4451500 and 4015372.
6482 --nirprasa, 12.1.1 enhancement, replace amount with plan_curr_amount
6483 CURSOR c_adj_amount(p_utilization_id IN NUMBER) IS
6484 SELECT sum(plan_curr_amount) adj_amt
6485 FROM ozf_funds_utilized_all_b
6486 --12/16/2005 changed by Feng
6487 WHERE orig_utilization_id = p_utilization_id
6488 --WHERE price_adjustment_id = p_price_adj_id
6489 --AND fund_id = p_fund_id
6490 --AND utilization_type ='ADJUSTMENT'
6491 AND utilization_type IN ('ADJUSTMENT', 'LEAD_ADJUSTMENT')
6492 AND adjustment_type_id in(-4,-5,-1);
6493
6494 --Added for bugfix 6278466
6495 CURSOR c_org_id (p_utilization_id IN NUMBER) IS
6496 SELECT org_id
6497 FROM ozf_funds_utilized_all_b
6498 WHERE utilization_id = p_utilization_id;
6499
6500 -- get conversion type (nirprasa 12.1.1 fix)
6501 CURSOR c_get_conversion_type( p_org_id IN NUMBER) IS
6502 SELECT exchange_rate_type
6503 FROM ozf_sys_parameters_all
6504 WHERE org_id = p_org_id;
6505 l_offer_info c_offer_info%ROWTYPE;
6506 l_index NUMBER := 1;
6507 l_rate NUMBER;
6508 l_arithmetic_operator VARCHAR2 (30);
6509 l_adj_amt NUMBER;
6510 --nirprasa, 12.1.1 enhancement
6511 l_converted_util_amount NUMBER;
6512 l_exchange_rate_type VARCHAR2(30) := FND_API.G_MISS_CHAR;
6513
6514 BEGIN
6515 write_conc_log ( l_full_name
6516 || ' : '
6517 || 'Adjusting From Date '
6518 || p_from_date
6519 || 'Adjusting To Date'
6520 || l_to_date);
6521 SAVEPOINT perform_adjustment;
6522 x_return_status := fnd_api.g_ret_sts_success;
6523 IF G_DEBUG THEN
6524 ozf_utility_pvt.debug_message (': begin ');
6525 END IF;
6526 IF fnd_api.to_boolean (p_init_msg_list) THEN
6527 fnd_msg_pub.initialize;
6528 END IF;
6529 OPEN c_offer_info;
6530 FETCH c_offer_info INTO l_offer_info;
6531 CLOSE c_offer_info;
6532
6533 write_conc_log ( l_full_name
6534 || ' : '
6535 || 'Before Processing Product For Offer Adjustment Id '
6536 || p_offer_adjustment_id);
6537
6538
6539 --process_offer_product
6540 process_offer_product (p_offer_adjustment_id => p_offer_adjustment_id, x_return_status => l_return_status);
6541 write_conc_log ( l_full_name
6542 || ' : '
6543 || 'After Process Product Return Status'
6544 || l_return_status);
6545
6546
6547 IF l_return_status = fnd_api.g_ret_sts_error THEN
6548 RAISE fnd_api.g_exc_error;
6549 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6550 RAISE fnd_api.g_exc_unexpected_error;
6551 END IF;
6552 --IF l_source_from_par_flag = 'N' THEN
6553
6554 -- updated by mkothari : 10-28-2002
6555 -- enhancement for 11.5.9: added BD adjustment for multi-tier accrual and off-invoice AND
6556 -- order_value(ORDER), trade deal(DEAL), promotional goods(OID) and volume offer(VOLUME_OFFER)
6557
6558 IF l_offer_info.offer_type = 'DEAL' THEN --(for 'TRADE DEAL' , use a different cursor)
6559 write_conc_log ('Processing TRADE DEAL offer ...');
6560 OPEN c_bdadj_trade_deal;
6561 ELSIF l_offer_info.offer_type = 'ORDER' THEN --(for 'ORDER VALUE' , use a different cursor)
6562 write_conc_log ('Processing ORDER VALUE offer ...');
6563 OPEN c_bdadj_order_value;
6564 ELSIF l_offer_info.offer_type = 'OID' THEN --(for 'promotional OFFER' , use a different cursor)
6565 write_conc_log ('Processing promotional OFFER offer ...');
6566 OPEN c_bdadj_promotion_value;
6567 ELSE
6568 write_conc_log ('Processing OID or ACCRUAL or OFF_INVOICE or Multi_Tier offer ...');
6569 write_conc_log ('p_from_date ...' || p_from_date);
6570 write_conc_log ('p_to_date ...' || p_to_date);
6571 write_conc_log ('p_qp_list_header_id ...' || p_qp_list_header_id);
6572 write_conc_log ('p_offer_adjustment_id ...' || p_offer_adjustment_id);
6573 OPEN c_bdadj_all_types;
6574 END IF;
6575
6576 LOOP
6577 IF l_offer_info.offer_type = 'DEAL' THEN
6578 FETCH c_bdadj_trade_deal BULK COLLECT INTO backdate_adj_rec LIMIT g_bulk_limit;
6579 ELSIF l_offer_info.offer_type = 'ORDER' THEN
6580 FETCH c_bdadj_order_value BULK COLLECT INTO backdate_adj_rec LIMIT g_bulk_limit;
6581 ELSIF l_offer_info.offer_type = 'OID' THEN
6582 FETCH c_bdadj_promotion_value BULK COLLECT INTO backdate_adj_rec LIMIT g_bulk_limit;
6583 ELSE
6584 FETCH c_bdadj_all_types BULK COLLECT INTO backdate_adj_rec LIMIT g_bulk_limit;
6585 END IF;
6586
6587 FOR i IN NVL(backdate_adj_rec.FIRST, 1) .. NVL(backdate_adj_rec.LAST, 0) LOOP
6588
6589 write_conc_log ( 'backdate_adj_rec.price_adjustment_id'
6590 || ' : ' || backdate_adj_rec(i).price_adjustment_id);
6591
6592 -- added by feliu on 06/30/2005 .
6593 --OPEN c_adj_amount (backdate_adj_rec(i).price_adjustment_id,backdate_adj_rec(i).fund_id);
6594 OPEN c_adj_amount (backdate_adj_rec(i).utilization_id);
6595 FETCH c_adj_amount INTO l_adj_amt;
6596 CLOSE c_adj_amount;
6597
6598 --Added for bugfix 6278466
6599 OPEN c_org_id(backdate_adj_rec(i).utilization_id);
6600 FETCH c_org_id INTO l_org_id;
6601 CLOSE c_org_id;
6602
6603 l_util_amount := ozf_utility_pvt.currround(backdate_adj_rec(i).plan_curr_amount,backdate_adj_rec(i).plan_currency_code); -- in transactional currency
6604 write_conc_log ( l_full_name
6605 || ' : '
6606 || 'Inside LOOP, Util Amount '
6607 || l_util_amount || 'Adj Amount '||l_adj_amt);
6608
6609 -- new utilization amount minus existing utilization amount.
6610 l_util_amount := l_util_amount - NVL(l_adj_amt,0);
6611
6612 write_conc_log ( l_full_name
6613 || ' : '
6614 || 'Inside LOOP, Util Amount '
6615 || l_util_amount);
6616
6617 IF l_util_amount <> 0 THEN
6618 l_act_budgets_rec := NULL;
6619 l_act_util_rec := NULL;
6620 l_act_budgets_rec.request_amount := l_util_amount;
6621 l_act_budgets_rec.approved_amount := l_act_budgets_rec.request_amount;
6622 --nirprasa,12.2
6623 OPEN c_get_conversion_type(backdate_adj_rec(i).org_id);
6624 FETCH c_get_conversion_type INTO backdate_adj_rec(i).exchange_rate_type;
6625 CLOSE c_get_conversion_type;
6626
6627 --nirprasa, 12.2 enhancement, convert the adjustment from transaction
6628 --to budget currency.
6629
6630 IF g_debug_flag = 'Y' THEN
6631 write_conc_log ('backdate_adj_rec(i).currency_code '||backdate_adj_rec(i).currency_code);
6632 write_conc_log ('backdate_adj_rec(i).plan_currency_code '||backdate_adj_rec(i).plan_currency_code);
6633 END IF;
6634
6635 IF backdate_adj_rec(i).currency_code = backdate_adj_rec(i).plan_currency_code THEN
6636 l_act_budgets_rec.parent_src_apprvd_amt := ozf_utility_pvt.currround(l_util_amount,backdate_adj_rec(i).currency_code);
6637 ELSE
6638
6639 ozf_utility_pvt.convert_currency (
6640 x_return_status => l_return_status,
6641 p_from_currency => backdate_adj_rec(i).plan_currency_code,
6642 p_to_currency => backdate_adj_rec(i).currency_code,
6643 p_conv_type => backdate_adj_rec(i).exchange_rate_type, -- nirprasa added for bug 7030415
6644 p_conv_date => OZF_ACCRUAL_ENGINE.G_FAE_START_DATE,
6645 p_from_amount => l_util_amount,
6646 x_to_amount => l_converted_util_amount,
6647 x_rate => l_rate
6648 );
6649
6650 IF g_debug_flag = 'Y' THEN
6651 write_conc_log ('l_converted_util_amount '||l_converted_util_amount);
6652 END IF;
6653
6654 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6655 IF g_debug_flag = 'Y' THEN
6656 ozf_utility_pvt.write_conc_log (' D: post_adjust_to_budget() convert currency failed. No posting to budget. Return');
6657 END IF;
6658 RAISE fnd_api.g_exc_unexpected_error;
6659 END IF;
6660 l_act_budgets_rec.parent_src_apprvd_amt := l_converted_util_amount;
6661
6662 END IF;
6663 --end nirprasa, 12.2 enhancement
6664
6665 write_conc_log (l_full_name || ' : '
6666 || 'In Process Ozf_Act_budgets offer id'
6667 || p_qp_list_header_id);
6668
6669 l_act_budgets_rec.act_budget_used_by_id := p_qp_list_header_id;
6670 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
6671 l_act_budgets_rec.budget_source_type := 'OFFR';
6672 l_act_budgets_rec.budget_source_id := p_qp_list_header_id;
6673 l_act_budgets_rec.request_currency := backdate_adj_rec(i).plan_currency_code;
6674 l_act_budgets_rec.request_date := SYSDATE;
6675 l_act_budgets_rec.status_code := 'APPROVED';
6676 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
6677 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
6678 l_act_budgets_rec.transfer_type := 'UTILIZED';
6679 l_act_budgets_rec.approval_date := SYSDATE;
6680 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
6681 write_conc_log (l_full_name || ' : '
6682 || 'resourceid '
6683 || l_act_budgets_rec.approver_id);
6684
6685 l_act_budgets_rec.justification := fnd_message.get_string ('OZF', 'OZF_BACKDATE_AMOUNT_ADJUSTMENT');
6686
6687 l_act_budgets_rec.parent_source_id := backdate_adj_rec(i).fund_id;
6688 l_act_budgets_rec.parent_src_curr := backdate_adj_rec(i).currency_code;
6689 l_act_util_rec.utilization_type :='ADJUSTMENT';
6690
6691 IF l_util_amount > 0 THEN
6692 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
6693 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
6694 ELSE
6695 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
6696 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
6697 END IF;
6698
6699 l_act_util_rec.product_level_type := 'PRODUCT';
6700 l_act_util_rec.product_id := backdate_adj_rec(i).product_id;
6701 -- yzhao: 02/23/2004 11.5.10 added billto_cust_account_id
6702 l_act_util_rec.billto_cust_account_id := backdate_adj_rec(i).billto_cust_account_id;
6703 l_act_util_rec.cust_account_id := backdate_adj_rec(i).cust_account_id;
6704 l_act_util_rec.org_id := l_org_id; -- Added for bugfix 6278466
6705 l_act_util_rec.price_adjustment_id := backdate_adj_rec(i).price_adjustment_id;
6706 --l_act_util_rec.volume_offer_tiers_id := backdate_adj_rec(i).volume_offer_tiers_id;
6707 --nirprasa,12.2 instead of sysdate use OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
6708 l_act_util_rec.adjustment_date := OZF_ACCRUAL_ENGINE.G_FAE_START_DATE;
6709 --SYSDATE;
6710 -- yzhao: 07/06/2004 11.5.10 populate order id, line id, original utilization id
6711 l_act_util_rec.object_type := backdate_adj_rec(i).object_type;
6712 l_act_util_rec.object_id := backdate_adj_rec(i).object_id;
6713 l_act_util_rec.order_line_id := backdate_adj_rec(i).order_line_id;
6714 l_act_util_rec.orig_utilization_id := backdate_adj_rec(i).utilization_id;
6715 l_act_util_rec.org_id := backdate_adj_rec(i).org_id;
6716 l_act_util_rec.ship_to_site_use_id := backdate_adj_rec(i).ship_to_site_use_id;
6717 l_act_util_rec.bill_to_site_use_id := backdate_adj_rec(i).bill_to_site_use_id;
6718 l_act_util_rec.reference_type := backdate_adj_rec(i).reference_type;
6719 l_act_util_rec.reference_id := backdate_adj_rec(i).reference_id;
6720 --nirprasa,12.2
6721 l_act_util_rec.currency_code := backdate_adj_rec(i).currency_code;
6722 l_act_util_rec.plan_currency_code := backdate_adj_rec(i).plan_currency_code;
6723 l_act_util_rec.fund_request_currency_code := l_offer_info.transaction_currency_code;
6724 l_act_util_rec.exchange_rate_type := backdate_adj_rec(i).exchange_rate_type;
6725 --nirprasa,12.2
6726 -- l_act_util_rec.gl_date := SYSDATE;
6727
6728 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => l_return_status
6729 ,x_msg_count => x_msg_count
6730 ,x_msg_data => x_msg_data
6731 ,p_act_budgets_rec => l_act_budgets_rec
6732 ,p_act_util_rec => l_act_util_rec
6733 ,x_act_budget_id => l_act_budget_id
6734 );
6735 END IF;
6736 write_conc_log (l_full_name || ' : '
6737 || 'Message :'
6738 || x_msg_data
6739 || 'Msg count'
6740 || x_msg_count
6741 || 'Return Status'
6742 || l_return_status
6743 );
6744 --DBMS_OUTPUT.put_line ( 'MESSAGE 11.5.9 (perform_adjustment) - BEGIN 2 :' || x_msg_data || 'msg count'|| x_msg_count || l_return_status);
6745 /* FOR_DEBUGGING
6746 -- IF l_return_status <> 'S' THEN
6747 IF(x_msg_count > 0)THEN
6748 FOR I IN 1 .. x_msg_count LOOP
6749 fnd_msg_pub.GET
6750 (p_msg_index => FND_MSG_PUB.G_NEXT,
6751 p_encoded => FND_API.G_FALSE,
6752 p_data => x_msg_data,
6753 p_msg_index_out => l_index);
6754 --ozf_utility_pvt.write_conc_log(l_full_name||' : '||i||x_msg_data);
6755 DBMS_OUTPUT.put_line('****(PA):'||x_msg_data);
6756 END LOOP;
6757 fnd_msg_pub.initialize;
6758 END IF;
6759 -- END IF;
6760 END FOR_DEBUGGING */
6761 --DBMS_OUTPUT.put_line ( 'MESSAGE 11.5.9 (perform_adjustment) - END 2 :' || x_msg_data || 'msg count'|| x_msg_count || l_return_status);
6762
6763 IF l_return_status = fnd_api.g_ret_sts_error THEN
6764 RAISE fnd_api.g_exc_error;
6765 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6766 RAISE fnd_api.g_exc_unexpected_error;
6767 END IF;
6768
6769 END LOOP; --FOR i IN NVL(backdate_adj_rec.FIRST, 1) .. NVL(backdate_adj_rec.LAST, 0) LOOP
6770
6771 IF l_offer_info.offer_type = 'DEAL' THEN
6772 EXIT WHEN c_bdadj_trade_deal%NOTFOUND;
6773 ELSIF l_offer_info.offer_type = 'ORDER' THEN
6774 EXIT WHEN c_bdadj_order_value%NOTFOUND;
6775 ELSIF l_offer_info.offer_type = 'OID' THEN
6776 EXIT WHEN c_bdadj_promotion_value%NOTFOUND;
6777 ELSE
6778 EXIT WHEN c_bdadj_all_types%NOTFOUND;
6779 END IF;
6780
6781 END LOOP;
6782
6783 IF l_offer_info.offer_type = 'DEAL' THEN
6784 CLOSE c_bdadj_trade_deal;
6785 ELSIF l_offer_info.offer_type = 'ORDER' THEN
6786 CLOSE c_bdadj_order_value;
6787 ELSIF l_offer_info.offer_type = 'OID' THEN
6788 CLOSE c_bdadj_promotion_value;
6789 ELSE
6790 CLOSE c_bdadj_all_types;
6791 END IF;
6792
6793 EXCEPTION
6794 WHEN fnd_api.g_exc_error THEN
6795 ROLLBACK TO perform_adjustment;
6796 x_return_status := fnd_api.g_ret_sts_error;
6797 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
6798 WHEN fnd_api.g_exc_unexpected_error THEN
6799 ROLLBACK TO perform_adjustment;
6800 x_return_status := fnd_api.g_ret_sts_unexp_error;
6801 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
6802 WHEN OTHERS THEN
6803 ROLLBACK TO perform_adjustment;
6804 x_return_status := fnd_api.g_ret_sts_unexp_error;
6805 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6806 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
6807 END IF;
6808 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
6809 END perform_adjustment;
6810
6811 -------------------------------------------------------------------
6812 -- NAME
6813 -- process_offer_product
6814 -- PURPOSE
6815 --
6816 -- History
6817 -- 4/18/2002 Mumu Pande Create.
6818 -- 05/09/2003 feliu use bind variable for dynamic sql.
6819 ----------------------------------------------------------------
6820 PROCEDURE process_offer_product (p_offer_adjustment_id IN NUMBER, x_return_status OUT NOCOPY VARCHAR2) IS
6821 l_adjustment_product_sql VARCHAR2 (32000) := NULL;
6822 l_temp_sql VARCHAR2 (32000) := NULL;
6823 l_return_status VARCHAR2 (20);
6824 l_msg_count NUMBER;
6825 l_msg_data VARCHAR2 (2000) := NULL;
6826 l_api_name VARCHAR2 (60) := 'process_offer_product';
6827 l_full_name VARCHAR2 (100) := g_pkg_name
6828 || '.process_offer_product';
6829 l_denorm_csr NUMBER;
6830 l_ignore NUMBER;
6831 l_stmt_denorm VARCHAR2(32000) := NULL;
6832
6833 -- get budget's product id and product family id
6834 CURSOR c_off_adj_lines IS
6835 SELECT offer_adjustment_line_id,
6836 qppa.product_attribute,
6837 qppa.product_attr_value
6838 FROM ozf_offer_adjustment_lines adjl, qp_pricing_attributes qppa
6839 WHERE adjl.offer_adjustment_id = p_offer_adjustment_id AND adjl.list_line_id = qppa.list_line_id;
6840 BEGIN
6841 -- ozf_utility_pvt.debug_message('enter validate_product_budget obj_id=' || p_object_id || ' budget_id=' || p_budget_id);
6842
6843 x_return_status := fnd_api.g_ret_sts_success;
6844 EXECUTE IMMEDIATE 'DELETE FROM ozf_temp_eligibility';
6845 write_conc_log ( l_full_name
6846 || ' : '
6847 || 'In Process Product '
6848 || p_offer_adjustment_id);
6849 ----DBMS_output.put_line ( 'In Process Product' || p_offer_adjustment_id);
6850 -- Get all product qualifiers for 'FUND'
6851 FOR product_rec IN c_off_adj_lines
6852 LOOP
6853
6854 FND_DSQL.init;
6855 FND_DSQL.add_text('INSERT INTO ozf_temp_eligibility(object_type, exclude_flag, eligibility_id,offer_adjustment_line_id) ');
6856 FND_DSQL.add_text('(SELECT ''FUND'', ''N'', product_id,' );
6857 FND_DSQL.add_text(product_rec.offer_adjustment_line_id );
6858 FND_DSQL.add_text(' FROM ( ');
6859
6860 -- For ALL items do a special processing , we donot eant to populate ozf_temp_wligibility
6861 -- with all items but insert -1 instead
6862 ----DBMS_output.put_line ( 'product_rec.product_attribute ' || product_rec.product_attribute);
6863 ----DBMS_output.put_line ( 'product_rec.product_attr_value ' || product_rec.product_attr_value);
6864 IF product_rec.product_attribute = 'PRICING_ATTRIBUTE3' AND product_rec.product_attr_value = 'ALL' THEN
6865 --l_temp_sql := 'SELECT -1 product_id FROM DUAL';
6866 FND_DSQL.add_text('SELECT -1 product_id FROM DUAL');
6867 ----DBMS_output.put_line (' IN ALL products ');
6868 ELSE
6869 l_temp_sql := ozf_offr_elig_prod_denorm_pvt.get_sql (
6870 p_context=> 'ITEM',
6871 p_attribute=> product_rec.product_attribute,
6872 p_attr_value_from=> product_rec.product_attr_value, -- product_id
6873 -- p_attr_value_from=> 199,
6874 p_attr_value_to=> NULL,
6875 p_comparison=> NULL,
6876 p_type=> 'PROD'
6877 );
6878 END IF;
6879 FND_DSQL.add_text('))');
6880 write_conc_log ( l_full_name
6881 || ' : '
6882 || 'Get Sql Returns'
6883 || l_temp_sql);
6884 ----DBMS_output.put_line ( 'get sql returns' || l_temp_sql);
6885 /*
6886 l_adjustment_product_sql := 'INSERT INTO ozf_temp_eligibility(object_type, exclude_flag, eligibility_id,offer_adjustment_line_id) '
6887 || '(SELECT ''FUND'', ''N'', product_id,'
6888 || product_rec.offer_adjustment_line_id
6889 || ' FROM ( '
6890 || l_temp_sql
6891 || '))';
6892 */
6893
6894 l_denorm_csr := DBMS_SQL.open_cursor;
6895 FND_DSQL.set_cursor(l_denorm_csr);
6896 l_stmt_denorm := FND_DSQL.get_text(FALSE);
6897 --ozf_utility_pvt.debug_message('offer query: '|| l_stmt_denorm);
6898 write_conc_log ( l_full_name
6899 || ' : '
6900 || 'Insert Sql'
6901 || l_stmt_denorm);
6902 ----DBMS_output.put_line ( 'sql' || l_adjustment_product_sql);
6903 --EXECUTE IMMEDIATE l_adjustment_product_sql;
6904 DBMS_SQL.parse(l_denorm_csr, l_stmt_denorm, DBMS_SQL.native);
6905 FND_DSQL.do_binds;
6906 l_ignore := DBMS_SQL.execute(l_denorm_csr);
6907
6908 END LOOP;
6909 EXCEPTION
6910 WHEN OTHERS THEN
6911 x_return_status := fnd_api.g_ret_sts_error;
6912 END process_offer_product;
6913 ---------------------------------------------------------------------
6914 -- PROCEDURE
6915 -- PROCESS_ACCRUAL
6916 --
6917 -- PURPOSE
6918 --
6919 -- PARAMETERS
6920 -- p_earned_amt IN NUMBER -- in offer currency
6921 -- p_qp_list_header_id IN NUMBER -- Offer Id
6922 -- NOTES
6923 -- HISTORY
6924 -- 4/18/2002 Mumu Pande Create.
6925 ----------------------------------------------------------------------
6926 PROCEDURE process_accrual (
6927 p_earned_amt IN NUMBER,
6928 p_qp_list_header_id IN NUMBER,
6929 p_act_util_rec IN ozf_actbudgets_pvt.act_util_rec_type,
6930 p_act_budgets_rec IN ozf_actbudgets_pvt.act_budgets_rec_type:= NULL,
6931 x_return_status OUT NOCOPY VARCHAR2,
6932 x_msg_count OUT NOCOPY NUMBER,
6933 x_msg_data OUT NOCOPY VARCHAR2);
6934
6935 ---------------------------------------------------------------------
6936 -- PROCEDURE
6937 -- ADJUST_VOLUME_OFFER
6938 --
6939 -- PURPOSE
6940 --
6941 -- PARAMETERS
6942 -- x_errbuf OUT NOCOPY VARCHAR2 STANDARD OUT NOCOPY PARAMETER
6943 -- x_retcode OUT NOCOPY NUMBER STANDARD OUT NOCOPY PARAMETER
6944 -- NOTES
6945 -- HISTORY
6946 -- 7/30/2002 Mumu Pande Create.
6947 -- 06/02/2005 Feliu rewrite to fix following issue:
6948 -- 1. First tier starts from 0.
6949 -- 2. The calculation for tier amount is based on unit selling price, not on unit list price.
6950 -- 3. Partial shipment for volume offer.
6951 -- 4. Returned order for volume offer.
6952 -- 5. Order quantity is over max tier amount or quantity.
6953
6954 ----------------------------------------------------------------------
6955
6956 PROCEDURE adjust_volume_offer(
6957 x_errbuf OUT NOCOPY VARCHAR2
6958 ,x_retcode OUT NOCOPY NUMBER
6959 ,p_debug IN VARCHAR2 := 'N')
6960 IS
6961
6962 CURSOR c_volume_off IS
6963 SELECT qp_list_header_id, volume_offer_type
6964 FROM ozf_offers
6965 WHERE offer_type = 'VOLUME_OFFER'
6966 AND status_code = 'ACTIVE';
6967
6968 l_api_name CONSTANT VARCHAR2(30) := 'adjust_volume_offer';
6969 l_full_name VARCHAr2(70):= g_pkg_name ||'.'||l_api_name ||' : ';
6970 l_api_version CONSTANT NUMBER := 1.0;
6971 l_return_status VARCHAR2 (20);
6972 l_msg_count NUMBER;
6973 l_msg_data VARCHAR2 (2000) := NULL;
6974
6975 TYPE qpListHeaderIdTbl IS TABLE OF ozf_offers.qp_list_header_id%TYPE;
6976 TYPE volumeOfferTypeTbl IS TABLE OF ozf_offers.volume_offer_type%TYPE;
6977
6978 l_qpListHeaderIdTbl qpListHeaderIdTbl;
6979 l_volumeOfferTypeTbl volumeOfferTypeTbl;
6980
6981 BEGIN
6982
6983 write_conc_log (' /*************************** DEBUG MESSAGE START *************************/' || l_api_name);
6984 SAVEPOINT adjust_volume_offer;
6985
6986 --Get All Active Volume Offer, volume_type
6987 OPEN c_volume_off;
6988 LOOP
6989 FETCH c_volume_off BULK COLLECT INTO l_qpListHeaderIdTbl, l_volumeOfferTypeTbl
6990 LIMIT g_bulk_limit;
6991
6992 FOR i IN NVL(l_qpListHeaderIdTbl.FIRST, 1) .. NVL(l_qpListHeaderIdTbl.LAST, 0) LOOP
6993
6994 FND_MSG_PUB.initialize;
6995 l_msg_count:= 0;
6996 l_msg_data := NULL;
6997 l_return_status := FND_API.g_ret_sts_success;
6998
6999 write_conc_log(l_full_name ||'VOLUME OFFER ID'|| l_qpListHeaderIdTbl(i));
7000
7001 BEGIN
7002 SAVEPOINT volume_offer;
7003
7004 volume_offer_adjustment(p_qp_list_header_id => l_qpListHeaderIdTbl(i)
7005 ,p_vol_off_type => l_volumeOfferTypeTbl(i)
7006 ,p_init_msg_list => fnd_api.g_false
7007 ,p_commit => fnd_api.g_false
7008 ,x_return_status => l_return_status
7009 ,x_msg_count => l_msg_count
7010 ,x_msg_data => l_msg_data
7011 );
7012
7013 write_conc_log(l_full_name ||'x_return_status'|| l_return_status);
7014
7015 IF l_return_status = fnd_api.g_ret_sts_error THEN
7016 RAISE fnd_api.g_exc_error;
7017 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7018 RAISE fnd_api.g_exc_unexpected_error;
7019 END IF;
7020
7021 ----------------------------------------
7022 volume_offer_util_adjustment(p_qp_list_header_id => l_qpListHeaderIdTbl(i)
7023 ,x_return_status => l_return_status
7024 ,x_msg_count => l_msg_count
7025 ,x_msg_data => l_msg_data
7026 );
7027
7028 write_conc_log(l_full_name ||'x_return_status'|| l_return_status);
7029
7030 IF l_return_status = fnd_api.g_ret_sts_error THEN
7031 RAISE fnd_api.g_exc_error;
7032 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7033 RAISE fnd_api.g_exc_unexpected_error;
7034 END IF;
7035 ----------------------------------------
7036
7037 EXCEPTION
7038 WHEN FND_API.G_EXC_ERROR THEN
7039 ROLLBACK TO VOLUME_OFFER;
7040 OZF_UTILITY_PVT.write_conc_log(l_full_name ||' Volume Offer Adjustment Failed EX ==>'||'VOLUME OFFER '|| l_qpListHeaderIdTbl(i));
7041 OZF_UTILITY_PVT.write_conc_log;
7042 OZF_UTILITY_PVT.write_conc_log(' ');
7043
7044 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7045 ROLLBACK TO VOLUME_OFFER;
7046 OZF_UTILITY_PVT.write_conc_log(l_full_name ||' Volume Offer Adjustment Failed UNEX ==>'||'VOLUME OFFER '|| l_qpListHeaderIdTbl(i));
7047 OZF_UTILITY_PVT.write_conc_log;
7048 OZF_UTILITY_PVT.write_conc_log(' ');
7049
7050 WHEN OTHERS THEN
7051 ROLLBACK TO VOLUME_OFFER;
7052 OZF_UTILITY_PVT.write_conc_log(l_full_name ||' Volume Offer Adjustment Failed OT ==>'||'VOLUME OFFER '|| l_qpListHeaderIdTbl(i));
7053 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
7054 OZF_UTILITY_PVT.write_conc_log;
7055 OZF_UTILITY_PVT.write_conc_log(' ');
7056 END;
7057
7058 END LOOP; --FOR i IN NVL(l_qpListHeaderIdTbl.FIRST, 1) .. NVL(l_qpListHeaderIdTbl.LAST, 0) LOOP
7059
7060 EXIT WHEN c_volume_off%NOTFOUND;
7061
7062 END LOOP; -- end volume offer bulk fetch loop
7063
7064 write_conc_log (' /*************************** DEBUG MESSAGE END *************************/' || l_api_name );
7065 EXCEPTION
7066 WHEN fnd_api.g_exc_error THEN
7067 ROLLBACK TO adjust_volume_offer;
7068 OZF_UTILITY_PVT.write_conc_log;
7069 x_ERRBUF := l_msg_data;
7070 x_RETCODE := 1;
7071
7072 WHEN fnd_api.g_exc_unexpected_error THEN
7073 ROLLBACK TO adjust_volume_offer;
7074 OZF_UTILITY_PVT.write_conc_log;
7075 x_ERRBUF := l_msg_data;
7076 x_RETCODE := 1;
7077
7078 WHEN OTHERS THEN
7079 ROLLBACK TO adjust_volume_offer;
7080 OZF_UTILITY_PVT.write_conc_log;
7081 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7082 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
7083 END IF;
7084 x_ERRBUF := l_msg_data;
7085 x_RETCODE := 1;
7086
7087 END adjust_volume_offer;
7088
7089 ---------------------------------------------------------------------
7090 -- PROCEDURE
7091 -- PROCESS_ACCRUAL
7092 --
7093 -- PURPOSE
7094 --
7095 -- PARAMETERS
7096 -- p_earned_amt IN NUMBER -- in offer currency
7097 -- p_qp_list_header_id IN NUMBER -- Offer Id
7098 -- NOTES
7099 -- HISTORY
7100 -- 7/31/2002 Mumu Pande Create.
7101 ----------------------------------------------------------------------
7102 PROCEDURE process_accrual (
7103 p_earned_amt IN NUMBER,
7104 p_qp_list_header_id IN NUMBER,
7105 p_act_util_rec IN ozf_actbudgets_pvt.act_util_rec_type,
7106 p_act_budgets_rec IN ozf_actbudgets_pvt.act_budgets_rec_type := NULL,
7107 x_return_status OUT NOCOPY VARCHAR2,
7108 x_msg_count OUT NOCOPY NUMBER,
7109 x_msg_data OUT NOCOPY VARCHAR2
7110 ) IS
7111 l_fund_amt_tbl ozf_accrual_engine.ozf_fund_amt_tbl_type;
7112 l_api_name VARCHAR2(30):= 'process_accrual';
7113 l_full_name VARCHAR2(60):= g_pkg_name ||'.'||l_api_name||' : ' ;
7114 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type := p_act_budgets_rec;
7115 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type := p_act_util_rec;
7116 l_earned_amount NUMBER;
7117 l_old_earned_amount NUMBER;
7118 l_header_id NUMBER; -- order or invoice id
7119 l_line_id NUMBER; -- order or invoice id
7120 l_remaining_amt NUMBER;
7121 l_count NUMBER := 1;
7122 l_rate NUMBER;
7123 l_util_curr VARCHAR2 (30);
7124 l_adj_amount NUMBER;
7125 l_converted_adj_amount NUMBER;
7126 j NUMBER; --loop counter
7127 l_off_name VARCHAR2(240);
7128 l_off_description VARCHAR2(2000);
7129 l_act_budget_id NUMBER;
7130 l_earned_amount NUMBER;
7131
7132 CURSOR c_offer_info (p_list_header_id IN NUMBER) IS
7133 ----- fix bug 5675871
7134 SELECT qp.description, qp.name ,nvl(ofr.transaction_currency_code, ofr.fund_request_curr_code)
7135 FROM qp_list_headers_vl qp, ozf_offers ofr
7136 WHERE qp.list_header_id = p_list_header_id
7137 AND qp.list_header_id = ofr.qp_list_header_id;
7138 /*
7139 SELECT description, name ,currency_code
7140 FROM qp_list_headers_vl
7141 WHERE list_header_id = p_list_header_id;
7142 */
7143 CURSOR c_adj_info (p_price_adj_id IN NUMBER,p_object_type VARCHAR2,p_order_line_id IN NUMBER) IS
7144 SELECT distinct billto_cust_account_id, cust_account_id,product_id,object_id,object_type,org_id
7145 ,ship_to_site_use_id,bill_to_site_use_id,exchange_rate_type --Added for bug 7030415
7146 FROM ozf_funds_utilized_all_b
7147 WHERE price_adjustment_id = p_price_adj_id
7148 AND object_type = p_object_type
7149 AND order_line_id = p_order_line_id;
7150
7151 CURSOR c_tp_adj_info (p_price_adj_id IN NUMBER,p_object_type VARCHAR2) IS
7152 SELECT distinct billto_cust_account_id, cust_account_id,product_id,object_id,object_type,org_id
7153 ,ship_to_site_use_id,bill_to_site_use_id,exchange_rate_type --Added for bug 7030415
7154 FROM ozf_funds_utilized_all_b
7155 WHERE price_adjustment_id = p_price_adj_id
7156 AND object_type = p_object_type;
7157
7158 -- Added for bug 7030415, cursor for currency conversion type.
7159 CURSOR c_get_conversion_type( p_org_id IN NUMBER) IS
7160 SELECT exchange_rate_type
7161 FROM ozf_sys_parameters_all
7162 WHERE org_id = p_org_id;
7163
7164 l_exchange_rate_type VARCHAR2(30) := FND_API.G_MISS_CHAR;
7165
7166
7167
7168 l_adj_info c_adj_info%ROWTYPE;
7169
7170 BEGIN
7171 x_return_status := fnd_api.g_ret_sts_success;
7172 SAVEPOINT process_accrual;
7173 IF G_DEBUG THEN
7174 ozf_utility_pvt.debug_message (' Start'|| g_pkg_name||'.'||l_api_name);
7175 END IF;
7176
7177 IF l_act_util_rec.object_type = 'TP_ORDER' THEN
7178 OPEN c_tp_adj_info (l_act_util_rec.price_adjustment_id,l_act_util_rec.object_type);
7179 FETCH c_tp_adj_info INTO l_adj_info;
7180 CLOSE c_tp_adj_info;
7181 ELSE
7182 OPEN c_adj_info (l_act_util_rec.price_adjustment_id,l_act_util_rec.object_type,l_act_util_rec.order_line_id);
7183 FETCH c_adj_info INTO l_adj_info;
7184 CLOSE c_adj_info;
7185 END IF;
7186
7187 ozf_accrual_engine.calculate_accrual_amount (
7188 x_return_status=> x_return_status,
7189 p_src_id=> p_qp_list_header_id,
7190 p_earned_amt=> p_earned_amt,
7191 -- yzhao: 02/23/2004 11.5.10 added following 3 parameters to return customer-product qualified budgets only
7192 -- if none budget qualifies, then post to all budgets
7193 p_cust_account_type => 'BILL_TO',
7194 p_cust_account_id => l_adj_info.billto_cust_account_id,
7195 p_product_item_id => l_adj_info.product_id,
7196 x_fund_amt_tbl=> l_fund_amt_tbl
7197 );
7198
7199 --dbms_output.put_line(' cal Status '||x_return_status);
7200 write_conc_log(l_full_name ||'Calculate Accrual Amt Return Status ' ||x_return_status);
7201 IF G_DEBUG THEN
7202 ozf_utility_pvt.debug_message (l_full_name ||'Return Status' ||x_return_status);
7203 END IF;
7204 -- fetch offer info
7205 OPEN c_offer_info ( p_qp_list_header_id);
7206 FETCH c_offer_info INTO l_off_description, l_off_name,l_util_curr ;
7207 CLOSE c_offer_info;
7208
7209 --- if this is not funded by a parent campaign or any budget the error out saying no budgte found
7210 IF l_fund_amt_tbl.COUNT = 0 OR x_return_status <> 'S' THEN
7211 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_error) THEN
7212 fnd_message.set_name ('OZF', 'OZF_FUND_NO_BUDGET_FOUND');
7213 fnd_message.set_token ('OFFER_NAME', l_off_name);
7214 fnd_msg_pub.ADD;
7215 END IF;
7216 --dbms_output.put_line(' In error ');
7217 IF x_return_status = fnd_api.g_ret_sts_error THEN
7218 RAISE fnd_api.g_exc_error;
7219 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
7220 RAISE fnd_api.g_exc_unexpected_error;
7221 END IF;
7222 ELSE
7223 --if some row is returned to adjust then
7224 IF G_DEBUG THEN
7225 ozf_utility_pvt.debug_message ('Begin Processing For Offer Adjustment: '||l_off_name);
7226 END IF;
7227 IF (l_fund_amt_tbl.COUNT > 0) AND x_return_status = fnd_api.g_ret_sts_success THEN
7228 l_adj_amount := 0; -- in offer currency
7229 l_remaining_amt := ozf_utility_pvt.currround (
7230 p_earned_amt,
7231 --nirprasa,12.1.1 l_util_curr ); -- in offer currency
7232 l_act_util_rec.plan_currency_code); -- in transaction currency
7233
7234 --nirprasa,12.1.1
7235 <<earned_adj_loop>>
7236 FOR j IN l_fund_amt_tbl.FIRST .. l_fund_amt_tbl.LAST
7237 LOOP
7238 IF g_recal_flag = 'N' THEN
7239 IF l_fund_amt_tbl (j).earned_amount = 0 THEN
7240 IF G_DEBUG THEN
7241 ozf_utility_pvt.debug_message (' D: 0 earned amount' );
7242 END IF;
7243 GOTO l_endofearadjloop;
7244 END IF;
7245 END IF;
7246 IF ABS(l_remaining_amt) >= l_fund_amt_tbl (j).earned_amount THEN
7247 l_adj_amount := l_fund_amt_tbl (j).earned_amount; -- this is in offer and order currency
7248 ELSE
7249 l_adj_amount := l_remaining_amt;
7250 END IF;
7251 l_adj_amount := ozf_utility_pvt.currround (
7252 l_adj_amount,
7253 --nirprasa,12.1.1 l_util_curr ); -- in offer currency
7254 l_act_util_rec.plan_currency_code); -- in transaction currency
7255 --nirprasa,12.1.1
7256
7257 l_remaining_amt := l_remaining_amt - l_adj_amount;
7258 -- conver the adjustment amount from offer currency to fund currency
7259 --use l_adj_info
7260
7261
7262 --nirprasa,12.1.1 IF l_util_curr <> l_fund_amt_tbl (j).budget_currency THEN
7263 IF l_act_util_rec.plan_currency_code <> l_fund_amt_tbl (j).budget_currency THEN
7264 ozf_utility_pvt.convert_currency (
7265 x_return_status=> x_return_status,
7266 p_from_currency=> l_act_util_rec.plan_currency_code, --nirprasa,12.1.1 l_util_curr,
7267 p_to_currency=> l_fund_amt_tbl (j).budget_currency,
7268 p_conv_date=> l_act_util_rec.exchange_rate_date,
7269 p_conv_type=> l_adj_info.exchange_rate_type, --Added for bug 7030415
7270 p_from_amount=> l_adj_amount,
7271 x_to_amount=> l_converted_adj_amount,
7272 x_rate=> l_rate
7273 );
7274 END IF;
7275 IF G_DEBUG THEN
7276 ozf_utility_pvt.debug_message( ' Adj amount coverted '|| l_converted_adj_amount
7277 || ' l_adj amount' || l_adj_amount);
7278 END IF;
7279
7280 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7281 IF G_DEBUG THEN
7282 -- ozf_utility_pvt.error_message( ' Convert Currency '||x_return_status);
7283 ozf_utility_pvt.debug_message( ' Convert Currency '||x_return_status);
7284 END IF;
7285 IF x_return_status = fnd_api.g_ret_sts_error THEN
7286 RAISE fnd_api.g_exc_error;
7287 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
7288 RAISE fnd_api.g_exc_unexpected_error;
7289 END IF;
7290 END IF;
7291 IF x_return_status = fnd_api.g_ret_sts_success THEN
7292 IF l_act_util_rec.plan_currency_code = l_fund_amt_tbl (j).budget_currency THEN
7293 l_act_budgets_rec.parent_src_apprvd_amt :=
7294 ozf_utility_pvt.currround (
7295 l_adj_amount,
7296 --nirprasa,12.1.1 l_util_curr );
7297 l_act_util_rec.plan_currency_code);
7298 --nirprasa,12.1.1
7299 ELSE
7300 IF G_DEBUG THEN
7301 ozf_utility_pvt.debug_message('in not equal currency');
7302 END IF;
7303 l_act_budgets_rec.parent_src_apprvd_amt :=
7304 ozf_utility_pvt.currround (
7305 l_converted_adj_amount,
7306 l_fund_amt_tbl (j).budget_currency );
7307 END IF;
7308
7309 l_act_util_rec.product_id := l_adj_info.product_id;
7310 l_act_util_rec.object_type := l_adj_info.object_type;
7311 l_act_util_rec.object_id := l_adj_info.object_id;
7312 l_act_util_rec.product_level_type := 'PRODUCT';
7313 -- yzhao: 11.5.10 02/23/2004 added billto_cust_account_id
7314 l_act_util_rec.billto_cust_account_id := l_adj_info.billto_cust_account_id;
7315 l_act_util_rec.cust_account_id := l_adj_info.cust_account_id;
7316 l_act_util_rec.utilization_type := 'ADJUSTMENT';
7317 l_act_util_rec.org_id := l_adj_info.org_id;
7318 l_act_util_rec.ship_to_site_use_id := l_adj_info.ship_to_site_use_id;
7319 l_act_util_rec.bill_to_site_use_id := l_adj_info.bill_to_site_use_id;
7320
7321 l_act_budgets_rec.justification := fnd_message.get_string ('OZF', 'OZF_ACR_VOL_BDADJ');
7322 l_act_budgets_rec.transfer_type := 'UTILIZED';
7323 l_act_budgets_rec.request_date := SYSDATE;
7324 l_act_budgets_rec.status_code := 'APPROVED';
7325 l_act_budgets_rec.user_status_id :=
7326 ozf_utility_pvt.get_default_user_status (
7327 'OZF_BUDGETSOURCE_STATUS',
7328 l_act_budgets_rec.status_code );
7329 l_act_budgets_rec.budget_source_type := 'OFFR';
7330 l_act_budgets_rec.budget_source_id := p_qp_list_header_id;
7331 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
7332 l_act_budgets_rec.act_budget_used_by_id := p_qp_list_header_id;
7333 l_act_budgets_rec.parent_src_curr := l_fund_amt_tbl (j).budget_currency;
7334 l_act_budgets_rec.parent_source_id := l_fund_amt_tbl (j).ofr_src_id;
7335 l_act_budgets_rec.request_amount :=
7336 ozf_utility_pvt.currround (l_adj_amount, l_act_util_rec.plan_currency_code);
7337 --nirprasa,12.2 ozf_utility_pvt.currround (l_adj_amount, l_util_curr);
7338
7339 l_act_budgets_rec.request_currency := l_act_util_rec.plan_currency_code; --l_util_curr;
7340 l_act_budgets_rec.approved_amount := l_act_budgets_rec.request_amount;
7341 l_act_budgets_rec.approved_in_currency := l_act_util_rec.plan_currency_code; --l_util_curr;
7342 l_act_util_rec.fund_request_currency_code := l_util_curr;
7343 --nirprasa,12.2 end.
7344
7345 IF l_adj_amount > 0 THEN
7346 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
7347 l_act_util_rec.adjustment_type_id := -7; -- Seeded Data for Backdated Positive Adj
7348 ELSE
7349 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
7350 l_act_util_rec.adjustment_type_id := -6; -- Seeded Data for Backdated Negative Adj
7351 END IF;
7352
7353 IF l_act_budgets_rec.request_amount <> 0 THEN -- fix bug 4720113
7354 ozf_fund_Adjustment_pvt.process_Act_budgets(
7355 x_return_status=> x_return_status,
7356 x_msg_count=> x_msg_count,
7357 x_msg_data=> x_msg_data,
7358 p_act_budgets_rec=> l_act_budgets_rec,
7359 p_act_util_rec=> l_act_util_rec,
7360 x_act_budget_id=> l_act_budget_id
7361 );
7362 write_conc_log(l_full_name ||'Process Act Budget' ||x_return_status);
7363 IF G_DEBUG THEN
7364 ozf_utility_pvt.debug_message('create utlization '|| x_return_status);
7365 END IF;
7366
7367 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7368 IF x_return_status = fnd_api.g_ret_sts_error THEN
7369 RAISE fnd_api.g_exc_error;
7370 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
7371 RAISE fnd_api.g_exc_unexpected_error;
7372 END IF;
7373 END IF;
7374 END IF; --l_act_budgets_rec.request_amount <> 0
7375 --- quit when the total earned amount is adjusted
7376 END IF;
7377 <<l_endofearadjloop>>
7378 IF G_DEBUG THEN
7379 ozf_utility_pvt.debug_message ( 'l_remaining_amt ' || l_remaining_amt
7380 || 'l_adj amount' || l_adj_amount || 'fund_id '|| l_fund_amt_tbl (j).ofr_src_id );
7381 END IF;
7382 EXIT WHEN l_remaining_amt = 0;
7383 END LOOP earned_adj_loop;
7384 END IF; --end of check for table count >0
7385 END IF; -- end of check for count
7386 EXCEPTION
7387 WHEN fnd_api.g_exc_error THEN
7388 ROLLBACK TO process_accrual;
7389 x_return_status := fnd_api.g_ret_sts_error;
7390 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
7391 WHEN fnd_api.g_exc_unexpected_error THEN
7392 ROLLBACK TO process_accrual;
7393 x_return_status := fnd_api.g_ret_sts_unexp_error;
7394 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
7395 WHEN OTHERS THEN
7396 ROLLBACK TO process_accrual;
7397 x_return_status := fnd_api.g_ret_sts_unexp_error;
7398 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7399 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
7400 END IF;
7401 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
7402
7403 END process_accrual;
7404
7405 ---------------------------------------------------------------------
7406 -- PROCEDURE
7407 --
7408 --
7409 -- PURPOSE
7410 --
7411 -- PARAMETERS
7412 -- p_from_date IN DATE
7413 -- p_qp_list_header_id IN NUMBER
7414 -- NOTES
7415 -- HISTORY
7416 -- 4/18/2002 Mumu Pande Create.
7417 ----------------------------------------------------------------------
7418 PROCEDURE process_claim_autopay (
7419 p_from_date IN DATE,
7420 p_qp_list_header_id IN NUMBER,
7421 x_return_status OUT NOCOPY VARCHAR2,
7422 x_msg_count OUT NOCOPY NUMBER,
7423 x_msg_data OUT NOCOPY VARCHAR2
7424 ) /*
7425 select product_id , cust_account_id , fund_id , sum(DECODE(adjl.arithmetic_operator,'AMOUNT', (adjl.modified_discount - adjl.original_discount),
7426 (( adjl.modified_discount - adjl.original_discount)* amount/adjl.original_discount))) AMount
7427 from ozf_funds_utilized_all_vl util , ozf_temp_eligibility temp,
7428 ozf_offer_adjustment_lines adjl
7429 where util.plan_type = 'OFFR'
7430 and product_id IS NOT NULL and util.plan_id = 7909
7431 and util.product_id = temp.eligibility_id
7432 and temp.offer_adjustment_line_id = adjl.offer_adjustment_line_id
7433 and adjustment_date BETWEEN from_date and to_date
7434 group by util.fund_id, util.product_id, util.fund_id,util.cust_account_id
7435 */ IS
7436 /******************Also pass the adjsutment_type_id */
7437 BEGIN
7438 NULL;
7439 /*
7440 get the last autppay date
7441 get the amount cursor from the from_date to the last autopay date
7442 Call claims Autopay API to settle the claim with proper date
7443 Perform Error Handling
7444 */
7445 END process_claim_autopay;
7446
7447
7448 ---------------------------------------------------------------------
7449 -- FUNCTION
7450 -- get_order_amount_quantity
7451 --
7452 -- PURPOSE -- Called from Offers UI
7453 --
7454 -- PARAMETERS
7455 -- p_list_header_id IN NUMBER,
7456 -- x_order_amount OUT NOCOPY NUMBER,
7457 -- NOTES
7458 -- HISTORY
7459 -- 10/18/2002 Mumu Pande Create.
7460 ----------------------------------------------------------------------
7461
7462 FUNCTION get_order_amount_quantity( p_list_header_id IN NUMBER
7463 )
7464 RETURN NUMBER
7465 IS
7466 l_new_discount NUMBER;
7467 l_new_operator VARCHAR2(30);
7468 l_old_discount NUMBER;
7469 l_old_operator VARCHAR2(30);
7470 l_return_status VARCHAR2(1);
7471 l_order_amount_quantity NUMBER;
7472 l_volume_type VARCHAR2(30);
7473
7474 BEGIN
7475
7476 l_order_amount_quantity:= get_order_amount_quantity(
7477 p_list_header_id => p_list_header_id ,
7478 x_order_amount_quantity => l_order_amount_quantity,
7479 x_new_discount =>l_new_discount,
7480 x_new_operator => l_new_operator,
7481 x_old_discount =>l_old_discount,
7482 x_old_operator =>l_old_operator,
7483 x_volume_type =>l_volume_type,
7484 x_return_status =>l_return_status
7485 );
7486 RETURN l_order_amount_quantity ;
7487 EXCEPTION
7488 WHEN OTHERS THEN
7489 NULL;
7490 RETURN 0;
7491 END;
7492
7493 ---------------------------------------------------------------------
7494 -- FUNCTION
7495 -- get_order_amount_quntity
7496 --
7497 -- PURPOSE
7498 --
7499 -- PARAMETERS
7500 -- p_list_header_id IN NUMBER,
7501 -- x_order_amount OUT NOCOPY NUMBER,
7502 -- x_new_discount OUT NOCOPY NUMBER,
7503 -- x_new_operator OUT NOCOPY VARCHAR2,
7504 -- x_old_discount OUT NOCOPY NUMBER,
7505 -- x_old_operator OUT NOCOPY VARCHAR2,
7506 -- x_return_status OUT NOCOPY VARCHAR2
7507 -- NOTES
7508 -- HISTORY
7509 -- 8/6/2002 Mumu Pande Create.
7510 -- 06/08/2005 feliu change cursor to handle case when g_order_gl_phase ='INVOICED';
7511 ----------------------------------------------------------------------
7512
7513 FUNCTION get_order_amount_quantity( p_list_header_id IN NUMBER,
7514 x_order_amount_quantity OUT NOCOPY NUMBER,
7515 x_new_discount OUT NOCOPY NUMBER,
7516 x_new_operator OUT NOCOPY VARCHAR2,
7517 x_old_discount OUT NOCOPY NUMBER,
7518 x_old_operator OUT NOCOPY VARCHAR2,
7519 x_volume_type OUT NOCOPY VARCHAR2,
7520 x_return_status OUT NOCOPY VARCHAR2
7521 ) RETURN NUMBER
7522 IS
7523 l_api_name VARCHAr2(30):= 'get_order_amount';
7524
7525 /*
7526 kdass 19-JUL-2004 Fix for 11.5.9 Bug 3742174
7527 Currently volume offer adjustment only considers shipped quantity. If total shipped quantity reaches new tier,
7528 the tier is adjusted. However for 'bill-only' order, there is no shipment involved, so shipped quantity is null,
7529 tier is never adjusted.
7530 To handle all possible scenarios,
7531 A) If profile 'OZF: Create GL Entries for Orders' is set to 'Shipped'
7532 1) if order line status is 'CLOSED' or 'INVOICED',
7533 a) if invoiced_quantity is not null, use invoiced_quantity
7534 b) else if shipped_quantity is not null, use shipped_quantity
7535 c) else, use nvl(ordered_quantity, 0)
7536 2) if order line status is 'SHIPPED',
7537 a) shipped_quantity is not null, use shipped_quantity
7538 b) else, use nvl(ordered_quantity, 0)
7539 B) A) If profile 'OZF: Create GL Entries for Orders' is set to 'Invoiced'
7540 1) if order line status is 'CLOSED' or 'INVOICED',
7541 a) if invoiced_quantity is not null, use invoiced_quantity
7542 b) else if shipped_quantity is not null, use shipped_quantity
7543 c) else, use nvl(ordered_quantity, 0)
7544 This cursor returns the order amount or order quantity depending on the value of the parameter p_amt_qty
7545 */
7546
7547 CURSOR c_order_amount_qty (p_list_header_id IN NUMBER, p_amt_qty IN VARCHAR2) IS
7548 --kdass 11-MAY-2005 Bug 4362575 changed unit_selling_price to unit_list_price
7549 SELECT SUM(DECODE(p_amt_qty, 'amt', line.unit_list_price, 1)*
7550 NVL(line.invoiced_quantity, NVL(line.shipped_quantity, NVL(line.ordered_quantity, 0)))
7551 ), header.transactional_curr_code
7552 FROM oe_order_lines_all line, oe_price_Adjustments adj, oe_order_headers_all header
7553 WHERE line.line_id = adj.line_id
7554 AND line.header_id = header.header_id
7555 AND line.header_id = adj.header_id
7556 AND adj.list_header_id = p_list_header_id
7557 AND adj.applied_flag = 'Y'
7558 AND line.cancelled_flag = 'N'
7559 AND line.booked_flag = 'Y'
7560 GROUP BY header.transactional_curr_code;
7561 --AND flow_status_code in ('CLOSED','INVOICED','SHIPPED');
7562
7563 -- For g_order_gl_phase ='INVOICED', only calculate order amount when flow_status_code = 'INVOICED'.
7564 -- and 'CLOSED').
7565 CURSOR c_invoice_amount_qty (p_list_header_id IN NUMBER, p_amt_qty IN VARCHAR2) IS
7566 --kdass 11-MAY-2005 Bug 4362575 changed unit_selling_price to unit_list_price
7567 SELECT SUM(DECODE(p_amt_qty, 'amt', line.unit_list_price, 1)*
7568 NVL(line.invoiced_quantity, NVL(line.shipped_quantity, NVL(line.ordered_quantity, 0)))
7569 ), header.transactional_curr_code
7570 FROM oe_order_lines_all line, oe_price_Adjustments adj, oe_order_headers_all header
7571 WHERE line.line_id = adj.line_id
7572 AND line.header_id = header.header_id
7573 AND line.header_id = adj.header_id
7574 AND adj.list_header_id = p_list_header_id
7575 AND adj.applied_flag = 'Y'
7576 AND line.cancelled_flag = 'N'
7577 AND line.booked_flag = 'Y'
7578 AND line.flow_status_code in ('CLOSED','INVOICED')
7579 GROUP BY header.transactional_curr_code;
7580
7581 /* remove it since we need to query tier in calling procedure. by feliu on 06/08/2005.
7582 CURSOR c_current_discount (p_list_header_id IN NUMBER,
7583 p_order_amount IN NUMBER) IS
7584 SELECT discount,
7585 discount_type_code
7586 FROM ozf_volume_offer_tiers
7587 WHERE p_order_amount BETWEEN
7588 tier_value_from AND tier_value_to
7589 AND qp_list_header_id = p_list_header_id;
7590 */
7591 CURSOR c_old_discount (p_list_header_id IN NUMBER) IS
7592 SELECT distinct operand,
7593 arithmetic_operator
7594 FROM qp_modifier_summary_v qp
7595 WHERE list_header_id = p_list_header_id;
7596
7597 CURSOR c_volume_type (p_list_header_id IN NUMBER) IS
7598 SELECT distinct volume_type
7599 FROM ozf_volume_offer_tiers tier
7600 WHERE qp_list_header_id = p_list_header_id;
7601
7602 CURSOR c_offer_curr IS
7603 SELECT nvl(transaction_currency_code,fund_request_curr_code)
7604 FROM ozf_offers
7605 WHERE qp_list_header_id = p_list_header_id;
7606
7607 l_volume_type VARCHAR2(30);
7608 l_offer_curr VARCHAR2(30);
7609 l_order_curr VARCHAR2(30);
7610 l_conv_amount NUMBER;
7611 l_rate NUMBER;
7612
7613 --profile: 'OZF: Create GL Entries for Orders' -- change as global constant by feliu on 06/21/2005
7614 -- l_order_gl_phase CONSTANT VARCHAR2 (15) := NVL(fnd_profile.VALUE ('OZF_ORDER_GLPOST_PHASE'), 'SHIPPED');
7615
7616 BEGIN
7617 x_return_status := fnd_api.g_ret_sts_success;
7618
7619 OPEN c_volume_type(p_list_header_id);
7620 FETCH c_volume_type INTO l_volume_type;
7621 CLOSE c_volume_type;
7622 x_volume_type := l_volume_type;
7623
7624 OPEN c_offer_curr;
7625 FETCH c_offer_curr INTO l_offer_curr;
7626 CLOSE c_offer_curr;
7627
7628 -- pricing_attr12 = AMOUNT
7629 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
7630 IF g_order_gl_phase ='SHIPPED' THEN
7631 OPEN c_order_amount_qty(p_list_header_id, 'amt');
7632 FETCH c_order_amount_qty INTO x_order_amount_quantity, l_order_curr;
7633 CLOSE c_order_amount_qty;
7634 ELSE
7635 OPEN c_invoice_amount_qty(p_list_header_id, 'amt');
7636 FETCH c_invoice_amount_qty INTO x_order_amount_quantity, l_order_curr;
7637 CLOSE c_invoice_amount_qty;
7638 END IF;
7639
7640 --kdass 31-MAR-2006 bug 5101720 convert from order currency to offer currency
7641 IF l_offer_curr <> l_order_curr THEN
7642
7643 ozf_utility_pvt.write_conc_log('order curr: ' || l_order_curr);
7644 ozf_utility_pvt.write_conc_log('offer curr: ' || l_offer_curr);
7645 ozf_utility_pvt.write_conc_log('order amount: ' || x_order_amount_quantity);
7646
7647 ozf_utility_pvt.convert_currency (x_return_status => x_return_status
7648 ,p_from_currency => l_order_curr
7649 ,p_to_currency => l_offer_curr
7650 ,p_from_amount => x_order_amount_quantity
7651 ,x_to_amount => l_conv_amount
7652 ,x_rate => l_rate
7653 );
7654
7655 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7656 ozf_utility_pvt.write_conc_log('x_return_status: ' || x_return_status);
7657 RETURN NULL;
7658 END IF;
7659
7660 x_order_amount_quantity := l_conv_amount;
7661 write_conc_log ('order amount after currency conversion: ' || x_order_amount_quantity);
7662
7663 END IF;
7664
7665 ELSE -- quantity
7666 IF g_order_gl_phase ='SHIPPED' THEN
7667 OPEN c_order_amount_qty(p_list_header_id, 'qty');
7668 FETCH c_order_amount_qty INTO x_order_amount_quantity, l_order_curr;
7669 CLOSE c_order_amount_qty;
7670 ELSE
7671 OPEN c_invoice_amount_qty(p_list_header_id, 'qty');
7672 FETCH c_invoice_amount_qty INTO x_order_amount_quantity, l_order_curr;
7673 CLOSE c_invoice_amount_qty;
7674 END IF;
7675 END IF;
7676
7677 /*
7678 OPEN c_current_discount(p_list_header_id,x_order_amount_quantity);
7679 FETCH c_current_discount INTO x_new_discount,x_new_operator;
7680 CLOSE c_current_discount;
7681 */
7682 --Get the existing Tier % or amount value executing in QP x2 .
7683 OPEN c_old_discount(p_list_header_id);
7684 FETCH c_old_discount INTO x_old_discount,x_old_operator;
7685 CLOSE c_old_discount;
7686
7687 RETURN x_order_amount_quantity;
7688
7689
7690 EXCEPTION
7691 WHEN OTHERS THEN
7692 x_return_status := fnd_api.g_ret_sts_error;
7693 RETURN NULL;
7694 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7695 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
7696 END IF;
7697 END ;
7698
7699
7700 ---------------------------------------------------------------------
7701 -- PROCEDURE
7702 -- volume_offer_adjustment
7703 --
7704 -- PURPOSE
7705 -- adjustment for volume offer.
7706
7707 -- PARAMETERS
7708 -- p_qp_list_header_id IN NUMBER
7709 -- p_offer_adjustment_id IN NUMBER,
7710 -- p_retroactive IN VARCHAR2,
7711 -- p_vol_off_type IN VARCHAR2
7712
7713 -- NOTES
7714 -- HISTORY
7715 -- 6/10/2005 feliu Create.
7716 -- for backdated adjustment, only make volume adjustment for these orders after effective date.
7717 ----------------------------------------------------------------------
7718
7719 PROCEDURE volume_offer_adjustment (
7720 p_qp_list_header_id IN NUMBER,
7721 p_vol_off_type IN VARCHAR2,
7722 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
7723 p_commit IN VARCHAR2 := fnd_api.g_false,
7724 x_return_status OUT NOCOPY VARCHAR2,
7725 x_msg_count OUT NOCOPY NUMBER,
7726 x_msg_data OUT NOCOPY VARCHAR2
7727 ) IS
7728
7729 --ninarasi: bug 15877269 - changed plan_curr_amount to fund_request_amount since plan_curr_amount is stored in order currency.
7730 --All calculations are in offer currency, so changed plan_curr_amount to fund_request_amount.
7731 --ninarasi Bug 16029659 - added exchange_rate_date in the query. Exchange_rate_date is used to store the shipped_date which will be used for calculations.
7732 --If gl_date gets changed later, then there will be no impact on volume offer calculations.
7733 CURSOR c_old_price_Adj(p_list_header_id IN NUMBER) IS
7734 SELECT old_Adj_amt,order_line_id, price_adjustment_id,exchange_rate_date,gl_date,object_type
7735 ,object_id, gl_posted_flag, utilization_id FROM
7736 ( SELECT sum(fund_request_amount) old_Adj_amt
7737 , order_line_id
7738 ,min(price_adjustment_id) price_adjustment_id
7739 ,min(exchange_rate_date) exchange_rate_date
7740 ,min(gl_date) gl_date
7741 ,object_type
7742 ,object_id
7743 ,'Y' gl_posted_flag
7744 ,min(utilization_id) utilization_id
7745 FROM ozf_funds_utilized_all_b
7746 WHERE plan_id = p_list_header_id
7747 AND plan_type = 'OFFR'
7748 -- AND gl_date is not NULL -- only process shipped or invoiced order.
7749 AND gl_posted_flag IN('Y','F')
7750 AND utilization_type IN ( 'ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
7751 AND price_adjustment_id IS NOT NULL
7752 GROUP BY order_line_id,object_type,object_id
7753 UNION ALL
7754 SELECT sum(fund_request_amount) old_Adj_amt
7755 , order_line_id
7756 ,min(price_adjustment_id) price_adjustment_id
7757 ,min(exchange_rate_date) exchange_rate_date
7758 ,min(gl_date) gl_date
7759 ,object_type
7760 ,object_id
7761 ,'X' gl_posted_flag
7762 ,min(utilization_id) utilization_id
7763 FROM ozf_funds_utilized_all_b
7764 WHERE plan_id = p_list_header_id
7765 AND plan_type = 'OFFR'
7766 AND gl_posted_flag = 'X'
7767 AND utilization_type IN ('SALES_ACCRUAL','ADJUSTMENT','ACCRUAL')
7768 AND price_adjustment_id IS NOT NULL
7769 GROUP BY order_line_id,object_type,object_id
7770 UNION ALL
7771 SELECT sum(fund_request_amount) old_Adj_amt
7772 , order_line_id
7773 ,min(price_adjustment_id) price_adjustment_id
7774 ,min(exchange_rate_date) exchange_rate_date
7775 ,min(gl_date) gl_date
7776 ,object_type
7777 ,object_id
7778 ,NULL gl_posted_flag
7779 ,min(utilization_id) utilization_id
7780 FROM ozf_funds_utilized_all_b
7781 WHERE plan_id = p_list_header_id
7782 AND plan_type = 'OFFR'
7783 AND gl_posted_flag IS NULL
7784 AND utilization_type IN ('UTILIZED','ADJUSTMENT')
7785 AND price_adjustment_id IS NOT NULL
7786 GROUP BY order_line_id,object_type,object_id)
7787 ORDER BY gl_date;
7788
7789 CURSOR c_order_line_info(p_order_line_id IN NUMBER) IS
7790 SELECT DECODE(line.line_category_code,'ORDER',line.ordered_quantity,
7791 'RETURN', -line.ordered_quantity) ordered_quantity,
7792 DECODE(line.line_category_code,'ORDER',NVL(line.shipped_quantity,line.ordered_quantity),
7793 'RETURN', line.invoiced_quantity,
7794 line.ordered_quantity) shipped_quantity,
7795 line.invoiced_quantity,
7796 line.unit_list_price,
7797 line.line_id,
7798 line.actual_shipment_date,
7799 line.fulfillment_date, -- invoiced date ?????
7800 line.inventory_item_id,
7801 header.transactional_curr_code,
7802 line.shipping_quantity, -- Catch Weight ER
7803 line.shipping_quantity_uom, -- Catch Weight ER
7804 line.shipping_quantity2, -- Catch Weight ER
7805 line.shipping_quantity_uom2, -- Catch Weight ER
7806 line.fulfillment_base -- Catch Weight ER
7807 FROM oe_order_lines_all line, oe_order_headers_all header
7808 WHERE line.line_id = p_order_line_id
7809 AND line.header_id = header.header_id;
7810
7811
7812 CURSOR c_resale_line_info(p_resale_line_id IN NUMBER, p_adj_id IN NUMBER) IS
7813 /* SELECT quantity ordered_quantity ,
7814 quantity shipped_quantity,
7815 quantity invoiced_quantity,
7816 purchase_price unit_list_price,
7817 resale_line_id line_id,
7818 NVL(date_shipped, date_ordered) actual_shipment_date,
7819 NVL(date_shipped, date_ordered) fulfillment_date, -- invoiced date ?????
7820 inventory_item_id,
7821 currency_code --dummy column
7822 FROM OZF_RESALE_LINES_ALL
7823 WHERE resale_line_id = p_resale_line_id;
7824 */
7825 ----- fix bug 5671169
7826 SELECT line.quantity ordered_quantity ,
7827 line.quantity shipped_quantity,
7828 line.quantity invoiced_quantity,
7829 adj.priced_unit_price unit_list_price,
7830 line.resale_line_id line_id,
7831 NVL(line.date_shipped, line.date_ordered) actual_shipment_date,
7832 NVL(line.date_shipped, line.date_ordered) fulfillment_date, -- invoiced date ?????
7833 line.inventory_item_id,
7834 line.currency_code, --dummy column
7835 line.quantity, -- Catch Weight ER : dummy column
7836 line.uom_code, -- Catch Weight ER : dummy column
7837 line.quantity, -- Catch Weight ER : dummy column
7838 line.uom_code, -- Catch Weight ER : dummy column
7839 NULL -- Catch Weight ER : dummy column
7840 FROM OZF_RESALE_LINES_ALL line,ozf_resale_adjustments_all adj
7841 WHERE line.resale_line_id = p_resale_line_id
7842 AND adj.resale_adjustment_id = p_adj_id
7843 AND line.resale_line_id = adj.resale_line_id;
7844
7845
7846 CURSOR c_prior_tiers(p_parent_discount_id IN NUMBER, p_volume IN NUMBER ) IS
7847 SELECT offer_discount_line_id ,volume_from ,volume_to, discount
7848 FROM ozf_offer_discount_lines
7849 WHERE parent_discount_line_id = p_parent_discount_id
7850 AND p_volume >= volume_from
7851 ORDER BY volume_from DESC;
7852
7853
7854 CURSOR c_discount_header(p_discount_line_id IN NUMBER) IS
7855 SELECT discount_type,volume_type
7856 FROM ozf_offer_discount_lines
7857 WHERE offer_discount_line_id = p_discount_line_id
7858 AND tier_type = 'PBH';
7859
7860 CURSOR c_get_group(p_order_line_id IN NUMBER,p_list_header_id IN NUMBER) IS
7861 SELECT group_no,pbh_line_id,include_volume_flag
7862 FROM ozf_order_group_prod
7863 WHERE order_line_id = p_order_line_id
7864 AND qp_list_header_id = p_list_header_id;
7865
7866 CURSOR c_market_option(p_list_header_id IN NUMBER, p_group_id IN NUMBER) IS
7867 SELECT opt.retroactive_flag
7868 FROM ozf_offr_market_options opt
7869 WHERE opt.GROUP_NUMBER= p_group_id
7870 AND opt.qp_list_header_id = p_list_header_id;
7871
7872 --fix for bug 5975203
7873 CURSOR c_current_discount(p_volume IN NUMBER, p_parent_discount_id IN NUMBER) IS
7874 SELECT discount
7875 FROM ozf_offer_discount_lines
7876 WHERE p_volume > volume_from
7877 AND p_volume <= volume_to
7878 AND parent_discount_line_id = p_parent_discount_id;
7879
7880 /* CURSOR c_max_volume(p_order_line_id IN NUMBER, p_qp_list_header_id IN NUMBER,p_source_code IN VARCHAR2) IS
7881 SELECT summ.individual_volume
7882 FROM ozf_volume_detail det,ozf_volume_summary summ
7883 WHERE det.order_line_id = p_order_line_id
7884 AND det.qp_list_header_id = p_qp_list_header_id
7885 AND det.volume_track_type = summ.individual_type
7886 AND det.qp_list_header_id = summ.qp_list_header_id
7887 AND det.source_code = p_source_code;
7888 */
7889 CURSOR c_preset_tier(p_pbh_line_id IN NUMBER, p_qp_list_header_id IN NUMBER,p_group_id IN NUMBER) IS
7890 SELECT a.discount
7891 FROM ozf_offer_discount_lines a, ozf_market_preset_tiers b, ozf_offr_market_options c
7892 WHERE a.offer_discount_line_id = b.dis_offer_discount_id
7893 AND b.pbh_offer_discount_id = p_pbh_line_id
7894 AND b.offer_market_option_id = c.offer_market_option_id
7895 AND c.qp_list_header_id = p_qp_list_header_id
7896 AND c.group_number = p_group_id;
7897
7898 CURSOR c_sales_accrual(p_list_header_id IN NUMBER) IS
7899 SELECT 'X' from ozf_funds_all_b
7900 WHERE plan_id= p_list_header_id
7901 AND accrual_basis = 'SALES'
7902 UNION
7903 SELECT 'X' from ozf_funds_all_b
7904 WHERE plan_id = p_list_header_id
7905 AND accrual_basis = 'CUSTOMER'
7906 AND liability_flag = 'N';
7907
7908 CURSOR c_unit_discount(p_order_line_id IN NUMBER, p_price_adjust_id NUMBER) IS
7909 SELECT SUM(adjusted_amount_per_pqty)
7910 FROM oe_price_adjustments
7911 WHERE line_id = p_order_line_id
7912 AND accrual_flag = 'N'
7913 AND applied_flag = 'Y'
7914 AND list_line_type_code IN ('DIS', 'SUR', 'PBH', 'FREIGHT_CHARGE')
7915 and pricing_group_sequence <
7916 (SELECT pricing_group_sequence FROM oe_price_adjustments
7917 WHERE price_Adjustment_id = p_price_adjust_id) ;
7918
7919 CURSOR c_discount(p_order_line_id IN NUMBER, p_price_adjust_id NUMBER) IS
7920 SELECT SUM(adjusted_amount_per_pqty)
7921 FROM oe_price_adjustments
7922 WHERE line_id = p_order_line_id
7923 AND accrual_flag = 'N'
7924 AND applied_flag = 'Y'
7925 AND list_line_type_code IN ('DIS', 'SUR', 'PBH', 'FREIGHT_CHARGE');
7926
7927 CURSOR c_get_tier_limits (p_parent_discount_id IN NUMBER) IS
7928 SELECT MIN(volume_from),MAX(volume_to)
7929 FROM ozf_offer_discount_lines
7930 WHERE parent_discount_line_id = p_parent_discount_id;
7931
7932 CURSOR c_get_max_tier (p_max_volume_to IN NUMBER,p_parent_discount_id IN NUMBER) IS
7933 SELECT discount
7934 FROM ozf_offer_discount_lines
7935 WHERE volume_to =p_max_volume_to
7936 AND parent_discount_line_id = p_parent_discount_id;
7937
7938 CURSOR c_offer_curr IS
7939 SELECT nvl(transaction_currency_code,fund_request_curr_code),
7940 transaction_currency_code,
7941 offer_id
7942 FROM ozf_offers
7943 WHERE qp_list_header_id = p_qp_list_header_id;
7944
7945 --22-FEB-2007 kdass bug 5759350 - changed datatype of p_product_id from NUMBER to VARCHAR2 based on Feng's suggestion
7946 --fix for bug 5979971
7947 CURSOR c_apply_discount(p_offer_id IN NUMBER,p_line_id IN NUMBER) IS
7948 SELECT NVL(apply_discount_flag,'N')
7949 FROM ozf_order_group_prod
7950 WHERE offer_id = p_offer_id
7951 AND order_line_id = p_line_id;
7952
7953
7954 l_api_name CONSTANT VARCHAR2(30) := 'volume_offer_adjustment';
7955 l_full_name VARCHAR2(70):= g_pkg_name ||'.'||l_api_name ||' : ';
7956 l_api_version CONSTANT NUMBER := 1.0;
7957 l_return_status VARCHAR2 (20) := fnd_api.g_ret_sts_success;
7958 l_msg_count NUMBER;
7959 l_msg_data VARCHAR2 (2000) := NULL;
7960 l_volume_offer_tier_id NUMBER;
7961 l_current_offer_tier_id NUMBER;
7962 l_order_amount NUMBER;
7963 l_old_discount NUMBER;
7964 l_new_discount NUMBER;--
7965 l_new_operator VARCHAR2(30);
7966 l_old_operator VARCHAR2(30);
7967 y1 NUMBER; -- Initial Adjsutment
7968 l_current_max_tier NUMBER;
7969 l_current_min_tier NUMBER;
7970 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type ;
7971 l_adj_amount NUMBER;
7972 l_volume_type VARCHAR2(30);
7973 l_current_tier_value NUMBER;
7974 l_total NUMBER;
7975 l_value NUMBER;
7976 l_previous_tier_max NUMBER;
7977 l_new_utilization NUMBER;
7978 l_total_order NUMBER;
7979 l_total_amount NUMBER;
7980 l_returned_flag BOOLEAN := false;
7981 l_qp_list_header_id NUMBER := p_qp_list_header_id;
7982 l_retroactive VARCHAR2(1) ;
7983 l_trx_date DATE;
7984 l_volume NUMBER;
7985 l_group_id NUMBER;
7986 l_pbh_line_id NUMBER;
7987 l_discount_type VARCHAR2(30);
7988 l_source_code VARCHAR2(30);
7989 l_preset_tier NUMBER;
7990 l_order_line_info c_order_line_info%ROWTYPE;
7991 l_order_line_id NUMBER;
7992 l_order_type VARCHAR2(30);
7993 l_sales_accrual_flag VARCHAR2 (3);
7994 l_volume_offer_type VARCHAR2(30) := p_vol_off_type;
7995 l_selling_price NUMBER;
7996 l_unit_discount NUMBER;
7997 l_min_tier NUMBER;
7998 l_max_tier NUMBER;
7999 l_offer_curr VARCHAR2(30);
8000 l_conv_price NUMBER;
8001 l_rate NUMBER;
8002 l_included_vol_flag VARCHAR2(1);
8003 l_amountTbl amountTbl ;
8004 l_glDateTbl glDateTbl ;
8005 l_exchangeRateDateTbl exchangeRateDateTbl;
8006 l_objectTypeTbl objectTypeTbl ;
8007 l_objectIdTbl objectIdTbl;
8008 l_priceAdjustmentIDTbl priceAdjustmentIDTbl ;
8009 l_glPostedFlagTbl glPostedFlagTbl;
8010 l_orderLineIdTbl orderLineIdTbl;
8011 l_conv_amt_value NUMBER;
8012 l_adj_conv_amount NUMBER;
8013
8014
8015 l_offer_id NUMBER;
8016 l_apply_discount VARCHAR2(1) ;
8017 l_transaction_currency_code VARCHAR2(30);
8018
8019 -- julou bug 6348078. cursor to get transaction_date for IDSM line.
8020 CURSOR c_trx_date(p_line_id NUMBER) IS
8021 SELECT transaction_date
8022 FROM ozf_sales_transactions
8023 WHERE source_code = 'IS'
8024 AND line_id = p_line_id;
8025
8026 --Added for bug 7030415
8027 l_utilizationIdTbl utilizationIdTbl;
8028 CURSOR c_utilization_details(l_utilization_id IN NUMBER) IS
8029 SELECT exchange_rate_type, org_id
8030 FROM ozf_funds_utilized_all_b
8031 WHERE utilization_id=l_utilization_id;
8032
8033 l_conv_type ozf_funds_utilized_all_b.exchange_rate_type%TYPE;
8034 l_org_id NUMBER;
8035
8036 -- Catch Weight - start
8037 CURSOR c_offer_uom_code(l_offer_id NUMBER) IS
8038 SELECT uom_code
8039 FROM ozf_offer_discount_lines
8040 WHERE offer_id = l_offer_id;
8041
8042 l_offer_uom_code VARCHAR2(10);
8043 l_quantity NUMBER;
8044 l_cw_quantity NUMBER;
8045 l_cw_quantity_uom VARCHAR(10);
8046 -- Catch Weight - end
8047
8048 BEGIN
8049 IF G_DEBUG THEN
8050 ozf_utility_pvt.debug_message(' /*************************** DEBUG MESSAGE START *************************/' || l_api_name);
8051 END IF;
8052 write_conc_log(' /*************************** DEBUG MESSAGE START *************************/' || l_api_name);
8053
8054 SAVEPOINT volume_offer_adjustment;
8055
8056 IF g_offer_id_tbl.FIRST IS NOT NULL THEN
8057 FOR i IN g_offer_id_tbl.FIRST .. g_offer_id_tbl.LAST
8058 LOOP
8059 IF g_offer_id_tbl(i) = l_qp_list_header_id THEN
8060 write_conc_log (' no adjustment for offer: ' || l_qp_list_header_id);
8061 GOTO l_endoffloop;
8062 END IF;
8063 END LOOP;
8064 END IF;
8065
8066 OPEN c_sales_accrual(l_qp_list_header_id);
8067 FETCH c_sales_accrual INTO l_sales_accrual_flag;
8068 CLOSE c_sales_accrual;
8069
8070 IF l_sales_accrual_flag is NOT NULL THEN
8071 l_order_type := 'SHIPPED'; --'BOOKED'; -- set to shipped for sales accrual untill decision has been made.
8072 ELSIF g_order_gl_phase ='SHIPPED' AND l_volume_offer_type = 'ACCRUAL' THEN
8073 l_order_type := 'SHIPPED';
8074 ELSIF g_order_gl_phase ='INVOICED' AND l_volume_offer_type = 'ACCRUAL' THEN
8075 l_order_type := 'INVOICED';
8076 ELSIF l_volume_offer_type = 'OFF_INVOICE' THEN
8077 l_order_type := 'INVOICED';
8078 END IF;
8079
8080 l_total_order := 0; -- total ordered amount for offer.
8081 l_total_amount := 0; --- total utilization amount for offer.
8082
8083 OPEN c_old_price_adj(l_qp_list_header_id);
8084 --FOR l_old_price_adj IN c_old_price_adj(l_qp_list_header_id)
8085 LOOP
8086 --ninarasi Bug 16029659 added l_exchangeRateDateTbl
8087 FETCH c_old_price_adj BULK COLLECT INTO l_amountTbl, l_orderLineIdTbl
8088 , l_priceAdjustmentIDTbl, l_exchangeRateDateTbl, l_glDateTbl
8089 , l_objectTypeTbl, l_objectIdTbl, l_glPostedFlagTbl, l_utilizationIdTbl --Added for bug 7030415
8090 LIMIT g_bulk_limit;
8091 FOR i IN NVL(l_priceAdjustmentIDTbl.FIRST, 1) .. NVL(l_priceAdjustmentIDTbl.LAST, 0) LOOP
8092 write_conc_log(' CWWWwwww l_glDateTbl: '|| l_glDateTbl(i) );
8093 IF l_objectTypeTbl(i) ='ORDER' THEN
8094 IF G_DEBUG THEN
8095 ozf_utility_pvt.debug_message(' order_line_id: '|| l_orderLineIdTbl(i) );
8096 END IF;
8097 write_conc_log(' order_line_id: '|| l_orderLineIdTbl(i) );
8098
8099 l_source_code := 'OM';
8100 l_order_line_id := l_orderLineIdTbl(i);
8101 OPEN c_order_line_info(l_order_line_id);
8102 FETCH c_order_line_info INTO l_order_line_info;
8103 CLOSE c_order_line_info;
8104
8105 IF l_priceAdjustmentIDTbl(i) = -1 THEN
8106 OPEN c_discount(l_order_line_id,l_priceAdjustmentIDTbl(i));
8107 FETCH c_discount INTO l_unit_discount;
8108 CLOSE c_discount;
8109 ELSE
8110 OPEN c_unit_discount(l_order_line_id,l_priceAdjustmentIDTbl(i));
8111 FETCH c_unit_discount INTO l_unit_discount;
8112 CLOSE c_unit_discount;
8113 END IF;
8114
8115 write_conc_log(' l_unit_discount: '|| l_unit_discount);
8116
8117 ELSE
8118 IF G_DEBUG THEN
8119 ozf_utility_pvt.debug_message(' resale_line_id: '|| l_objectIdTbl(i) );
8120 END IF;
8121 write_conc_log(' resale_line_id: '|| l_objectIdTbl(i));
8122
8123 l_source_code := 'IS';
8124 l_order_line_id := l_objectIdTbl(i);
8125 OPEN c_resale_line_info(l_order_line_id,l_priceAdjustmentIDTbl(i));
8126 FETCH c_resale_line_info INTO l_order_line_info;
8127 CLOSE c_resale_line_info;
8128 END IF;
8129
8130 l_selling_price := l_order_line_info.unit_list_price + NVL(l_unit_discount,0); -- discount is negative
8131 write_conc_log(' l_selling_price: '|| l_selling_price);
8132
8133 OPEN c_offer_curr;
8134 FETCH c_offer_curr INTO l_offer_curr, l_transaction_currency_code, l_offer_id;
8135 CLOSE c_offer_curr;
8136
8137 IF l_amountTbl(i) = 0 THEN -- fix bug 5689866
8138 --21-MAY-07 kdass fixed bug 6059036 - added condition for direct and indirect orders
8139 IF l_objectTypeTbl(i) ='ORDER' THEN
8140 OPEN c_apply_discount(l_offer_id, l_orderLineIdTbl(i));
8141 FETCH c_apply_discount INTO l_apply_discount;
8142 CLOSE c_apply_discount;
8143 ELSE
8144 OPEN c_apply_discount(l_offer_id, l_objectIdTbl(i));
8145 FETCH c_apply_discount INTO l_apply_discount;
8146 CLOSE c_apply_discount;
8147 END IF;
8148
8149 write_conc_log('l_apply_discount: ' || l_apply_discount);
8150
8151 IF l_apply_discount ='N' THEN
8152 IF G_DEBUG THEN
8153 ozf_utility_pvt.debug_message('not apply discount: ' || l_order_line_info.inventory_item_id);
8154 END IF;
8155 write_conc_log(' not apply discount:'|| l_order_line_info.inventory_item_id);
8156 GOTO l_endoffloop;
8157 END IF;
8158 END IF; -- bug 5689866
8159
8160 --Added for bug 7030415
8161 OPEN c_utilization_details(l_utilizationIdTbl(i));
8162 FETCH c_utilization_details INTO l_conv_type,l_org_id;
8163 CLOSE c_utilization_details;
8164
8165 l_act_util_rec.org_id := l_org_id;
8166
8167 --12.2, multi-currency enhancement.
8168 IF l_transaction_currency_code IS NOT NULL
8169 AND l_transaction_currency_code <> l_order_line_info.transactional_curr_code THEN
8170
8171 ozf_utility_pvt.write_conc_log('order curr: ' || l_order_line_info.transactional_curr_code);
8172 ozf_utility_pvt.write_conc_log('offer curr: ' || l_transaction_currency_code);
8173 ozf_utility_pvt.write_conc_log('selling price: ' || l_selling_price);
8174
8175
8176
8177 ozf_utility_pvt.write_conc_log('l_conv_type: ' || l_conv_type);
8178
8179
8180 ozf_utility_pvt.convert_currency (x_return_status => l_return_status
8181 ,p_conv_type => l_conv_type --7030415
8182 ,p_conv_date => OZF_ACCRUAL_ENGINE.G_FAE_START_DATE
8183 --l_order_line_info.actual_shipment_date
8184 ,p_from_currency => l_order_line_info.transactional_curr_code
8185 ,p_to_currency => l_transaction_currency_code
8186 ,p_from_amount => l_selling_price
8187 ,x_to_amount => l_conv_price
8188 ,x_rate => l_rate
8189 );
8190
8191 IF l_return_status = fnd_api.g_ret_sts_error THEN
8192 RAISE fnd_api.g_exc_error;
8193 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8194 RAISE fnd_api.g_exc_unexpected_error;
8195 END IF;
8196
8197 l_selling_price := l_conv_price;
8198 write_conc_log ('selling price after currency conversion: ' || l_selling_price);
8199
8200 END IF;
8201 --ninarasi: bug 15877269 - selling price is in order currency which is in turn used to calculated the order line amount.
8202 --While calculating the utilization amount, order line amount is in order currency and the discount
8203 --is in offer currency which is wrong. So, converted the selling price to offer currency in case of NULL currency offers
8204 --and when the offer currency and order currency does not match.
8205 IF l_transaction_currency_code IS NULL AND l_offer_curr <> l_order_line_info.transactional_curr_code THEN
8206
8207 --ninarasi Bug 16029659 - changed conversion date used from gl_date to exchange_rate_date since exchange_rate_date stores the shipped date.
8208 ozf_utility_pvt.convert_currency(x_return_status => l_return_status
8209 ,p_from_currency => l_order_line_info.transactional_curr_code
8210 ,p_to_currency => l_offer_curr
8211 ,p_conv_type => l_conv_type
8212 ,p_conv_date => l_exchangeRateDateTbl(i)
8213 ,p_from_amount => l_selling_price
8214 ,x_to_amount => l_conv_price
8215 ,x_rate => l_rate);
8216 l_selling_price := l_conv_price;
8217 write_conc_log ('selling price after currency conversion: ' || l_selling_price);
8218 END IF;
8219
8220 /* IF g_order_gl_phase = 'SHIPPED' THEN
8221 l_trx_date := l_order_line_info.actual_shipment_date;
8222 ELSE
8223 l_trx_date := l_order_line_info.fulfillment_date;
8224 END IF;
8225 */
8226 -- for testing
8227 /* IF l_volume = 0 THEN
8228
8229 l_volume := get_order_amount_quantity( l_qp_list_header_id ,
8230 l_order_amount,
8231 l_new_discount,
8232 l_new_operator,
8233 l_old_discount, -- discount in QP.
8234 l_old_operator,
8235 l_volume_type,
8236 l_return_status
8237 );
8238 write_conc_log(' l_volume from test: '|| l_volume );
8239
8240 END IF;
8241 */
8242
8243 OPEN c_get_group(l_order_line_id,l_qp_list_header_id);
8244 FETCH c_get_group INTO l_group_id,l_pbh_line_id,l_included_vol_flag;
8245 CLOSE c_get_group;
8246
8247 IF G_DEBUG THEN
8248 ozf_utility_pvt.debug_message(' l_group_id: '|| l_group_id );
8249 ozf_utility_pvt.debug_message(' l_pbh_line_id: '|| l_pbh_line_id );
8250 ozf_utility_pvt.debug_message(' l_included_vol_flag: '|| l_included_vol_flag );
8251 END IF;
8252 write_conc_log(' l_group_id: '|| l_group_id );
8253 write_conc_log(' l_pbh_line_id: '|| l_pbh_line_id );
8254 write_conc_log(' l_included_vol_flag: '|| l_included_vol_flag );
8255
8256 IF l_group_id is NULL OR l_pbh_line_id is NULL THEN
8257 GOTO l_endoffloop;
8258 END IF;
8259
8260 OPEN c_market_option(l_qp_list_header_id,l_group_id);
8261 FETCH c_market_option INTO l_retroactive;
8262 CLOSE c_market_option;
8263
8264 OPEN c_discount_header(l_pbh_line_id);
8265 FETCH c_discount_header INTO l_discount_type,l_volume_type;
8266 CLOSE c_discount_header;
8267
8268 /* IF l_retroactive = 'Y' THEN -- for retroactive, always takes the max volume.
8269 OPEN c_max_volume(l_order_line_id,l_qp_list_header_id,l_source_code);
8270 FETCH c_max_volume INTO l_volume;
8271 CLOSE c_max_volume;-- not work for non-include volume product since query return null. 12/11/06 by feliu
8272 ELSE
8273 */
8274
8275 IF l_retroactive = 'Y' THEN
8276 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y l_qp_list_header_id = '|| l_qp_list_header_id);
8277 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y l_order_line_id = '|| l_order_line_id);
8278 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y l_source_code = '|| l_source_code);
8279 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y trx_date = '|| sysdate+1);
8280 ozf_volume_calculation_pub.get_volume
8281 (p_init_msg_list =>fnd_api.g_false
8282 ,p_api_version =>1.0
8283 ,p_commit =>fnd_api.g_false
8284 ,x_return_status =>l_return_status
8285 ,x_msg_count => l_msg_count
8286 ,x_msg_data => l_msg_data
8287 ,p_qp_list_header_id => l_qp_list_header_id
8288 ,p_order_line_id =>l_order_line_id
8289 ,p_trx_date =>sysdate+1
8290 ,p_source_code => l_source_code
8291 ,x_acc_volume => l_volume
8292 );
8293 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y l_volume = '|| l_volume);
8294 ELSE
8295 -- julou bug 6348078. can't use gl_date for IDSM line. it's different from transaction_date
8296 IF l_source_code = 'IS' THEN
8297 write_conc_log('calculating transaction_date for non-retro offer, IS line_id: ' || l_order_line_id);
8298 OPEN c_trx_date(l_order_line_id);
8299 FETCH c_trx_date INTO l_trx_date;
8300 CLOSE c_trx_date;
8301 ELSE
8302 --ninarasi Bug 16029659 - passed exchange_rate_date instead of gl_date.
8303 l_trx_date := l_exchangeRateDateTbl(i);
8304 END IF;
8305 write_conc_log('transaction_date after conversion: ' || TO_CHAR(l_trx_date, 'YYYY-MM-DD HH:MI:SS'));
8306 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = N l_qp_list_header_id = '|| l_qp_list_header_id);
8307 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = N l_order_line_id = '|| l_order_line_id);
8308 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = N l_source_code = '|| l_source_code);
8309 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = Y trx_date = '|| l_trx_date);
8310 ozf_volume_calculation_pub.get_volume
8311 (p_init_msg_list =>fnd_api.g_false
8312 ,p_api_version =>1.0
8313 ,p_commit =>fnd_api.g_false
8314 ,x_return_status =>l_return_status
8315 ,x_msg_count => l_msg_count
8316 ,x_msg_data => l_msg_data
8317 ,p_qp_list_header_id => l_qp_list_header_id
8318 ,p_order_line_id =>l_order_line_id
8319 --,p_trx_date =>l_glDateTbl(i)
8320 ,p_trx_date => l_trx_date
8321 ,p_source_code => l_source_code
8322 ,x_acc_volume => l_volume
8323 );
8324 ozf_utility_pvt.write_conc_log('Catch Weight --> l_retroactive = N l_volume = '|| l_volume);
8325 END IF;
8326
8327 IF l_return_status = fnd_api.g_ret_sts_error THEN
8328 RAISE fnd_api.g_exc_error;
8329 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8330 RAISE fnd_api.g_exc_unexpected_error;
8331 END IF;
8332 -- END IF; --l_retroactive = 'Y'
8333
8334 IF G_DEBUG THEN
8335 ozf_utility_pvt.debug_message(' l_volume: '|| l_volume );
8336 END IF;
8337 write_conc_log(' l_volume: '|| l_volume );
8338
8339 -- l_new_discount := 0;
8340 OPEN c_current_discount(l_volume,l_pbh_line_id);
8341 FETCH c_current_discount INTO l_new_discount;
8342 CLOSE c_current_discount;
8343
8344 -- fix bug 5055425 by feliu on 02/23/2006
8345 IF l_new_discount is NULL THEN
8346 OPEN c_get_tier_limits(l_pbh_line_id);
8347 FETCH c_get_tier_limits INTO l_min_tier,l_max_tier;
8348 CLOSE c_get_tier_limits;
8349 IF l_volume < l_min_tier THEN
8350 l_new_discount := 0;
8351 ELSE
8352 OPEN c_get_max_tier(l_max_tier,l_pbh_line_id);
8353 FETCH c_get_max_tier INTO l_new_discount;
8354 CLOSE c_get_max_tier;
8355 END IF;
8356 IF G_DEBUG THEN
8357 ozf_utility_pvt.debug_message(' l_new_discount: '|| l_new_discount );
8358 END IF;
8359 write_conc_log(' l_new_discount: '|| l_new_discount );
8360 END IF;
8361
8362 l_preset_tier := NULL;
8363 OPEN c_preset_tier(l_pbh_line_id,l_qp_list_header_id,l_group_id);
8364 FETCH c_preset_tier INTO l_preset_tier;
8365 CLOSE c_preset_tier;
8366
8367 write_conc_log( ' l_preset_tier=' || l_preset_tier);
8368 write_conc_log( ' l_new_discount=' || l_new_discount);
8369
8370
8371 IF l_preset_tier is NOT NULL AND l_preset_tier > l_new_discount THEN
8372 l_new_discount := l_preset_tier;
8373 IF G_DEBUG THEN
8374 ozf_utility_pvt.debug_message('not reach preset tier: ');
8375 END IF;
8376 write_conc_log(' not reach preset tier:');
8377 END IF;
8378
8379 l_new_utilization := 0;
8380 l_value :=0;
8381 l_adj_amount := 0;
8382 write_conc_log(' l_volume_type : ' || l_volume_type);
8383 write_conc_log(' l_order_type : ' || l_order_type);
8384 write_conc_log(' l_order_line_info.shipped_quantity : ' || l_order_line_info.shipped_quantity);
8385 write_conc_log(' l_selling_price : ' || l_selling_price);
8386
8387
8388 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN -- volume type = AMOUNT
8389
8390 IF l_order_type = 'SHIPPED' THEN
8391 l_value := l_order_line_info.shipped_quantity * l_selling_price ;
8392 ELSIF l_order_type = 'INVOICED' THEN
8393 l_value := l_order_line_info.invoiced_quantity * l_selling_price ;
8394 ELSE
8395 l_value := l_order_line_info.ordered_quantity * l_selling_price ;
8396 END IF;
8397 ELSE -- tiers by quantity
8398 -- [Catch Weight Calculation:
8399 -- Order Booked : 3 Case = 36 Ea = 360 Pounds
8400 -- Order Shipped : (shipping_quantity)300 Pounds = 2.5 Case
8401 -- Volume Offer : Tiers By Quantity, Discount By Percent(1% per Pound)
8402 -- l_volume = 300
8403 -- l_value = 360
8404 -- Volume Offer : Tiers By Quantity, Discount By Percent(1% per Case)
8405 -- l_volume = 2.5
8406 -- l_value = 3
8407 -- Volume Offer : Tiers By Quantity, Discount By Amount(1 AMT per Pound)
8408 -- l_volume = 300
8409 -- l_value = 300
8410 -- Volume Offer : Tiers By Quantity, Discount By Percent(1 AMT per Case)
8411 -- l_volume = 2.5
8412 -- l_value = 2.5 ]
8413 -- Catch Weight - start
8414 OPEN c_offer_uom_code(l_offer_id);
8415 FETCH c_offer_uom_code INTO l_offer_uom_code;
8416 CLOSE c_offer_uom_code;
8417 ozf_utility_pvt.write_conc_log('EXT PVT Catch Weight 1--> offer uom code ='|| l_offer_uom_code);
8418
8419 /*OZF_UTILITY_PVT.get_catch_weight_quantity (
8420 p_inventory_item_id => l_order_line_info.inventory_item_id,
8421 p_order_line_id => l_order_line_id,
8422 x_return_status => l_return_status,
8423 x_cw_quantity => l_cw_quantity,
8424 x_cw_quantity_uom => l_cw_quantity_uom );*/
8425
8426 -- getting fulfillment_base from OE API. In case of performance issue can think of using fulfillment_base from existing cursor
8427 l_order_line_info.fulfillment_base := OE_DUAL_UOM_UTIL.get_fulfillment_base(l_order_line_id) ;
8428
8429 IF l_order_line_info.fulfillment_base = 'S' THEN
8430 l_cw_quantity := l_order_line_info.shipping_quantity;
8431 l_cw_quantity_uom := l_order_line_info.shipping_quantity_uom;
8432 ELSE
8433 l_cw_quantity := NVL(l_order_line_info.shipping_quantity2, l_order_line_info.shipping_quantity);
8434 l_cw_quantity_uom := NVL(l_order_line_info.shipping_quantity_uom2, l_order_line_info.shipping_quantity_uom);
8435 END IF;
8436
8437 IF l_offer_uom_code <> l_cw_quantity_uom THEN
8438 l_quantity :=
8439 inv_convert.inv_um_convert(l_order_line_info.inventory_item_id -- item_id
8440 ,NULL -- precision
8441 ,l_cw_quantity -- from_quantity
8442 ,l_cw_quantity_uom -- from_unit
8443 ,l_offer_uom_code -- to_unit
8444 ,NULL -- from_name
8445 ,NULL -- to_name
8446 );
8447 IF (l_quantity = -99999) THEN
8448 ozf_utility_pvt.write_conc_log ('Error in UOM conversion');
8449 END IF;
8450 ELSE
8451 l_quantity := l_cw_quantity ;
8452 END IF;
8453 ozf_utility_pvt.write_conc_log('Catch Weight --> l_quantity = '|| l_quantity);
8454 -- Catch Weight - end
8455 IF l_order_type = 'SHIPPED' THEN
8456 IF l_discount_type = '%' THEN
8457 l_value := l_order_line_info.shipped_quantity ;
8458 ELSE
8459 l_value := l_quantity ; -- Catch Weight
8460 END IF;
8461 ELSIF l_order_type = 'INVOICED' THEN
8462 IF l_discount_type = '%' THEN
8463 l_value := l_order_line_info.invoiced_quantity ;
8464 ELSE
8465 l_value := l_quantity ; -- Catch Weight
8466 END IF;
8467 ELSE
8468 l_value := l_order_line_info.ordered_quantity ;
8469 END IF;
8470 END IF;
8471
8472 --For retroactive volume offer.need to make adjustment for all of orders in this offer.
8473 write_conc_log('ozfvadeb.pls ---> l_retroactive = '|| l_retroactive);
8474 write_conc_log('ozfvadeb.pls ---> l_discount_type = '|| l_discount_type);
8475 write_conc_log('ozfvadeb.pls ---> l_volume_type = '|| l_volume_type);
8476 write_conc_log('ozfvadeb.pls ---> l_new_utilization = '|| l_volume_type);
8477 write_conc_log('ozfvadeb.pls ---> l_value = '|| l_value);
8478 write_conc_log('ozfvadeb.pls ---> l_selling_price = '|| l_selling_price);
8479 write_conc_log('ozfvadeb.pls ---> l_new_discount = '|| l_new_discount);
8480 IF l_retroactive = 'Y' THEN
8481 IF l_discount_type = '%' THEN
8482 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
8483 l_new_utilization := l_value* l_new_discount / 100;
8484 ELSE -- % is for unit price. need to multiple when range in quantity.
8485 l_new_utilization := l_value* l_selling_price * l_new_discount / 100;
8486 END IF;
8487 ELSIF l_discount_type = 'AMT' THEN
8488 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
8489 -- amt is for unit pirce. need to divide when range in amount.
8490 -- Fix for bug 9318975 - when l_selling price is zero, need not divide by selling price
8491 IF l_selling_price <> 0 THEN
8492 l_new_utilization :=l_value / l_selling_price * l_new_discount ;
8493 write_conc_log ('l_selling_price <> 0, l_new_utilization1 = '||l_new_utilization);
8494 ELSE
8495 l_new_utilization := l_value;
8496 write_conc_log ('l_selling_price = 0, l_new_utilization1 = '||l_new_utilization);
8497 END IF;
8498 ELSE
8499 l_new_utilization :=l_value * l_new_discount ;
8500 END IF;
8501 END IF;
8502 --ninarasi fix for bug 16029659. Rounded the utilization amount since l_amountTbl(i) contains a rounded value.
8503 l_new_utilization := ozf_utility_pvt.currround(l_new_utilization, l_offer_curr);
8504
8505 l_adj_amount := l_new_utilization - l_amountTbl(i);
8506
8507 IF G_DEBUG THEN
8508 ozf_utility_pvt.debug_message(l_full_name ||' retroactive flag is Y. ' || ' l_volume_type=' || l_volume_type
8509 || ' l_new_discount=' || l_new_discount
8510 || ' l_new_utilization=' || l_new_utilization
8511 || ' l_amountTbl=' || l_amountTbl(i)
8512 || ' l_adj_amount=' || l_adj_amount);
8513 END IF;
8514 write_conc_log(l_full_name ||' retroactive flag is Y. ' || ' l_volume_type=' || l_volume_type
8515 || ' l_new_discount=' || l_new_discount
8516 || ' l_new_utilization=' || l_new_utilization
8517 || ' l_amountTbl=' || l_amountTbl(i)
8518 || ' l_adj_amount=' || l_adj_amount);
8519
8520 END IF; --l_retroactive
8521
8522 --For non-retroactive volume offer.
8523 -- adjusment need to be make for all of orders when considering returned order.
8524 IF NVL(l_retroactive, 'N') = 'N' THEN
8525 IF l_included_vol_flag = 'Y' THEN
8526 l_previous_tier_max := l_volume;
8527 ELSE
8528 /*
8529 logic here is to add current order line's volume to offer's volume for adjustment.
8530 eg: offer's volume=2.
8531 order line's volume = 5, then total volume = 7.
8532 */
8533 l_previous_tier_max := l_volume + l_value;
8534 END IF;
8535
8536 /*
8537 1-10 1
8538 10-20 2
8539 20-30 3
8540
8541 l_volume = 25
8542 l_value = 10
8543
8544 1st loop: l_previous_tier_max = 25, y1= 5 l_value = 5 l_new_utilization = 5 * 3 = 15 l_previous_tier_max = 20
8545 2st loop: l_previous_tier_max = 20, y1= 5 l_value = 0 l_new_utilization = 5 * 2 = 10 l_previous_tier_max = 10
8546 by feliu on 12/14/06. pre_qualify tier is only for retroactive. not for non-retroactive.
8547 */
8548 /* Catch Weight Calculation : Volume Offer : Tiers By Qty in Pound
8549 0-100 1
8550 100-200 2
8551 200-300 3
8552 300-400 4
8553 400-500 5
8554 500- 6
8555 Discount By AMT, Tiers By QTY in Shipping UOM(Pound): l_new_utilization := l_new_utilization + y1* l_current_tier_value ;
8556 1st loop: l_previous_tier_max = 300, y1=0 l_value = 300 current_tier_value= 4 l_new_utilization = 0 l_previous_tier_max = 300
8557 2st loop: l_previous_tier_max = 300, y1=100 l_value = 300 current_tier_value= 3 l_new_utilization = 300 l_previous_tier_max = 200
8558 3rd loop: l_previous_tier_max = 200, y1=100 l_value = 200 current_tier_value= 2 l_new_utilization = 200 l_previous_tier_max = 100
8559 4th loop: l_previous_tier_max = 100, y1=100 l_value = 100 current_tier_value= 1 l_new_utilization = 100 l_previous_tier_max = 0
8560 Discount By %, Tiers By QTY in Shipping UOM(Pound): l_new_utilization := l_new_utilization + y1* l_selling_price * l_current_tier_value / 100;
8561 1st loop: l_previous_tier_max = 300, y1=0 l_value = 360 current_tier_value= 4 l_new_utilization = 60 * 250 * 4 / 100 = 600 l_previous_tier_max = 300
8562 2st loop: l_previous_tier_max = 300, y1=100 l_value = 300 current_tier_value= 3 l_new_utilization = 100 * 250 * 3 /100 = 750 l_previous_tier_max = 200
8563 3rd loop: l_previous_tier_max = 200, y1=100 l_value = 200 current_tier_value= 2 l_new_utilization = 100 * 250 * 2 /100 = 500 l_previous_tier_max = 100
8564 4th loop: l_previous_tier_max = 100, y1=100 l_value = 100 current_tier_value= 1 l_new_utilization = 100 * 250 * 1 /100 = 250 l_previous_tier_max = 0
8565 Catch Weight Calculation : Volume Offer : Tiers By Qty in Case
8566 0-2 1
8567 2-4 2
8568 4-6 3
8569 6-8 4
8570 8-10 5
8571 10- 6
8572 Discount By AMT, Tiers By QTY in Ordered UOM(Pound): l_new_utilization := l_new_utilization + y1* l_current_tier_value ;
8573 1st loop: l_previous_tier_max = 4, y1=0.5 l_value = 2.5 current_tier_value= 2 l_new_utilization = 1 l_previous_tier_max = 2
8574 2st loop: l_previous_tier_max = 2, y1=2 l_value = 0.5 current_tier_value= 1 l_new_utilization = 2 l_previous_tier_max = 0
8575 Discount By %, Tiers By QTY in Shipping UOM(Pound): l_new_utilization := l_new_utilization + y1* l_selling_price * l_current_tier_value / 100;
8576 1st loop: l_previous_tier_max = 4, y1=1 l_value = 3 current_tier_value= 2 l_new_utilization = 1 * 250 * 2 / 100 = 5 l_previous_tier_max = 2
8577 2st loop: l_previous_tier_max = 2, y1=2 l_value = 1 current_tier_value= 1 l_new_utilization = 2 * 250 * 1 / 100 = 5 l_previous_tier_max = 0
8578 */
8579 IF G_DEBUG THEN
8580 ozf_utility_pvt.debug_message( ' l_value=' || l_value);
8581 END IF;
8582
8583 --fix for bug 6021538
8584 IF l_max_tier IS NULL THEN
8585 OPEN c_get_tier_limits(l_pbh_line_id);
8586 FETCH c_get_tier_limits INTO l_min_tier,l_max_tier;
8587 CLOSE c_get_tier_limits;
8588 END IF;
8589
8590 write_conc_log( ' l_value=' || l_value);
8591 write_conc_log( ' l_volume=' || l_volume);
8592 write_conc_log( ' l_max_tier=' || l_max_tier);
8593
8594
8595 IF l_volume > l_max_tier THEN
8596 l_value:= l_max_tier -l_volume + l_value;
8597 IF l_value<0 THEN
8598 l_value:=0;
8599 END IF;
8600 END IF;
8601
8602 --end bug 6021538
8603 l_preset_tier := NULL;
8604 OPEN c_prior_tiers(l_pbh_line_id, l_volume);
8605 LOOP
8606 FETCH c_prior_tiers INTO l_current_offer_tier_id,l_current_min_tier,l_current_max_tier,l_current_tier_value;
8607 EXIT WHEN c_prior_tiers%NOTFOUND;
8608
8609 write_conc_log( ' l_current_offer_tier_id=' || l_current_offer_tier_id);
8610
8611 -- handle over tier cap. not applicable for R12.
8612 /* IF l_current_max_tier < l_previous_tier_max THEN
8613 l_previous_tier_max := l_current_max_tier;
8614 END IF;
8615 */
8616
8617 OPEN c_preset_tier(l_pbh_line_id,l_qp_list_header_id,l_group_id);
8618 FETCH c_preset_tier INTO l_preset_tier;
8619 CLOSE c_preset_tier;
8620
8621 write_conc_log( ' l_preset_tier=' || l_preset_tier);
8622 write_conc_log( ' l_current_tier_value=' || l_current_tier_value);
8623
8624
8625 IF l_preset_tier is NOT NULL AND l_preset_tier > l_current_tier_value THEN
8626 l_current_tier_value := l_preset_tier;
8627 IF G_DEBUG THEN
8628 ozf_utility_pvt.debug_message('not reach preset tier: ');
8629 END IF;
8630 write_conc_log(' not reach preset tier:');
8631 END IF;
8632
8633 -- logic here is:
8634 -- start from top tier, calculate amount in each tier, until order amount has been calculated.
8635 -- y1 := LEAST((l_previous_tier_max-l_current_min_tier + 1),l_value) ;
8636 write_conc_log('ozfvadeb.pls ---> l_previous_tier_max = '|| l_previous_tier_max);
8637 write_conc_log('ozfvadeb.pls ---> l_current_min_tier = '|| l_current_min_tier);
8638 write_conc_log('ozfvadeb.pls ---> l_value = '|| l_value);
8639 y1 := LEAST((l_previous_tier_max-l_current_min_tier),l_value) ;
8640 write_conc_log('y1 is ' || y1);
8641 write_conc_log('l_value is ' || l_value);
8642 l_value := l_value - y1;
8643 write_conc_log('ozfvadeb.pls ---> l_discount_type = '|| l_discount_type);
8644 write_conc_log('ozfvadeb.pls ---> l_volume_type = '|| l_volume_type);
8645 write_conc_log('ozfvadeb.pls ---> l_new_utilization = '|| l_new_utilization);
8646 write_conc_log('ozfvadeb.pls ---> l_current_tier_value = '|| l_current_tier_value);
8647 write_conc_log('ozfvadeb.pls ---> l_selling_price = '|| l_selling_price);
8648 IF l_discount_type = '%' THEN
8649 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
8650 write_conc_log ('Discount By %, Tiers By AMT');
8651 l_new_utilization := l_new_utilization + y1* l_current_tier_value / 100;
8652 ELSE
8653 write_conc_log ('Discount By %, Tiers By QTY');
8654 l_new_utilization := l_new_utilization + y1* l_selling_price * l_current_tier_value / 100;
8655 END IF;
8656 ELSIF l_discount_type = 'AMT' THEN
8657 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
8658 write_conc_log ('Discount By AMT, Tiers By AMT');
8659 -- Fix for bug 9318975 - when l_selling price is zero, need not divide by selling price
8660 IF l_selling_price <> 0 THEN
8661 l_new_utilization := l_new_utilization + y1 / l_selling_price * l_current_tier_value ;
8662 write_conc_log ('l_selling_price <> 0, l_new_utilization3 = '||l_new_utilization);
8663 ELSE
8664 l_new_utilization :=l_new_utilization + y1;
8665 write_conc_log ('l_selling_price = 0, l_new_utilization3 = '||l_new_utilization);
8666 END IF;
8667 ELSE
8668 write_conc_log ('Discount By AMT, Tiers By QTY');
8669 l_new_utilization := l_new_utilization + y1* l_current_tier_value ;
8670 END IF;
8671 END IF;
8672
8673 --l_previous_tier_max := l_current_min_tier - 1 ;
8674 l_previous_tier_max := l_current_min_tier;
8675
8676 IF G_DEBUG THEN
8677 ozf_utility_pvt.debug_message(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
8678 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
8679 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
8680 || ' l_new_utilization: ' || l_new_utilization);
8681 END IF;
8682 write_conc_log(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
8683 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
8684 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
8685 || ' l_new_utilization: ' || l_new_utilization);
8686
8687 EXIT WHEN l_value <= 0;
8688
8689 END LOOP; -- end of loop for c_prior_tiers
8690 CLOSE c_prior_tiers;
8691 -- For R12, returned order for different customers. ????????
8692 --For returned order, create positive record for return line, then
8693 -- make adjustment based on the difference of total utilization for previous orders.
8694 --ninarasi fix for bug 16029659. Rounded the utilization amount since l_amountTbl(i) contains a rounded value.
8695 l_new_utilization := ozf_utility_pvt.currround(l_new_utilization, l_offer_curr);
8696
8697 IF l_returned_flag = true THEN
8698 write_conc_log('ozfvadeb.pls ---> IF l_returned_flag = true THEN');
8699 l_total_amount := l_total_amount + l_amountTbl(i) ;
8700 l_adj_amount := l_new_utilization - l_total_amount;
8701 write_conc_log('l_amountTbl(i) : ' || l_amountTbl(i));
8702 ELSE -- for non-returned order, make adjustment based on difference of total utilization for specified price adjustment id.
8703 write_conc_log('ozfvadeb.pls ---> IF l_returned_flag = false THEN');
8704 l_adj_amount := l_new_utilization - l_amountTbl(i);
8705 write_conc_log('l_amountTbl(i) : ' || l_amountTbl(i));
8706 l_total_amount := l_total_amount + l_amountTbl(i) + l_adj_amount;
8707 END IF;
8708 write_conc_log('ozfvadeb.pls ---> l_adj_amount after = '|| l_adj_amount);
8709 write_conc_log('ozfvadeb.pls ---> l_total_amount after = '|| l_total_amount);
8710 END IF; -- end of non-retroactive adjustment.
8711
8712 l_act_util_rec.price_Adjustment_id := l_priceAdjustmentIDTbl(i);
8713 l_act_util_rec.order_line_id := l_orderLineIdTbl(i);
8714 l_act_util_rec.gl_posted_flag := l_glPostedFlagTbl(i);
8715 l_act_util_rec.object_type := l_objectTypeTbl(i);
8716
8717 write_conc_log('l_transaction_currency_code : ' || l_transaction_currency_code);
8718 write_conc_log('l_act_util_rec.plan_currency_code : ' || l_act_util_rec.plan_currency_code);
8719
8720 --nirprasa, 12.2 assign the currencies.
8721 IF l_transaction_currency_code IS NULL THEN
8722 l_act_util_rec.plan_currency_code := l_order_line_info.transactional_curr_code;
8723 ELSE
8724 l_act_util_rec.plan_currency_code := l_offer_curr;
8725 END IF;
8726
8727 write_conc_log('l_act_util_rec.plan_currency_code : ' || l_act_util_rec.plan_currency_code);
8728 write_conc_log('l_offer_curr : ' || l_offer_curr);
8729 l_act_util_rec.fund_request_currency_code := l_offer_curr;
8730 --ninarasi Bug 16029659. Passed exchange_rate_date since this date should be used for all calculations.
8731 l_act_util_rec.exchange_rate_date := l_exchangeRateDateTbl(i);
8732 l_act_util_rec.gl_date := l_glDateTbl(i);
8733 --nirprasa, 12.2 end assign the currencies.
8734
8735 --ninarasi: bug 15877269 - Process_accrual expects the adjustment amount to be in order currency. So converted the adjustment
8736 --amount to order currency from offer currency in case of NULL currency offers and where order currency is different than offer currency.
8737 IF l_transaction_currency_code IS NULL AND l_offer_curr <> l_order_line_info.transactional_curr_code THEN
8738
8739 write_conc_log ('l_adj_amount before currency conversion: ' || l_adj_amount);
8740 write_conc_log ('From currency: ' || l_offer_curr);
8741 write_conc_log ('To currency: ' || l_order_line_info.transactional_curr_code);
8742
8743 --ninarasi Bug 16029659 - changed conversion date used from gl_date to exchange_rate_date.
8744 ozf_utility_pvt.convert_currency(x_return_status => l_return_status
8745 ,p_from_currency => l_offer_curr
8746 ,p_to_currency => l_order_line_info.transactional_curr_code
8747 ,p_conv_type => l_conv_type
8748 ,p_conv_date => l_exchangeRateDateTbl(i)
8749 ,p_from_amount => l_adj_amount
8750 ,x_to_amount => l_adj_conv_amount
8751 ,x_rate => l_rate);
8752 l_adj_amount := l_adj_conv_amount;
8753 write_conc_log ('l_adj_amount after currency conversion: ' || l_adj_amount);
8754 write_conc_log ('Conversion Rate: ' || l_rate);
8755 END IF;
8756
8757 IF NVL(l_adj_amount,0) <> 0 THEN
8758 process_accrual (
8759 p_earned_amt =>l_adj_amount,
8760 p_qp_list_header_id =>l_qp_list_header_id,
8761 p_act_util_rec =>l_act_util_rec,
8762 x_return_status =>l_return_status,
8763 x_msg_count =>l_msg_count,
8764 x_msg_data =>l_msg_data );
8765
8766 IF l_return_status = fnd_api.g_ret_sts_error THEN
8767 RAISE fnd_api.g_exc_error;
8768 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8769 RAISE fnd_api.g_exc_unexpected_error;
8770 END IF;
8771 END IF;
8772
8773 IF G_DEBUG THEN
8774 ozf_utility_pvt.debug_message(
8775 l_full_name ||' Process Accrual Msg count '||l_msg_count||' Msg data'||l_msg_data||' Return status'||l_return_status
8776 );
8777 END IF;
8778 write_conc_log(
8779 l_full_name ||' Process Accrual Msg count '||l_msg_count||' Msg data'||l_msg_data||' Return status'||l_return_status
8780 );
8781
8782 <<l_endoffloop>>
8783 NULL;
8784 END LOOP; -- loop for For
8785 EXIT WHEN c_old_price_adj%NOTFOUND;
8786 END LOOP; -- end price adj loop
8787 CLOSE c_old_price_adj;
8788
8789 IF l_return_status = fnd_api.g_ret_sts_error THEN
8790 RAISE fnd_api.g_exc_error;
8791 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8792 RAISE fnd_api.g_exc_unexpected_error;
8793 END IF;
8794
8795 <<l_endoffloop>>
8796 NULL;
8797
8798 IF G_DEBUG THEN
8799 ozf_utility_pvt.debug_message(' /*************************** DEBUG MESSAGE END *************************/' || l_api_name );
8800 END IF;
8801 write_conc_log(' /*************************** DEBUG MESSAGE END *************************/' || l_api_name );
8802
8803 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
8804
8805 x_return_status := l_return_status;
8806
8807 EXCEPTION
8808 WHEN fnd_api.g_exc_error THEN
8809 ROLLBACK TO volume_offer_adjustment;
8810 x_return_status := fnd_api.g_ret_sts_error;
8811 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
8812 WHEN fnd_api.g_exc_unexpected_error THEN
8813 ROLLBACK TO volume_offer_adjustment;
8814 x_return_status := fnd_api.g_ret_sts_unexp_error;
8815 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
8816 WHEN OTHERS THEN
8817 ROLLBACK TO volume_offer_adjustment;
8818 x_return_status := fnd_api.g_ret_sts_unexp_error;
8819 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8820 fnd_msg_pub.add_exc_msg (g_pkg_name, l_api_name);
8821 END IF;
8822 fnd_msg_pub.count_and_get (p_count => x_msg_count, p_data => x_msg_data, p_encoded => fnd_api.g_false);
8823
8824 END volume_offer_adjustment;
8825
8826
8827 ---------------------------------------------------------------------
8828 -- PROCEDURE
8829 -- volume_offer_util_adjustment
8830 -- PURPOSE
8831 -- adjustment of utilization amount for backdated adjustments and split orders.
8832 -- HISTORY
8833 -- 2/16/2007 nirprasa Created for bug 6021635
8834 ----------------------------------------------------------------------
8835
8836
8837 PROCEDURE volume_offer_util_adjustment(
8838 p_qp_list_header_id IN NUMBER,
8839 x_return_status OUT NOCOPY VARCHAR2,
8840 x_msg_count OUT NOCOPY NUMBER,
8841 x_msg_data OUT NOCOPY VARCHAR2
8842 ) IS
8843
8844 CURSOR c_old_price_Adj(p_list_header_id IN NUMBER) IS
8845 SELECT sum(plan_curr_amount) old_Adj_amt
8846 , order_line_id
8847 ,min(price_adjustment_id) price_adjustment_id
8848 ,object_type
8849 ,object_id
8850 ,min(gl_date) gl_date
8851 ,min(utilization_id) utilization_id
8852 FROM ozf_funds_utilized_all_b
8853 WHERE plan_id = p_list_header_id
8854 AND plan_type = 'OFFR'
8855 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
8856 AND price_adjustment_id IS NOT NULL
8857 GROUP BY order_line_id,object_type,object_id
8858 ORDER BY gl_date;
8859
8860
8861
8862
8863
8864 /* CURSOR c_order_line_qty(p_order_line_id IN NUMBER) IS
8865 SELECT DECODE(line.line_category_code,'ORDER',line.ordered_quantity,
8866 'RETURN', -line.ordered_quantity) ordered_quantity
8867 FROM oe_order_lines_all line
8868 WHERE line.line_id = p_order_line_id;*/
8869
8870
8871 /* CURSOR c_all_orders (p_list_header_id IN NUMBER) IS
8872 select sum(ordered_quantity)
8873 FROM (
8874 select sum(ordered_quantity) ordered_quantity from oe_order_lines_all
8875 where line_id IN
8876 (SELECT order_line_id FROM ozf_funds_utilized_all_b
8877 WHERE plan_id = p_list_header_id
8878 AND plan_type = 'OFFR'
8879 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
8880 AND price_adjustment_id IS NOT NULL
8881 )
8882 UNION
8883 select sum(quantity) ordered_quantity from OZF_RESALE_LINES_INT_ALL
8884 where resale_batch_id IN
8885 (SELECT reference_id FROM ozf_funds_utilized_all_b
8886 WHERE plan_id = p_list_header_id
8887 AND plan_type = 'OFFR'
8888 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
8889 AND price_adjustment_id IS NOT NULL
8890 )
8891 );*/
8892
8893
8894 CURSOR c_all_orders (p_list_header_id IN NUMBER) IS
8895 select sum(ordered_quantity)
8896 FROM (
8897 SELECT SUM(DECODE(line_category_code,'ORDER',ordered_quantity,
8898 'RETURN', -ordered_quantity)) ordered_quantity
8899 from oe_order_lines_all oe,
8900 (SELECT distinct order_line_id FROM ozf_funds_utilized_all_b
8901 WHERE plan_id = p_list_header_id
8902 AND plan_type = 'OFFR'
8903 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
8904 AND price_adjustment_id IS NOT NULL
8905 ) orders
8906 where oe.line_id = orders.order_line_id
8907 UNION
8908 select sum(quantity) ordered_quantity from OZF_RESALE_LINES_INT_ALL ol ,
8909 (SELECT distinct reference_id FROM ozf_funds_utilized_all_b
8910 WHERE plan_id = p_list_header_id
8911 AND plan_type = 'OFFR'
8912 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
8913 AND price_adjustment_id IS NOT NULL
8914 ) orders
8915 where ol.resale_batch_id = orders.reference_id
8916
8917 );
8918
8919
8920 CURSOR c_discount_header(p_discount_line_id IN NUMBER) IS
8921 SELECT discount_type,volume_type
8922 FROM ozf_offer_discount_lines
8923 WHERE offer_discount_line_id = p_discount_line_id
8924 AND tier_type = 'PBH';
8925
8926 CURSOR c_get_group(p_order_line_id IN NUMBER,p_list_header_id IN NUMBER) IS
8927 SELECT group_no,pbh_line_id,include_volume_flag
8928 FROM ozf_order_group_prod
8929 WHERE order_line_id = p_order_line_id
8930 AND qp_list_header_id = p_list_header_id;
8931
8932 CURSOR c_market_option(p_list_header_id IN NUMBER, p_group_id IN NUMBER) IS
8933 SELECT opt.retroactive_flag
8934 FROM ozf_offr_market_options opt
8935 WHERE opt.GROUP_NUMBER= p_group_id
8936 AND opt.qp_list_header_id = p_list_header_id;
8937
8938 CURSOR c_current_discount(p_volume IN NUMBER, p_parent_discount_id IN NUMBER) IS
8939 SELECT discount
8940 FROM ozf_offer_discount_lines
8941 WHERE p_volume > volume_from
8942 AND p_volume <= volume_to
8943 AND parent_discount_line_id = p_parent_discount_id;
8944
8945 CURSOR c_get_tier_limits (p_parent_discount_id IN NUMBER) IS
8946 SELECT MIN(volume_from),MAX(volume_to)
8947 FROM ozf_offer_discount_lines
8948 WHERE parent_discount_line_id = p_parent_discount_id;
8949
8950 CURSOR c_get_max_tier (p_max_volume_to IN NUMBER,p_parent_discount_id IN NUMBER) IS
8951 SELECT discount
8952 FROM ozf_offer_discount_lines
8953 WHERE volume_to =p_max_volume_to
8954 AND parent_discount_line_id = p_parent_discount_id;
8955
8956 CURSOR c_order_line_info(p_order_line_id IN NUMBER) IS
8957 SELECT DECODE(line.line_category_code,'ORDER',line.ordered_quantity,
8958 'RETURN', -line.ordered_quantity) ordered_quantity,
8959 DECODE(line.line_category_code,'ORDER',NVL(line.shipped_quantity,line.ordered_quantity),
8960 'RETURN', line.invoiced_quantity,
8961 line.ordered_quantity) shipped_quantity,
8962 line.invoiced_quantity,
8963 line.unit_selling_price,
8964 line.line_id,
8965 line.actual_shipment_date,
8966 line.fulfillment_date, -- invoiced date ?????
8967 line.inventory_item_id,
8968 header.transactional_curr_code,
8969 header.header_id
8970 FROM oe_order_lines_all line, oe_order_headers_all header
8971 WHERE line.line_id = p_order_line_id
8972 AND line.header_id = header.header_id;
8973
8974
8975 CURSOR c_resale_line_info(p_resale_line_id IN NUMBER, p_adj_id IN NUMBER) IS
8976 SELECT line.quantity ordered_quantity ,
8977 line.quantity shipped_quantity,
8978 line.quantity invoiced_quantity,
8979 adj.priced_unit_price unit_list_price,
8980 line.resale_line_id line_id,
8981 NVL(line.date_shipped, line.date_ordered) actual_shipment_date,
8982 NVL(line.date_shipped, line.date_ordered) fulfillment_date, -- invoiced date ?????
8983 line.inventory_item_id,
8984 line.currency_code, --dummy column
8985 line.resale_header_id
8986 FROM OZF_RESALE_LINES_ALL line,ozf_resale_adjustments_all adj
8987 WHERE line.resale_line_id = p_resale_line_id
8988 AND adj.resale_adjustment_id = p_adj_id
8989 AND line.resale_line_id = adj.resale_line_id;
8990
8991 CURSOR c_offer_curr IS
8992 SELECT nvl(transaction_currency_code,fund_request_curr_code), offer_id
8993 FROM ozf_offers
8994 WHERE qp_list_header_id = p_qp_list_header_id;
8995
8996 --22-FEB-2007 kdass bug 5759350 - changed datatype of p_product_id from NUMBER to VARCHAR2 based on Feng's suggestion
8997 --fix for bug 5979971
8998 CURSOR c_apply_discount(p_offer_id IN NUMBER,p_line_id IN NUMBER) IS
8999 SELECT NVL(apply_discount_flag,'N')
9000 FROM ozf_order_group_prod
9001 WHERE offer_id = p_offer_id
9002 AND order_line_id = p_line_id;
9003
9004 CURSOR c_offer_info (p_list_header_id IN NUMBER) IS
9005 SELECT nvl(transaction_currency_code,fund_request_curr_code) transaction_currency_code
9006 , beneficiary_account_id, offer_id
9007 FROM ozf_offers
9008 WHERE qp_list_header_id = p_list_header_id;
9009
9010 CURSOR c_order_line_details (p_line_id IN NUMBER) IS
9011 SELECT invoice_to_org_id, ship_to_org_id
9012 FROM oe_order_lines_all
9013 WHERE line_id = p_line_id;
9014
9015 CURSOR c_cust_number (p_header_id IN NUMBER) IS
9016 SELECT cust.cust_account_id
9017 FROM hz_cust_acct_sites_all acct_site,
9018 hz_cust_site_uses_all site_use,
9019 hz_cust_accounts cust,
9020 oe_order_headers_all header
9021 WHERE header.header_id = p_header_id
9022 AND acct_site.cust_acct_site_id = site_use.cust_acct_site_id
9023 AND acct_site.cust_account_id = cust.cust_account_id
9024 AND site_use.site_use_id = header.invoice_to_org_id ;
9025
9026
9027 CURSOR c_prior_tiers(p_parent_discount_id IN NUMBER, p_volume IN NUMBER ) IS
9028 SELECT offer_discount_line_id ,volume_from ,volume_to, discount
9029 FROM ozf_offer_discount_lines
9030 WHERE parent_discount_line_id = p_parent_discount_id
9031 AND p_volume >= volume_from
9032 ORDER BY volume_from DESC;
9033
9034 CURSOR c_preset_tier(p_pbh_line_id IN NUMBER, p_qp_list_header_id IN NUMBER,p_group_id IN NUMBER) IS
9035 SELECT a.discount
9036 FROM ozf_offer_discount_lines a, ozf_market_preset_tiers b, ozf_offr_market_options c
9037 WHERE a.offer_discount_line_id = b.dis_offer_discount_id
9038 AND b.pbh_offer_discount_id = p_pbh_line_id
9039 AND b.offer_market_option_id = c.offer_market_option_id
9040 AND c.qp_list_header_id = p_qp_list_header_id
9041 AND c.group_number = p_group_id;
9042
9043
9044 CURSOR c_volume_detail (p_order_line_id IN NUMBER,p_source_code IN VARCHAR2) IS
9045 SELECT billto_cust_account_id, bill_to_site_use_id, ship_to_site_use_id
9046 FROM ozf_funds_utilized_all_b
9047 WHERE (p_source_code = 'OM' AND object_type = 'ORDER' AND order_line_id = p_order_line_id)
9048 OR (p_source_code = 'IS' AND object_type = 'TP_ORDER' AND object_id = p_order_line_id);
9049
9050 CURSOR c_all_cust_orders (p_list_header_id IN NUMBER, p_cust_account_id IN NUMBER) IS
9051 select sum(ordered_quantity)
9052 FROM (
9053 SELECT SUM (DECODE(line_category_code,'ORDER',ordered_quantity,
9054 'RETURN', -ordered_quantity)) ordered_quantity
9055 from oe_order_lines_all oe,
9056 (SELECT distinct order_line_id FROM ozf_funds_utilized_all_b
9057 WHERE plan_id = p_list_header_id
9058 AND plan_type = 'OFFR'
9059 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9060 AND price_adjustment_id IS NOT NULL
9061 AND cust_account_id = p_cust_account_id
9062 ) orders
9063 where oe.line_id = orders.order_line_id
9064 UNION
9065 select sum(quantity) ordered_quantity from OZF_RESALE_LINES_INT_ALL ol ,
9066 (SELECT distinct reference_id FROM ozf_funds_utilized_all_b
9067 WHERE plan_id = p_list_header_id
9068 AND plan_type = 'OFFR'
9069 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9070 AND price_adjustment_id IS NOT NULL
9071 AND cust_account_id = p_cust_account_id
9072 ) orders
9073 where ol.resale_batch_id = orders.reference_id
9074
9075 );
9076
9077
9078 CURSOR c_all_cust_orders2 (p_list_header_id IN NUMBER, p_cust_account_id IN NUMBER, p_transaction_date IN DATE) IS
9079 select sum(ordered_quantity)
9080 FROM (
9081 SELECT SUM (DECODE(line_category_code,'ORDER',ordered_quantity,
9082 'RETURN', -ordered_quantity)) ordered_quantity
9083 from oe_order_lines_all oe,
9084 (SELECT distinct order_line_id FROM ozf_funds_utilized_all_b
9085 WHERE plan_id = p_list_header_id
9086 AND plan_type = 'OFFR'
9087 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9088 AND price_adjustment_id IS NOT NULL
9089 AND cust_account_id = p_cust_account_id
9090 AND gl_date <= p_transaction_date
9091 ) orders
9092 where oe.line_id = orders.order_line_id
9093 UNION
9094 select sum(quantity) ordered_quantity from OZF_RESALE_LINES_INT_ALL ol ,
9095 (SELECT distinct reference_id FROM ozf_funds_utilized_all_b
9096 WHERE plan_id = p_list_header_id
9097 AND plan_type = 'OFFR'
9098 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9099 AND price_adjustment_id IS NOT NULL
9100 AND cust_account_id = p_cust_account_id
9101 AND gl_date <= p_transaction_date
9102 ) orders
9103 where ol.resale_batch_id = orders.reference_id
9104
9105 );
9106
9107 CURSOR c_is_util_correct(p_list_header_id IN NUMBER) IS
9108 SELECT 1 FROM DUAL WHERE EXISTS
9109 ( SELECT 1
9110 FROM
9111 ( SELECT sum(plan_curr_amount) old_Adj_amt
9112 , order_line_id
9113 ,min(price_adjustment_id) price_adjustment_id
9114 ,object_type
9115 ,object_id
9116 ,min(gl_date) gl_date
9117 FROM ozf_funds_utilized_all_b
9118 WHERE plan_id = p_list_header_id
9119 AND plan_type = 'OFFR'
9120 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9121 AND price_adjustment_id IS NOT NULL
9122 AND NVL(gl_posted_flag,'Y') IN ('Y','F') --ninarasi fix for bug 14610746
9123 GROUP BY order_line_id,object_type,object_id
9124 ORDER BY gl_date) earned,
9125 ( SELECT sum(plan_curr_amount) old_Adj_amt
9126 , order_line_id
9127 ,min(price_adjustment_id) price_adjustment_id
9128 ,object_type
9129 ,object_id
9130 ,min(gl_date) gl_date
9131 FROM ozf_funds_utilized_all_b
9132 WHERE plan_id = p_list_header_id
9133 AND plan_type = 'OFFR'
9134 AND utilization_type IN ( 'ACCRUAL','SALES_ACCRUAL','LEAD_ACCRUAL','UTILIZED', 'ADJUSTMENT', 'LEAD_ADJUSTMENT')
9135 AND price_adjustment_id IS NOT NULL
9136 -- AND gl_posted_flag in ('Y','N')
9137 GROUP BY order_line_id,object_type,object_id
9138 ORDER BY gl_date) utilized
9139
9140 WHERE utilized.old_Adj_amt <> earned.old_Adj_amt
9141 AND utilized.order_line_id=earned.order_line_id
9142 );
9143
9144
9145
9146 l_api_name CONSTANT VARCHAR2(30) := 'volume_offer_util_adjustment';
9147 l_retroactive VARCHAR2(1) ;
9148 l_total_ordered_qty NUMBER;
9149 l_line_ordered_qty NUMBER;
9150 l_volume NUMBER;
9151 l_group_id NUMBER;
9152 l_pbh_line_id NUMBER;
9153 l_value NUMBER;
9154 l_included_vol_flag VARCHAR2(1);
9155 l_discount_type VARCHAR2(30);
9156 l_volume_type VARCHAR2(30);
9157 l_adj_amount NUMBER;
9158 l_utilization_amount NUMBER;
9159 l_min_tier NUMBER;
9160 l_max_tier NUMBER;
9161 l_new_discount NUMBER;
9162 l_offer_curr VARCHAR2(30);
9163 l_offer_id NUMBER;
9164 l_selling_price NUMBER;
9165 l_apply_discount VARCHAR2(1) ;
9166 l_return_status VARCHAR2 (20) := fnd_api.g_ret_sts_success;
9167 l_conv_price NUMBER;
9168 l_rate NUMBER;
9169 l_new_utilization NUMBER;
9170 l_invoice_to_org_id NUMBER;
9171 l_ship_to_org_id NUMBER;
9172 l_cust_number NUMBER;
9173 l_act_budget_id NUMBER;
9174 l_act_budgets_rec ozf_actbudgets_pvt.act_budgets_rec_type;
9175 l_act_util_rec ozf_actbudgets_pvt.act_util_rec_type;
9176 l_offer_info c_offer_info%ROWTYPE;
9177 l_order_line_info c_order_line_info%ROWTYPE;
9178 l_amountTbl amountTbl ;
9179 l_objectTypeTbl objectTypeTbl ;
9180 l_objectIdTbl objectIdTbl;
9181 l_priceAdjustmentIDTbl priceAdjustmentIDTbl ;
9182 l_orderLineIdTbl orderLineIdTbl;
9183 l_glDateTbl glDateTbl;
9184 l_order_line_id NUMBER;
9185
9186 --Added for bug 7030415
9187 l_utilizationIdTbl utilizationIdTbl;
9188 CURSOR c_utilization_details(l_utilization_id IN NUMBER) IS
9189 SELECT exchange_rate_type, org_id
9190 FROM ozf_funds_utilized_all_b
9191 WHERE utilization_id=l_utilization_id;
9192
9193 l_conv_type ozf_funds_utilized_all_b.exchange_rate_type%TYPE;
9194 l_org_id NUMBER;
9195
9196
9197
9198 l_current_offer_tier_id NUMBER;
9199 y1 NUMBER; -- Initial Adjsutment
9200 l_current_max_tier NUMBER;
9201 l_current_min_tier NUMBER;
9202 l_current_tier_value NUMBER;
9203 l_previous_tier_max NUMBER;
9204 l_preset_tier NUMBER;
9205 l_cust_account_id NUMBER;
9206 l_bill_to NUMBER;
9207 l_ship_to NUMBER;
9208 l_source_code VARCHAR2(30);
9209 l_util_correct NUMBER;
9210
9211
9212 BEGIN
9213
9214 write_conc_log(' /*************************** DEBUG MESSAGE START *************************/' || l_api_name);
9215 write_conc_log(' p_qp_list_header_id: ' || p_qp_list_header_id);
9216
9217 OPEN c_all_orders (p_qp_list_header_id);
9218 FETCH c_all_orders INTO l_total_ordered_qty;
9219 CLOSE c_all_orders;
9220
9221 write_conc_log(' l_total_ordered_qty: ' || l_total_ordered_qty);
9222
9223 l_volume:=0;
9224 l_new_utilization := 0;
9225
9226 OPEN c_is_util_correct(p_qp_list_header_id);
9227 FETCH c_is_util_correct INTO l_util_correct;
9228 CLOSE c_is_util_correct;
9229
9230 write_conc_log(' l_util_correct: ' || l_util_correct);
9231
9232
9233
9234 IF NVL(l_util_correct,0)<>0 THEN
9235 OPEN c_old_price_adj(p_qp_list_header_id);
9236 LOOP
9237 FETCH c_old_price_adj BULK COLLECT INTO l_amountTbl, l_orderLineIdTbl
9238 , l_priceAdjustmentIDTbl
9239 , l_objectTypeTbl, l_objectIdTbl, l_glDateTbl, l_utilizationIdTbl
9240 LIMIT g_bulk_limit;
9241
9242 FOR i IN NVL(l_priceAdjustmentIDTbl.FIRST, 1) .. NVL(l_priceAdjustmentIDTbl.LAST, 0) LOOP
9243
9244 write_conc_log(' l_objectTypeTbl(i): ' || l_objectTypeTbl(i));
9245
9246
9247 IF l_objectTypeTbl(i) ='ORDER' THEN
9248 IF G_DEBUG THEN
9249 ozf_utility_pvt.debug_message(' order_line_id: '|| l_orderLineIdTbl(i) );
9250 END IF;
9251 write_conc_log(' order_line_id: '|| l_orderLineIdTbl(i) );
9252
9253 l_order_line_id:=l_orderLineIdTbl(i);
9254
9255 OPEN c_order_line_info(l_orderLineIdTbl(i));
9256 FETCH c_order_line_info INTO l_order_line_info;
9257 CLOSE c_order_line_info;
9258
9259 ELSE
9260 IF G_DEBUG THEN
9261 ozf_utility_pvt.debug_message(' resale_line_id: '|| l_objectIdTbl(i) );
9262 END IF;
9263 write_conc_log(' resale_line_id: '|| l_objectIdTbl(i));
9264
9265 l_order_line_id:=l_objectIdTbl(i);
9266
9267 OPEN c_resale_line_info(l_objectIdTbl(i),l_priceAdjustmentIDTbl(i));
9268 FETCH c_resale_line_info INTO l_order_line_info;
9269 CLOSE c_resale_line_info;
9270 END IF;
9271
9272 l_selling_price := NVL(l_order_line_info.unit_selling_price,0) ; -- discount is negative
9273
9274 write_conc_log(' l_selling_price: '|| l_selling_price);
9275
9276 OPEN c_offer_curr;
9277 FETCH c_offer_curr INTO l_offer_curr, l_offer_id;
9278 CLOSE c_offer_curr;
9279
9280
9281 IF l_objectTypeTbl(i) ='ORDER' THEN
9282 l_source_code := 'OM';
9283 ELSE
9284 l_source_code := 'IS';
9285 END IF;
9286
9287 IF l_amountTbl(i) = 0 THEN -- fix bug 5689866
9288 -- OPEN c_apply_discount(l_offer_id,l_order_line_info.inventory_item_id);
9289 IF l_objectTypeTbl(i) ='ORDER' THEN
9290
9291 OPEN c_apply_discount(l_offer_id, l_orderLineIdTbl(i));
9292 FETCH c_apply_discount INTO l_apply_discount;
9293 CLOSE c_apply_discount;
9294 ELSE
9295 OPEN c_apply_discount(l_offer_id, l_objectIdTbl(i));
9296 FETCH c_apply_discount INTO l_apply_discount;
9297 CLOSE c_apply_discount;
9298 END IF;
9299
9300 IF l_apply_discount ='N' THEN
9301 IF G_DEBUG THEN
9302 ozf_utility_pvt.debug_message('not apply discount: ' || l_order_line_info.inventory_item_id);
9303 END IF;
9304 write_conc_log(' not apply discount:'|| l_order_line_info.inventory_item_id);
9305 GOTO l_endoffloop;
9306 END IF;
9307 END IF; -- bug 5689866
9308
9309 --kdass 31-MAR-2006 bug 5101720 convert from order currency to offer currency
9310 IF l_offer_curr <> l_order_line_info.transactional_curr_code THEN
9311
9312 ozf_utility_pvt.write_conc_log('order curr: ' || l_order_line_info.transactional_curr_code);
9313 ozf_utility_pvt.write_conc_log('offer curr: ' || l_offer_curr);
9314 ozf_utility_pvt.write_conc_log('selling price: ' || l_selling_price);
9315
9316 -- Added for bug 7030415
9317 OPEN c_utilization_details(l_utilizationIdTbl(i));
9318 FETCH c_utilization_details INTO l_conv_type, l_org_id;
9319 CLOSE c_utilization_details;
9320 l_act_util_rec.org_id := l_org_id;
9321
9322 ozf_utility_pvt.write_conc_log('l_conv_type: ' || l_conv_type);
9323
9324 ozf_utility_pvt.convert_currency (x_return_status => l_return_status
9325 ,p_conv_type => l_conv_type -- 7030415
9326 ,p_conv_date => l_order_line_info.actual_shipment_date
9327 ,p_from_currency => l_order_line_info.transactional_curr_code
9328 ,p_to_currency => l_offer_curr
9329 ,p_from_amount => l_selling_price
9330 ,x_to_amount => l_conv_price
9331 ,x_rate => l_rate
9332 );
9333
9334 IF l_return_status = fnd_api.g_ret_sts_error THEN
9335 RAISE fnd_api.g_exc_error;
9336 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9337 RAISE fnd_api.g_exc_unexpected_error;
9338 END IF;
9339
9340 l_selling_price := NVL(l_conv_price,0);
9341 write_conc_log ('selling price after currency conversion: ' || l_selling_price);
9342
9343 END IF;
9344 /*ozf_utility_pvt.write_conc_log('l_orderLineIdTbl(i): ' || l_orderLineIdTbl(i));
9345 OPEN c_order_line_qty(l_orderLineIdTbl(i));
9346 FETCH c_order_line_qty INTO l_line_ordered_qty;
9347 CLOSE c_order_line_qty;*/
9348
9349 l_line_ordered_qty := l_order_line_info.ordered_quantity;
9350
9351 ozf_utility_pvt.write_conc_log('l_line_ordered_qty: ' || l_line_ordered_qty);
9352 ozf_utility_pvt.write_conc_log('l_orderLineIdTbl(i): ' || l_orderLineIdTbl(i));
9353 ozf_utility_pvt.write_conc_log('p_qp_list_header_id: ' || p_qp_list_header_id);
9354
9355
9356
9357
9358 OPEN c_get_group(l_orderLineIdTbl(i),p_qp_list_header_id);
9359 FETCH c_get_group INTO l_group_id,l_pbh_line_id,l_included_vol_flag;
9360 CLOSE c_get_group;
9361
9362 IF G_DEBUG THEN
9363 ozf_utility_pvt.debug_message(' l_group_id: '|| l_group_id );
9364 ozf_utility_pvt.debug_message(' l_pbh_line_id: '|| l_pbh_line_id );
9365 ozf_utility_pvt.debug_message(' l_included_vol_flag: '|| l_included_vol_flag );
9366 END IF;
9367
9368 write_conc_log(' l_group_id: '|| l_group_id );
9369 write_conc_log(' l_pbh_line_id: '|| l_pbh_line_id );
9370 write_conc_log(' l_included_vol_flag: '|| l_included_vol_flag );
9371
9372 IF l_group_id is NULL OR l_pbh_line_id is NULL THEN
9373 GOTO l_endoffloop;
9374 END IF;
9375
9376 OPEN c_market_option(p_qp_list_header_id,l_group_id);
9377 FETCH c_market_option INTO l_retroactive;
9378 CLOSE c_market_option;
9379
9380 write_conc_log(' l_retroactive: '|| l_retroactive );
9381
9382
9383
9384 --if retroactive
9385 IF l_retroactive = 'Y' THEN
9386 OPEN c_volume_detail(l_orderLineIdTbl(i),l_source_code);
9387 FETCH c_volume_detail INTO l_cust_account_id,l_ship_to,l_bill_to;
9388 CLOSE c_volume_detail;
9389
9390 OPEN c_all_cust_orders(p_qp_list_header_id,l_cust_account_id);
9391 FETCH c_all_cust_orders INTO l_total_ordered_qty;
9392 CLOSE c_all_cust_orders;
9393
9394 l_volume:=NVL(l_total_ordered_qty,0);
9395
9396 ELSE
9397
9398 OPEN c_volume_detail(l_orderLineIdTbl(i),l_source_code);
9399 FETCH c_volume_detail INTO l_cust_account_id,l_ship_to,l_bill_to;
9400 CLOSE c_volume_detail;
9401
9402 OPEN c_all_cust_orders2(p_qp_list_header_id,l_cust_account_id,l_glDateTbl(i));
9403 FETCH c_all_cust_orders2 INTO l_total_ordered_qty;
9404 CLOSE c_all_cust_orders2;
9405
9406 --l_volume:=NVL(l_volume,0)+NVL(l_line_ordered_qty,0);
9407
9408 l_volume:=NVL(l_total_ordered_qty,0);
9409
9410
9411 END IF;
9412
9413 write_conc_log(' l_volume: '|| l_volume );
9414
9415 OPEN c_discount_header(l_pbh_line_id);
9416 FETCH c_discount_header INTO l_discount_type,l_volume_type;
9417 CLOSE c_discount_header;
9418
9419 -- fix for bug 6345305
9420 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
9421 l_volume := l_volume * l_selling_price;
9422 END IF;
9423
9424 OPEN c_current_discount(l_volume,l_pbh_line_id);
9425 FETCH c_current_discount INTO l_new_discount;
9426 CLOSE c_current_discount;
9427
9428 write_conc_log(' l_volume_type: '|| l_volume_type );
9429 write_conc_log(' l_discount_type: '|| l_discount_type );
9430 write_conc_log(' l_new_discount: '|| l_new_discount );
9431
9432 IF l_new_discount is NULL THEN
9433 OPEN c_get_tier_limits(l_pbh_line_id);
9434 FETCH c_get_tier_limits INTO l_min_tier,l_max_tier;
9435 CLOSE c_get_tier_limits;
9436 write_conc_log(' l_min_tier: '|| l_min_tier );
9437 write_conc_log(' l_max_tier: '|| l_max_tier );
9438 write_conc_log(' l_volume: '|| l_volume );
9439 IF l_volume < l_min_tier THEN
9440 l_new_discount := 0;
9441 ELSE
9442 OPEN c_get_max_tier(l_max_tier,l_pbh_line_id);
9443 FETCH c_get_max_tier INTO l_new_discount;
9444 CLOSE c_get_max_tier;
9445
9446 END IF;
9447 IF G_DEBUG THEN
9448 ozf_utility_pvt.debug_message(' l_new_discount: '|| l_new_discount );
9449 END IF;
9450 write_conc_log(' l_new_discount: '|| l_new_discount );
9451 END IF;
9452
9453
9454 write_conc_log(' l_selling_price: '|| l_selling_price );
9455 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN -- volume type = AMOUNT
9456 l_value := NVL(l_line_ordered_qty,0) * l_selling_price ;
9457 ELSE
9458 l_value := NVL(l_line_ordered_qty,0) ;
9459 END IF;
9460
9461 write_conc_log(' l_value: '|| l_value );
9462 write_conc_log(' l_retroactive: '|| l_retroactive );
9463 write_conc_log(' l_volume_type: '|| l_volume_type );
9464 write_conc_log(' l_discount_type: '|| l_discount_type );
9465 write_conc_log(' l_selling_price: '|| l_selling_price );
9466
9467 l_preset_tier := NULL;
9468
9469 OPEN c_preset_tier(l_pbh_line_id,p_qp_list_header_id,l_group_id);
9470 FETCH c_preset_tier INTO l_preset_tier;
9471 CLOSE c_preset_tier;
9472
9473 write_conc_log( ' l_preset_tier=' || l_preset_tier);
9474 write_conc_log( ' l_new_discount=' || l_new_discount);
9475
9476
9477 IF l_preset_tier is NOT NULL AND l_preset_tier > l_new_discount THEN
9478 l_new_discount := l_preset_tier;
9479 IF G_DEBUG THEN
9480 ozf_utility_pvt.debug_message('not reach preset tier: ');
9481 END IF;
9482 write_conc_log(' not reach preset tier:');
9483 END IF;
9484
9485
9486 IF l_retroactive = 'Y' THEN
9487 IF l_discount_type = '%' THEN
9488 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
9489 l_new_utilization := l_value* l_new_discount / 100;
9490 ELSE -- % is for unit price. need to multiple when range in quantity.
9491 l_new_utilization := l_value* l_selling_price * l_new_discount / 100;
9492 END IF;
9493 ELSIF l_discount_type = 'AMT' THEN
9494 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
9495 -- amt is for unit pirce. need to divide when range in amount.
9496 -- Fix for bug 9318975 - when l_selling price is zero, need not divide by selling price
9497 IF l_selling_price <> 0 THEN
9498 l_new_utilization :=l_value / l_selling_price * l_new_discount ;
9499 write_conc_log ('l_selling_price <> 0, l_new_utilization2 = '||l_new_utilization);
9500 ELSE
9501 l_new_utilization := l_value;
9502 write_conc_log ('l_selling_price = 0, l_new_utilization2 = '||l_new_utilization);
9503 END IF;
9504 ELSE
9505 l_new_utilization :=l_value * l_new_discount ;
9506 END IF;
9507 END IF;
9508 END IF; --l_retroactive
9509
9510
9511 IF NVL(l_retroactive, 'N') = 'N' THEN
9512
9513 l_new_utilization := 0;
9514
9515 IF l_included_vol_flag = 'Y' THEN
9516 l_previous_tier_max := l_volume;
9517 ELSE
9518 /*
9519 logic here is to add current order line's volume to offer's volume for adjustment.
9520 eg: offer's volume=2.
9521 order line's volume = 5, then total volume = 7.
9522 */
9523 l_previous_tier_max :=l_line_ordered_qty + l_volume ;
9524 END IF;
9525
9526 IF G_DEBUG THEN
9527 ozf_utility_pvt.debug_message( ' l_line_ordered_qty=' || l_line_ordered_qty);
9528 END IF;
9529 write_conc_log( ' l_line_ordered_qty=' || l_line_ordered_qty);
9530 --fix for bug 6021538
9531
9532 IF l_max_tier IS NULL THEN
9533 OPEN c_get_tier_limits(l_pbh_line_id);
9534 FETCH c_get_tier_limits INTO l_min_tier,l_max_tier;
9535 CLOSE c_get_tier_limits;
9536 END IF;
9537
9538 write_conc_log( ' l_value=' || l_value);
9539 write_conc_log( ' l_volume=' || l_volume);
9540 write_conc_log( ' l_max_tier=' || l_max_tier);
9541
9542
9543 IF l_volume > l_max_tier THEN
9544 l_line_ordered_qty:= l_max_tier -l_volume + l_line_ordered_qty;
9545 IF l_line_ordered_qty<0 THEN
9546 l_line_ordered_qty:=0;
9547 END IF;
9548 END IF;
9549
9550 --end bug 6021538
9551
9552 l_preset_tier := NULL;
9553
9554
9555
9556 OPEN c_prior_tiers(l_pbh_line_id, l_volume);
9557 LOOP
9558 FETCH c_prior_tiers INTO l_current_offer_tier_id,l_current_min_tier,l_current_max_tier,l_current_tier_value;
9559 EXIT WHEN c_prior_tiers%NOTFOUND;
9560
9561 write_conc_log( ' l_current_offer_tier_id=' || l_current_offer_tier_id);
9562
9563
9564 OPEN c_preset_tier(l_pbh_line_id,p_qp_list_header_id,l_group_id);
9565 FETCH c_preset_tier INTO l_preset_tier;
9566 CLOSE c_preset_tier;
9567
9568 write_conc_log( ' l_preset_tier=' || l_preset_tier);
9569 write_conc_log( ' l_current_tier_value=' || l_current_tier_value);
9570
9571
9572 IF l_preset_tier is NOT NULL AND l_preset_tier > l_current_tier_value THEN
9573 l_current_tier_value := l_preset_tier;
9574 IF G_DEBUG THEN
9575 ozf_utility_pvt.debug_message('not reach preset tier: ');
9576 END IF;
9577 write_conc_log(' not reach preset tier:');
9578 END IF;
9579
9580
9581
9582 y1 := LEAST((l_previous_tier_max-l_current_min_tier),l_line_ordered_qty) ;
9583 l_line_ordered_qty := l_line_ordered_qty - y1;
9584 IF l_discount_type = '%' THEN
9585 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
9586 l_new_utilization := l_new_utilization + y1* l_current_tier_value / 100;
9587 ELSE
9588 l_new_utilization := l_new_utilization + y1* l_selling_price * l_current_tier_value / 100;
9589 END IF;
9590 ELSIF l_discount_type = 'AMT' THEN
9591 IF l_volume_type = 'PRICING_ATTRIBUTE12' THEN
9592 l_new_utilization := l_new_utilization + y1 / l_selling_price * l_current_tier_value ;
9593 ELSE
9594 l_new_utilization := l_new_utilization + y1* l_current_tier_value ;
9595 END IF;
9596 END IF;
9597
9598 --l_previous_tier_max := l_current_min_tier - 1 ;
9599 l_previous_tier_max := l_current_min_tier;
9600
9601 IF G_DEBUG THEN
9602 ozf_utility_pvt.debug_message(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
9603 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
9604 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
9605 || ' l_new_utilization: ' || l_utilization_amount);
9606 END IF;
9607 write_conc_log(' retroactive flag is N, computing for prior tier id=' || l_current_offer_tier_id
9608 || ' y1=' || y1 || ' tier_min=' || l_current_min_tier
9609 || ' tier_max=' || l_current_max_tier || ' l_previous_tier_max: ' || l_previous_tier_max
9610 || ' l_new_utilization: ' || l_utilization_amount);
9611
9612 EXIT WHEN l_line_ordered_qty <= 0;
9613
9614 END LOOP; -- end of loop for c_prior_tiers
9615 CLOSE c_prior_tiers;
9616
9617 END IF; -- IF NVL(l_retroactive, 'N') = 'N' THEN
9618
9619
9620 write_conc_log(' l_amountTbl(i): '|| l_amountTbl(i) );
9621 write_conc_log(' l_new_utilization: '|| l_new_utilization );
9622
9623 --IF l_amountTbl(i)<= l_new_utilization THEN
9624
9625 l_adj_amount := l_new_utilization - l_amountTbl(i);
9626
9627 write_conc_log(' l_adj_amount: '|| l_adj_amount );
9628
9629 OPEN c_offer_info (p_qp_list_header_id);
9630 FETCH c_offer_info INTO l_offer_info;
9631 CLOSE c_offer_info;
9632
9633 OPEN c_order_line_details (l_orderLineIdTbl(i));
9634 FETCH c_order_line_details into l_invoice_to_org_id, l_ship_to_org_id;
9635 CLOSE c_order_line_details;
9636
9637 write_conc_log(' l_invoice_to_org_id: '|| l_invoice_to_org_id );
9638 write_conc_log(' l_ship_to_org_id: '|| l_ship_to_org_id );
9639
9640
9641
9642 --create records
9643 l_act_budgets_rec.act_budget_used_by_id := p_qp_list_header_id;
9644 l_act_budgets_rec.arc_act_budget_used_by := 'OFFR';
9645 l_act_budgets_rec.budget_source_type := 'OFFR';
9646 l_act_budgets_rec.budget_source_id := p_qp_list_header_id;
9647 l_act_budgets_rec.request_currency := l_order_line_info.transactional_curr_code; --ninarasi fix for bug 14610746
9648 l_act_budgets_rec.request_date := SYSDATE;
9649 l_act_budgets_rec.status_code := 'APPROVED';
9650 l_act_budgets_rec.user_status_id := ozf_Utility_Pvt.get_default_user_status (
9651 'OZF_BUDGETSOURCE_STATUS', l_act_budgets_rec.status_code);
9652 l_act_budgets_rec.approved_in_currency := l_offer_info.transaction_currency_code;
9653 l_act_budgets_rec.approval_date := SYSDATE;
9654 l_act_budgets_rec.approver_id := ozf_utility_pvt.get_resource_id (fnd_global.user_id);
9655 l_act_budgets_rec.justification := 'Offer adjustment before offer start date';
9656 l_act_budgets_rec.transfer_type := 'UTILIZED';
9657
9658 l_act_util_rec.utilization_type :='ADJUSTMENT';
9659 l_act_util_rec.product_level_type := 'PRODUCT';
9660 l_act_util_rec.adjustment_date := SYSDATE;
9661 l_act_util_rec.cust_account_id := l_offer_info.beneficiary_account_id;
9662 l_act_util_rec.ship_to_site_use_id := l_ship_to_org_id;
9663 l_act_util_rec.bill_to_site_use_id := l_invoice_to_org_id;
9664
9665 l_act_util_rec.product_id := l_order_line_info.inventory_item_id;
9666 l_act_util_rec.object_type :='ORDER';
9667 l_act_util_rec.object_id := l_order_line_info.header_id;
9668 l_act_util_rec.order_line_id := l_order_line_id;
9669 l_act_util_rec.price_adjustment_id := -1;
9670 l_act_util_rec.orig_utilization_id:= -1;
9671
9672 l_act_util_rec.plan_currency_code := l_order_line_info.transactional_curr_code; --ninarasi fix for bug 14610746
9673 l_act_util_rec.fund_request_currency_code := l_offer_info.transaction_currency_code;
9674
9675
9676 write_conc_log('l_order_line_info.transactional_curr_code : ' || l_order_line_info.transactional_curr_code);
9677 write_conc_log(' l_order_line_info.header_id: '|| l_order_line_info.header_id );
9678 OPEN c_cust_number (l_order_line_info.header_id);
9679 FETCH c_cust_number INTO l_cust_number;
9680 CLOSE c_cust_number;
9681
9682 l_act_util_rec.billto_cust_account_id := l_cust_number;
9683
9684 IF l_offer_info.beneficiary_account_id IS NULL THEN
9685 l_act_util_rec.cust_account_id := l_cust_number;
9686 END IF;
9687
9688
9689 -- this adjustment is to adjust utilized amount in all cases so its not backdated adjustment
9690 -- also it is not for earned so it is not volume offer adjustment either.
9691 -- set to backdated until decision is made.
9692 IF l_adj_amount > 0 THEN
9693 l_act_util_rec.adjustment_type :='STANDARD'; -- Seeded Data for Backdated Positive Adj
9694 l_act_util_rec.adjustment_type_id := -5; -- Seeded Data for Backdated Positive Adj
9695 ELSE
9696 l_act_util_rec.adjustment_type :='DECREASE_EARNED'; -- Seeded Data for Backdated Negative Adj
9697 l_act_util_rec.adjustment_type_id := -4; -- Seeded Data for Backdated Negative Adj
9698 END IF;
9699
9700 l_act_util_rec.gl_posted_flag:= 'N';
9701
9702 l_act_budgets_rec.request_amount := l_adj_amount;
9703 l_act_budgets_rec.approved_amount := l_adj_amount;
9704
9705 ----------------------
9706
9707
9708 IF NVL(l_adj_amount,0) <> 0 THEN
9709 ozf_fund_adjustment_pvt.process_act_budgets(x_return_status => x_return_status
9710 ,x_msg_count => x_msg_count
9711 ,x_msg_data => x_msg_data
9712 ,p_act_budgets_rec => l_act_budgets_rec
9713 ,p_act_util_rec => l_act_util_rec
9714 ,x_act_budget_id => l_act_budget_id
9715 );
9716
9717 write_conc_log('process_act_budgets returns: ' || x_return_status);
9718 IF l_return_status = fnd_api.g_ret_sts_error THEN
9719 RAISE fnd_api.g_exc_error;
9720 ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
9721 RAISE fnd_api.g_exc_unexpected_error;
9722 END IF;
9723 END IF;
9724 -- END IF;
9725
9726 <<l_endoffloop>>
9727 NULL;
9728 END LOOP; -- loop for For
9729 EXIT WHEN c_old_price_adj%NOTFOUND;
9730 END LOOP; -- end price adj loop
9731
9732 CLOSE c_old_price_adj;
9733 END IF;
9734
9735 END volume_offer_util_adjustment;
9736
9737
9738
9739
9740 END ozf_adjustment_ext_pvt;
9741