[Home] [Help]
PACKAGE BODY: APPS.CST_PRJMFG_COST_COLLECTOR
Source
1 PACKAGE BODY CST_PRJMFG_COST_COLLECTOR as
2 /* $Header: CSTPPCCB.pls 120.17.12010000.2 2008/10/29 21:54:28 anjha ship $*/
3
4 /*----------------------------------------------------------------------------*
5 | PRIVATE FUNCTION/PROCEDURES |
6 *----------------------------------------------------------------------------*/
7
8 PROCEDURE pm_process_txn_mmt (
9 p_Group_Id NUMBER,
10 p_transaction_id NUMBER,
11 p_organization_id NUMBER,
12 p_transaction_action_id NUMBER,
13 p_transaction_source_type_id NUMBER,
14 p_type_class NUMBER,
15 p_project_id NUMBER,
16 p_task_id NUMBER,
17 p_transaction_date DATE,
18 p_primary_quantity NUMBER,
19 p_expenditure_type VARCHAR2,
20 p_item_description VARCHAR2,
21 p_cost_group_id NUMBER,
22 p_transfer_cost_group_id NUMBER,
23 p_inventory_item_id NUMBER,
24 p_transaction_source_id NUMBER,
25 p_to_project_id NUMBER,
26 p_to_task_id NUMBER,
27 p_source_project_id NUMBER,
28 p_source_task_id NUMBER,
29 p_transfer_transaction_id NUMBER,
30 p_primary_cost_method NUMBER,
31 p_std_cg_acct NUMBER, -- Added for bug 3495967
32 p_acct_period_id NUMBER,
33 p_exp_org_id NUMBER,
34 p_distribution_account_id NUMBER,
35 p_proj_job_ind NUMBER,
36 p_first_matl_se_exp_type VARCHAR2,
37 p_inv_txn_source_literal VARCHAR2,
38 p_cap_txn_source_literal VARCHAR2,
39 p_inv_syslink_literal VARCHAR2,
40 p_bur_syslink_literal VARCHAR2,
41 p_wip_syslink_literal VARCHAR2,
42 p_user_def_exp_type NUMBER,
43 O_err_num OUT NOCOPY NUMBER,
44 O_err_code OUT NOCOPY VARCHAR2,
45 O_err_msg OUT NOCOPY VARCHAR2,
46 p_transfer_organization_id NUMBER,
47 p_flow_schedule VARCHAR2,
48 p_si_asset_yes_no NUMBER,
49 p_transfer_si_asset_yes_no NUMBER,
50 p_denom_currency_code VARCHAR2);
51
52 PROCEDURE pm_check_error_mmt (
53 p_transaction_id NUMBER,
54 p_organization_id NUMBER,
55 p_cost_method NUMBER,
56 p_inventory_item_id NUMBER,
57 p_avg_rates_cost_type_id NUMBER,
58 p_transaction_action_id NUMBER,
59 p_transaction_source_type_id NUMBER,
60 p_type_class NUMBER,
61 p_project_id NUMBER,
62 p_task_id NUMBER,
63 p_to_project_id NUMBER,
64 p_to_task_id NUMBER,
65 p_source_project_id NUMBER,
66 p_source_task_id NUMBER,
67 p_transaction_source_id NUMBER,
68 p_proj_job_ind OUT NOCOPY NUMBER,
69 p_process_yn OUT NOCOPY NUMBER,
70 p_first_matl_se_exp_type OUT NOCOPY VARCHAR2,
71 p_user_id NUMBER,
72 p_login_id NUMBER,
73 p_req_id NUMBER,
74 p_prg_appl_id NUMBER,
75 p_prg_id NUMBER,
76 O_err_num OUT NOCOPY NUMBER,
77 O_err_code OUT NOCOPY VARCHAR2,
78 O_err_msg OUT NOCOPY VARCHAR2,
79 p_flow_schedule VARCHAR2,
80 p_cost_group_id NUMBER);
81
82 PROCEDURE pm_mark_error_mmt (
83 p_transaction_id NUMBER,
84 p_error_code VARCHAR2,
85 p_error_explanation VARCHAR2,
86 p_user_id NUMBER,
87 p_login_id NUMBER,
88 p_req_id NUMBER,
89 p_prg_appl_id NUMBER,
90 p_prg_id NUMBER,
91 O_err_num OUT NOCOPY NUMBER,
92 O_err_code OUT NOCOPY VARCHAR2,
93 O_err_msg OUT NOCOPY VARCHAR2);
94
95
96 PROCEDURE pm_process_txn_wt (
97 p_Group_Id NUMBER,
98 p_business_group_name VARCHAR2,
99 p_transaction_id NUMBER,
100 p_organization_id NUMBER,
101 p_employee_number VARCHAR2,
102 p_department_id NUMBER,
103 p_project_id NUMBER,
104 p_task_id NUMBER,
105 p_transaction_date DATE,
106 p_base_transaction_value NUMBER,
107 p_primary_quantity NUMBER,
108 p_acct_period_id NUMBER,
109 p_expenditure_type VARCHAR2,
110 p_resource_description VARCHAR2,
111 p_wt_transaction_type NUMBER,
112 p_cost_element_id NUMBER,
113 p_exp_org_name VARCHAR2,
114 p_wip_txn_source_literal VARCHAR2,
115 p_wip_straight_time_literal VARCHAR2,
116 p_wip_syslink_literal VARCHAR2,
117 p_bur_syslink_literal VARCHAR2,
118 O_err_num OUT NOCOPY NUMBER,
119 O_err_code OUT NOCOPY VARCHAR2,
120 O_err_msg OUT NOCOPY VARCHAR2,
121 p_reference_account NUMBER,
122 p_cr_account NUMBER,
123 p_wip_dr_sub_ledger_id NUMBER,
124 p_wip_cr_sub_ledger_id NUMBER,
125 p_wip_entity_id NUMBER,
126 p_resource_id NUMBER,
127 p_basis_resource_id NUMBER,
128 p_denom_currency_code VARCHAR2);
129
130 PROCEDURE pm_check_error_wt (
131 p_transaction_id NUMBER,
132 p_project_id NUMBER,
133 p_task_id NUMBER,
134 p_expenditure_type VARCHAR2,
135 p_organization_id NUMBER,
136 p_department_id NUMBER,
137 p_employee_number VARCHAR2,
138 p_exp_org_name OUT NOCOPY VARCHAR2,
139 p_process_yn OUT NOCOPY NUMBER,
140 p_user_id NUMBER,
141 p_login_id NUMBER,
142 p_req_id NUMBER,
143 p_prg_appl_id NUMBER,
144 p_prg_id NUMBER,
145 O_err_num OUT NOCOPY NUMBER,
146 O_err_code OUT NOCOPY VARCHAR2,
147 O_err_msg OUT NOCOPY VARCHAR2);
148
149 PROCEDURE pm_mark_error_wt (
150 p_transaction_id NUMBER,
151 p_error_code VARCHAR2,
152 p_error_explanation VARCHAR2,
153 p_user_id NUMBER,
154 p_login_id NUMBER,
155 p_req_id NUMBER,
156 p_prg_appl_id NUMBER,
157 p_prg_id NUMBER,
158 O_err_num OUT NOCOPY NUMBER,
159 O_err_code OUT NOCOPY VARCHAR2,
160 O_err_msg OUT NOCOPY VARCHAR2);
161
162 PROCEDURE pm_insert_pti_pvt
163 (p_transaction_source VARCHAR2,
164 p_batch_name VARCHAR2,
165 p_expenditure_ending_date DATE,
166 p_employee_number VARCHAR2,
167 p_organization_name VARCHAR2,
168 p_expenditure_item_date DATE,
169 p_project_number VARCHAR2,
170 p_task_number VARCHAR2,
171 p_expenditure_type VARCHAR2,
172 p_pa_quantity NUMBER,
173 p_raw_cost NUMBER,
174 p_expenditure_comment VARCHAR2,
175 p_orig_transaction_reference VARCHAR2,
176 p_raw_cost_rate NUMBER,
177 p_unmatched_negative_txn_flag VARCHAR2,
178 p_gl_date DATE,
179 p_org_id NUMBER,
180 p_burdened_cost NUMBER,
181 p_burdened_cost_rate NUMBER,
182 p_system_linkage VARCHAR2,
183 p_transaction_status_code VARCHAR2,
184 p_denom_currency_code VARCHAR2,
185
186 p_transaction_id NUMBER,
187 p_transaction_action_id NUMBER,
188 p_transaction_source_type_id NUMBER,
189 p_organization_id NUMBER,
190 p_inventory_item_id NUMBER,
191 p_cost_element_id NUMBER,
192 p_resource_id NUMBER,
193 p_source_flag NUMBER,
194 p_variance_flag NUMBER,
195 p_primary_quantity NUMBER,
196 p_transfer_organization_id NUMBER,
197 p_fob_point NUMBER,
198 p_wip_entity_id NUMBER,
199 p_basis_resource NUMBER,
200
201 p_type_class NUMBER,
202 p_project_id NUMBER,
203 p_task_id NUMBER,
204 p_transaction_date DATE,
205 p_cost_group_id NUMBER,
206 p_transfer_cost_group_id NUMBER,
207 p_transaction_source_id NUMBER,
208 p_to_project_id NUMBER,
209 p_to_task_id NUMBER,
210 p_source_project_id NUMBER,
211 p_source_task_id NUMBER,
212 p_transfer_transaction_id NUMBER,
213 p_primary_cost_method NUMBER,
214 p_acct_period_id NUMBER,
215 p_exp_org_id NUMBER,
216 p_distribution_account_id NUMBER,
217 p_proj_job_ind NUMBER,
218 p_first_matl_se_exp_type VARCHAR2,
219 p_inv_txn_source_literal VARCHAR2,
220 p_cap_txn_source_literal VARCHAR2,
221 p_inv_syslink_literal VARCHAR2,
222 p_bur_syslink_literal VARCHAR2,
223 p_wip_syslink_literal VARCHAR2,
224 p_user_def_exp_type VARCHAR2,
225 p_flow_schedule VARCHAR2,
226 p_si_asset_yes_no NUMBER,
227 p_transfer_si_asset_yes_no NUMBER,
228
229 O_err_num OUT NOCOPY NUMBER,
230 O_err_code OUT NOCOPY VARCHAR2,
231 O_err_msg OUT NOCOPY VARCHAR2
232 );
233
234 /*----------------------------------------------------------------------------*
235 | PUBLIC PROCEDURE |
236 | pm_mark_non_project_world_txns |
237 | |
238 | DESCRIPTION |
239 | This procedure would mark all non-project world transactions as Cost |
240 | Collected for the Given Organization and Upto the Given Date. |
241 | |
242 | For MMT trasactions, all transactions that are not selected by the view |
243 | 'cst_pm_matl_txn_v' and satisfy the date and org criteria are marked as |
244 | cost collected with no exception. |
245 | |
246 | For WIP trasactions, transactions falling into either of these category |
247 | are marked as cost collected. |
248 | -- All wip transaction records that refer to a non-project costed job |
249 | -- All wt records with transaction type as other than (1,2,3) and refer |
250 | to a project costed job |
251 | -- All wt records with transaction type as (1,2,3) but have no records |
252 | in WTA because their standard_rate_flag was 2 and auto_charge_type as|
253 | any thing other than manual resulting in the resource having no cost.|
254 | -- All ipv transfer transactions (source_code = 'IPV' |
255 | |
256 | PARAMETERS |
257 | Organization_Id, |
258 | UpToDate, |
259 | p_user_id, |
260 | p_login_id, |
261 | p_req_id, |
262 | p_prg_appl_id, |
263 | p_prg_id, |
264 | O_err_num, |
265 | O_err_code, |
266 | O_err_msg */
267
268 PROCEDURE pm_mark_non_project_world_txns (
269 p_Org_Id NUMBER,
270 p_prior_days NUMBER,
271 p_user_id NUMBER,
272 p_login_id NUMBER,
273 p_req_id NUMBER,
274 p_prg_appl_id NUMBER,
275 p_prg_id NUMBER,
276 O_err_num OUT NOCOPY NUMBER,
277 O_err_code OUT NOCOPY VARCHAR2,
278 O_err_msg OUT NOCOPY VARCHAR2)
279 IS
280
281 l_err_num NUMBER;
282 l_err_code VARCHAR2(240);
283 l_err_msg VARCHAR2(240);
284 l_stmt_num NUMBER;
285 l_return_status VARCHAR2(1);
286 l_msg_count NUMBER;
287 l_msg_data VARCHAR2(30);
288
289 l_primary_cost_method NUMBER;
290 l_std_cg_acct NUMBER;
291 l_debug VARCHAR2(80);
292
293 CST_FAILED_STD_CG_FLAG EXCEPTION;
294
295 BEGIN
296 l_err_num := 0;
297 l_err_code := '';
298 l_err_msg := '';
299 l_stmt_num := 5;
300
301 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
302 if (l_debug = 'Y') then
303 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_mark_non_project_world_txns');
304 end if;
305
306 -- The query is to mark all non-project world txns satisfying the
307 -- arguments provided, as processed.
308
309 ------------------------------------------------------------------
310 -- Mark all transactions as NULL for non-CG ACCT Std Organizations
311 -- Except the Proj Misc Txns.
312 ------------------------------------------------------------------
313
314 l_stmt_num := 10;
315
316 SELECT mp.primary_cost_method
317 INTO l_primary_cost_method
318 FROM mtl_parameters mp
319 WHERE mp.organization_id = p_org_id;
320
321 l_stmt_num := 15;
322
323 CST_Utility_Pub.GET_STD_CG_ACCT_FLAG
324 (p_api_version => 1.0,
325 p_organization_id => p_org_id,
326 x_cg_acct_flag => l_std_cg_acct,
327 x_return_status => l_return_status,
328 x_msg_count => l_msg_count,
329 x_msg_data => l_msg_data );
330
331 IF (l_return_status = FND_API.G_RET_STS_ERROR OR
332 l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
333 RAISE CST_FAILED_STD_CG_FLAG;
334 END IF;
335
336 IF (l_primary_cost_method = 1 AND l_std_cg_acct <> 1) THEN
337 ------------------------------------------------------------------
338 -- Logical Expense Requisition Receipts are an Exception
339 -- These are cost collected regardless of whether the organization
340 -- is PJM enabled
341 ------------------------------------------------------------------
342 l_stmt_num := 20;
343
344 UPDATE mtl_material_transactions mmt
345 SET mmt.pm_cost_collected = NULL,
346 mmt.last_update_date = sysdate,
347 mmt.last_updated_by = p_user_id,
348 mmt.last_update_login = p_login_id,
349 mmt.request_id = p_req_id,
350 mmt.program_application_id = p_prg_appl_id,
351 mmt.program_id = p_prg_id,
352 mmt.program_update_date = sysdate
353 WHERE NOT EXISTS
354 ( SELECT NULL
355 FROM mtl_transaction_types mtt
356 WHERE mtt.type_class = 1
357 AND mtt.transaction_type_id = mmt.transaction_type_id )
358 AND mmt.organization_id = p_Org_Id
359 AND mmt.transaction_date <= ((trunc(sysdate) - p_prior_days) + 0.99999)
360 AND mmt.costed_flag is NULL
361 AND mmt.pm_cost_collected = 'N'
362 AND mmt.transaction_action_id <> 17; -- See Note about exception above
363 ELSE
364
365 l_stmt_num := 25;
366
367 UPDATE mtl_material_transactions mmt
368 SET mmt.pm_cost_collected = NULL,
369 mmt.last_update_date = sysdate,
370 mmt.last_updated_by = p_user_id,
371 mmt.last_update_login = p_login_id,
372 mmt.request_id = p_req_id,
373 mmt.program_application_id = p_prg_appl_id,
374 mmt.program_id = p_prg_id,
375 mmt.program_update_date = sysdate
376 WHERE NOT EXISTS
377 ( SELECT NULL
378 FROM cst_pm_matl_txn_v cpmtv
379 WHERE cpmtv.transaction_id = mmt.transaction_id )
380 AND mmt.organization_id = p_Org_Id
381 AND mmt.transaction_date <= ((trunc(sysdate) - p_prior_days) + 0.99999)
382 AND mmt.costed_flag is NULL
383 AND mmt.pm_cost_collected = 'N';
384
385 END IF;
386
387 if (l_debug = 'Y') then
388 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: NP Count MMT is #: '||to_char(SQL%ROWCOUNT) );
389 end if;
390
391 /* Changes for consigned inventory */
392 /* Mark all transactions not owned by the current org as cost collected */
393
394 l_stmt_num := 30;
395
396 UPDATE
397 mtl_material_transactions mmt
398 SET mmt.pm_cost_collected = NULL,
399 mmt.last_update_date = sysdate,
400 mmt.last_updated_by = p_user_id,
401 mmt.last_update_login = p_login_id,
402 mmt.request_id = p_req_id,
403 mmt.program_application_id = p_prg_appl_id,
404 mmt.program_id = p_prg_id,
405 mmt.program_update_date = sysdate
406 WHERE
407 (
408 mmt.organization_id <> nvl(mmt.owning_organization_id, mmt.organization_id)
409 OR nvl(mmt.owning_tp_type, 2) <> 2
410 )
411 AND mmt.pm_cost_collected = 'N'
412 AND mmt.organization_id = p_Org_Id
413 AND mmt.transaction_date <= ((trunc(sysdate) - p_prior_days) + 0.99999)
414 AND mmt.costed_flag is null;
415
416 if (l_debug = 'Y') then
417 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Count of consigned txns in MMT - no cost collection - is #: '||to_char(SQL%ROWCOUNT) );
418 end if;
419
420 l_stmt_num := 35;
421
422 /* changes to support PJM Blue Print organizations.All logical transactions */
423 /* except Logical PO receipt in the case of a true ship case will be set to */
424 /* cost collected. Retroactive price updates will laso be set as cost */
425 /* collected */
426
427 UPDATE
428 mtl_material_transactions mmt
429 SET mmt.pm_cost_collected = NULL,
430 mmt.last_update_date = sysdate,
431 mmt.last_updated_by = p_user_id,
432 mmt.last_update_login = p_login_id,
433 mmt.request_id = p_req_id,
434 mmt.program_application_id = p_prg_appl_id,
435 mmt.program_id = p_prg_id,
436 mmt.program_update_date = sysdate
437 WHERE mmt.pm_cost_collected = 'N'
438 AND mmt.organization_id = p_org_id
439 AND mmt.transaction_date <= ((trunc(sysdate) - p_prior_days) + 0.99999)
440 AND mmt.costed_flag is null
441 AND
442 (
443 (
444 (
445 NVL(mmt.logical_transaction,2) = 1
446 )
447 AND NOT ( MMT.TRANSACTION_TYPE_ID = 19
448 AND MMT.TRANSACTION_ACTION_ID = 26
449 AND MMT.TRANSACTION_SOURCE_TYPE_ID = 1
450 AND NVL(MMT.LOGICAL_TRX_TYPE_CODE,5) = 2
451 AND EXISTS
452 (
453 SELECT
454 1
455 FROM rcv_transactions rcv
456 WHERE rcv.transaction_id = NVL(mmt.rcv_transaction_id,-9999)
457 AND rcv.organization_id = p_org_id
458 )
459 )
460 )
461 OR NVL(mmt.logical_trx_type_code,5) = 4
462 );
463
464 if (l_debug = 'Y') then
465 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Count of logical txns or retroactive price updates in MMT - no cost collection - is #: '||to_char(SQL%ROWCOUNT) );
466 end if;
467
468
469 l_stmt_num := 40;
470
471 /* Bug # 589460 PJM AUTO TASK API */
472 /* Check WIP Transactions Table for Prj/Tsk Ref Rather than the Job Header */
473 UPDATE
474 wip_transactions wt
475 SET wt.pm_cost_collected = NULL,
476 wt.last_update_date = sysdate,
477 wt.last_updated_by = p_user_id,
478 wt.last_update_login = p_login_id,
479 wt.request_id = p_req_id,
480 wt.program_application_id = p_prg_appl_id,
481 wt.program_id = p_prg_id,
482 wt.program_update_date = sysdate
483 WHERE wt.organization_id = p_Org_Id
484 AND wt.transaction_date <= ((trunc(sysdate) - p_prior_days) + 0.99999)
485 AND wt.pm_cost_collected = 'N'
486 AND
487 (
488 (
489 NOT wt.transaction_type in (1,2,3,17)
490 AND wt.project_id IS NOT NULL
491 )
492 OR wt.project_id IS NULL
493 OR
494 (
495 wt.transaction_type in (1,2,3)
496 AND NOT EXISTS
497 (
498 SELECT
499 NULL
500 FROM wip_transaction_accounts wta
501 WHERE wta.transaction_id = wt.transaction_id
502 )
503 )
504 OR wt.source_code = 'IPV' -- Bug 2130771
505 );
506
507
508
509 EXCEPTION
510 WHEN CST_FAILED_STD_CG_FLAG THEN
511 rollback;
512 O_err_num := 2001;
513 O_err_code := 'Failed CST_UTILITY_PUB.GET_STD_CG_ACCT_FLAG()'
514 ||' Organization_Id: '
515 ||p_org_id;
516 O_err_msg := 'CSTPPCCB.pm_mark_non_project_world_txns('
517 || to_char(l_stmt_num)
518 || '): ';
519 WHEN OTHERS THEN
520 rollback;
521 O_err_num := SQLCODE;
522 O_err_code := NULL;
523 O_err_msg := 'CSTPPCCB.pm_mark_non_project_world_txns('
524 || to_char(l_stmt_num)
525 || '): '
526 || substr(SQLERRM,1,200);
527 END pm_mark_non_project_world_txns;
528
529 /*----------------------------------------------------------------------------*
530 | PRIVATE PROCEDURE |
531 | assign_groups_to_mmt_txns |
532 | |
533 | DESCRIPTION |
534 | This procedure would for every record selected from the view, update the|
535 | MMT record to assign a group_id. The number of records to be updated is |
536 | determined by the user_spec_group_size. |
537 | |
538 | Every Transaction that satisfies the conditions mentioned below gets |
539 | a group id assigned to itself. |
540 | |
541 | - All Project related transactions from the Project World |
542 | |
543 | - All Project related transactions from the Non-Proj World |
544 | - Select Txns: Capital Projects related txns in the NPW |
545 | - Select Txns: Component Issue to Project Job from a NPW |
546 | - Select Txns: Component Return from Project Job to NPW |
547 | |
548 | - Ensure that the transaction has not yet got any group assigned |
549 | |
550 | - Ensure that the transaction took place before the Date upto which the |
551 | Cost Collection was desired |
552 | |
553 | - Ensure that the transaction took place in the Org for which the cost |
554 | Cost Collection was desired |
555 | |
556 | PARAMETERS |
557 | p_Org_Id, |
558 | p_prior_days, |
559 | p_user_spec_group_size, |
560 | p_rows_processed, |
561 | p_group_id OUT, |
562 | p_user_id, |
563 | p_login_id, |
564 | p_req_id, |
565 | p_prg_appl_id, |
566 | p_prg_id, |
567 | p_proj_misc_txn_only, |
568 | O_err_num, |
569 | O_err_code, |
570 | O_err_msg |
571 | |
572 | HISTORY |
573 | 07-SEP-96 Bhaskar Dasari Created. |
574 *----------------------------------------------------------------------------*/
575 PROCEDURE assign_groups_to_mmt_txns ( p_Org_Id NUMBER,
576 p_prior_days NUMBER,
577 p_user_spec_group_size NUMBER,
578 p_rows_processed OUT NOCOPY NUMBER,
579 p_group_id OUT NOCOPY NUMBER,
580 p_user_id NUMBER,
581 p_login_id NUMBER,
582 p_req_id NUMBER,
583 p_prg_appl_id NUMBER,
584 p_prg_id NUMBER,
585 p_proj_misc_txn_only NUMBER,
586 O_err_num OUT NOCOPY NUMBER,
587 O_err_code OUT NOCOPY VARCHAR2,
588 O_err_msg OUT NOCOPY VARCHAR2)
589 IS
590
591 CURSOR sel_mmt_trx (c_Org_Id NUMBER,
592 c_prior_days NUMBER,
593 c_proj_misc_txn_only NUMBER,
594 c_user_spec_group_size NUMBER) IS
595 SELECT NULL
596 FROM mtl_material_transactions mmt
597 WHERE mmt.transaction_id in (
598 SELECT cpmtv.transaction_id
599 FROM cst_pm_matl_txn_v cpmtv
600 WHERE cpmtv.organization_id = c_Org_Id
601 AND cpmtv.transaction_date <=
602 ((trunc(sysdate) - c_prior_days) + 0.99999)
603 AND cpmtv.pm_cost_collector_group_id is NULL
604 AND rownum <= c_user_spec_group_size
605 AND ( cpmtv.type_class = decode(c_proj_misc_txn_only,1,1,cpmtv.type_class)
606 OR cpmtv.transaction_action_id=17)
607 )
608 FOR UPDATE OF mmt.pm_cost_collected NOWAIT;
609 l_err_num NUMBER;
610 l_err_code VARCHAR2(240);
611 l_err_msg VARCHAR2(240);
612 l_stmt_num NUMBER;
613 l_rows NUMBER;
614 l_debug VARCHAR2(80);
615 BEGIN
616 -- initialize local variables
617 l_err_num := 0;
618 l_err_code := '';
619 l_err_msg := '';
620 p_rows_processed := 0;
621 l_stmt_num := 1;
622
623 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
624 if (l_debug = 'Y') then
625 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: assign_groups_to_mmt_txns');
626 end if;
627
628
629 l_stmt_num := 10;
630
631 SELECT mtl_material_transactions_s.nextval
632 INTO p_group_id
633 FROM dual;
634
635 l_stmt_num := 20;
636
637 FOR sel_mmt_rec IN sel_mmt_trx( p_Org_Id,
638 p_prior_days,
639 p_proj_misc_txn_only,
640 p_user_spec_group_size) LOOP
641
642
643 UPDATE mtl_material_transactions mmt
644 SET mmt.pm_cost_collector_group_id = p_group_id,
645 mmt.last_update_date = sysdate,
646 mmt.last_updated_by = p_user_id,
647 mmt.last_update_login = p_login_id,
648 mmt.request_id = p_req_id,
649 mmt.program_application_id = p_prg_appl_id,
650 mmt.program_id = p_prg_id,
651 mmt.program_update_date = sysdate
652 WHERE current of sel_mmt_trx;
653
654
655 p_rows_processed := sel_mmt_trx%ROWCOUNT;
656 l_rows := sel_mmt_trx%ROWCOUNT;
657
658 END LOOP;
659
660
661 EXCEPTION
662 WHEN OTHERS THEN
663 rollback;
664 O_err_num := SQLCODE;
665 O_err_code := NULL;
666 O_err_msg := 'CSTPPCCB.assign_groups_to_mmt_txns('
667 || to_char(l_stmt_num)
668 || '): '
669 || substr(SQLERRM,1,200);
670 END assign_groups_to_mmt_txns;
671 /*----------------------------------------------------------------------------*
672 | PRIVATE PROCEDURE |
673 | pm_cc_worker_mmt |
674 | |
675 | DESCRIPTION |
676 | This procedure would Cost Collect the given transaction id. The code |
677 | would check if the transaction is with errors. If none, the code would |
678 | to make a call to a procedure that would process the transaction. On |
679 | successful return from the process_txn procedure, the transaction being |
680 | is flagged as successfully cost collected by marking the flag |
681 | 'pm_cost_collected' as NULL. |
682 | |
683 | PARAMETERS |
684 | Transaction_id |
685 | Org_id |
686 | p_std_cg_acct Added for bug 3495967 |
687 | p_inv_txn_source_literal |
688 | p_cap_txn_source_literal |
689 | p_inv_syslink_literal |
690 | p_bur_syslink_literal |
691 | p_wip_syslink_literal |
692 | p_user_id, |
693 | p_user_def_exp_type |
694 | p_login_id, |
695 | p_req_id, |
696 | p_prg_appl_id, |
697 | p_prg_id, |
698 | O_err_num, |
699 | O_err_code, |
700 | O_err_msg |
701 | |
702 | HISTORY |
703 | 07-SEP-96 Bhaskar Dasari Created. |
704 | |
705 | 30-JUL-97 Hemant Gosain Modified to pass transfer_organization_id |
706 | so that fob point can be determined to pass accounting info |
707 | to Projects. |
708 *----------------------------------------------------------------------------*/
709 PROCEDURE pm_cc_worker_mmt (
710 p_transaction_id NUMBER,
711 p_Org_Id NUMBER,
712 p_std_cg_acct NUMBER, -- Added for bug 3495967
713 p_inv_txn_source_literal VARCHAR2,
714 p_cap_txn_source_literal VARCHAR2,
715 p_inv_syslink_literal VARCHAR2,
716 p_bur_syslink_literal VARCHAR2,
717 p_wip_syslink_literal VARCHAR2,
718 p_denom_currency_code VARCHAR2,
719 p_user_def_exp_type NUMBER,
720 p_user_id NUMBER,
721 p_login_id NUMBER,
722 p_req_id NUMBER,
723 p_prg_appl_id NUMBER,
724 p_prg_id NUMBER,
725 O_err_num OUT NOCOPY NUMBER,
726 O_err_code OUT NOCOPY VARCHAR2,
727 O_err_msg OUT NOCOPY VARCHAR2)
728 IS
729
730 CURSOR sel_mmt_trx_to_cost (c_Transaction_Id NUMBER,
731 c_Organization_Id NUMBER) IS
732 SELECT cpmtv.transaction_action_id,
733 cpmtv.transaction_source_type_id,
734 cpmtv.type_class,
735 cpmtv.expenditure_type,
736 cpmtv.transaction_date,
737 cpmtv.project_id,
738 cpmtv.task_id,
739 cpmtv.inventory_item_id,
740 cpmtv.primary_quantity,
741 cpmtv.costed_flag,
742 cpmtv.primary_cost_method,
743 cpmtv.avg_rates_cost_type_id,
744 cpmtv.item_description,
745 cpmtv.cost_group_id,
746 cpmtv.transfer_cost_group_id,
747 cpmtv.transaction_source_id,
748 cpmtv.to_project_id,
749 cpmtv.to_task_id,
750 cpmtv.source_project_id,
751 cpmtv.source_task_id,
752 cpmtv.transfer_transaction_id,
753 cpmtv.acct_period_id,
754 cpmtv.pm_cost_collector_group_id,
755 cpmtv.exp_org_id,
756 cpmtv.distribution_account_id,
757 cpmtv.transfer_organization_id,
758 cpmtv.flow_schedule,
759 cpmtv.si_asset_yes_no,
760 cpmtv.transfer_si_asset_yes_no
761 FROM cst_pm_matl_txn_v cpmtv
762 WHERE cpmtv.transaction_id = c_Transaction_Id
763 AND cpmtv.organization_id = c_Organization_Id;
764
765 l_proj_job_ind NUMBER;
766 l_process_yn NUMBER;
767 l_first_matl_se_exp_type VARCHAR2(30);
768 l_err_num NUMBER;
769 l_err_code VARCHAR2(240);
770 l_err_msg VARCHAR2(240);
771 l_err_msg_temp VARCHAR2(240);
772
773 l_error_code VARCHAR2(240);
774 l_error_explanation VARCHAR2(240);
775 PROCESS_ERROR EXCEPTION;
776 l_stmt_num NUMBER;
777 rec_to_proc NUMBER;
778 l_debug VARCHAR2(80);
779 l_count NUMBER;
780 BEGIN
781
782
783 -- initialize local variables
784 l_err_num := 0;
785 l_err_code := '';
786 l_err_msg := '';
787 l_err_msg_temp := '';
788 l_stmt_num := 1;
789 l_count := 0;
790
791 l_error_code := '';
792 l_error_explanation := '';
793
794 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
795 if (l_debug = 'Y') then
796 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_cc_worker_mmt ...');
797 end if;
798
799 l_stmt_num := 10;
800
801 /* The transaction may not need to be cost collected. This is because
802 the task auto assignment may have resulted in the task_id being equal
803 to the source_task_id. In this case, set the cost_collected flag to
804 NULL and return. */
805 SELECT count(*)
806 INTO l_count
807 FROM cst_pm_matl_txn_v
808 WHERE transaction_id = p_transaction_id;
809
810 IF (l_count = 0)
811 THEN
812 if (l_debug = 'Y') then
813 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Transfer between same project and task.' ||
814 ' No need to collect cost');
815 end if;
816
817 UPDATE mtl_material_transactions mmt
818 SET mmt.pm_cost_collected = NULL,
819 mmt.pm_cost_collector_group_id = NULL,
820 mmt.last_update_date = sysdate,
821 mmt.last_updated_by = p_user_id,
822 mmt.last_update_login = p_login_id,
823 mmt.request_id = p_req_id,
824 mmt.program_application_id = p_prg_appl_id,
825 mmt.program_id = p_prg_id,
826 mmt.program_update_date = sysdate
827 WHERE
828 mmt.transaction_id =p_transaction_id;
829
830 END IF;
831
832 FOR cpmtv_rec IN sel_mmt_trx_to_cost(p_transaction_id,
833 p_Org_Id) LOOP
834
835 if (l_debug = 'Y') then
836 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Processing transaction : '||to_char(p_transaction_id));
837 end if;
838
839 savepoint pm_cc_worker_mmt;
840
841 pm_check_error_mmt( p_transaction_id,
842 p_Org_Id,
843 cpmtv_rec.primary_cost_method,
844 cpmtv_rec.inventory_item_id,
845 cpmtv_rec.avg_rates_cost_type_id,
846 cpmtv_rec.transaction_action_id,
847 cpmtv_rec.transaction_source_type_id,
848 cpmtv_rec.type_class,
849 cpmtv_rec.project_id,
850 cpmtv_rec.task_id,
851 cpmtv_rec.to_project_id,
852 cpmtv_rec.to_task_id,
853 cpmtv_rec.source_project_id,
854 cpmtv_rec.source_task_id,
855 cpmtv_rec.transaction_source_id,
856 l_proj_job_ind ,
857 l_process_yn ,
858 l_first_matl_se_exp_type ,
859 p_user_id,
860 p_login_id,
861 p_req_id,
862 p_prg_appl_id,
863 p_prg_id,
864 l_err_num,
865 l_err_code,
866 l_err_msg,
867 cpmtv_rec.flow_schedule,
868 cpmtv_rec.cost_group_id
869 );
870
871 IF (l_err_num <> 0) THEN
872 -- Error occured
873 raise PROCESS_ERROR;
874 END IF;
875
876 IF l_process_yn = 1 THEN
877
878 pm_process_txn_mmt( cpmtv_rec.pm_cost_collector_group_id,
879 p_transaction_id,
880 p_Org_Id,
881 cpmtv_rec.transaction_action_id,
882 cpmtv_rec.transaction_source_type_id,
883 cpmtv_rec.type_class,
884 cpmtv_rec.project_id,
885 cpmtv_rec.task_id,
886 cpmtv_rec.transaction_date,
887 cpmtv_rec.primary_quantity,
888 cpmtv_rec.expenditure_type,
889 cpmtv_rec.item_description,
890 cpmtv_rec.cost_group_id,
891 cpmtv_rec.transfer_cost_group_id,
892 cpmtv_rec.inventory_item_id,
893 cpmtv_rec.transaction_source_id,
894 cpmtv_rec.to_project_id,
895 cpmtv_rec.to_task_id,
896 cpmtv_rec.source_project_id,
897 cpmtv_rec.source_task_id,
898 cpmtv_rec.transfer_transaction_id,
899 cpmtv_rec.primary_cost_method,
900 p_std_cg_acct, -- Added for bug 3495967
901 cpmtv_rec.acct_period_id,
902 cpmtv_rec.exp_org_id,
903 cpmtv_rec.distribution_account_id,
904 l_proj_job_ind,
905 l_first_matl_se_exp_type,
906 p_inv_txn_source_literal,
907 p_cap_txn_source_literal,
908 p_inv_syslink_literal,
909 p_bur_syslink_literal,
910 p_wip_syslink_literal,
911 p_user_def_exp_type,
912 l_err_num,
913 l_err_code,
914 l_err_msg,
915 cpmtv_rec.transfer_organization_id,
916 cpmtv_rec.flow_schedule,
917 cpmtv_rec.si_asset_yes_no,
918 cpmtv_rec.transfer_si_asset_yes_no,
919 p_denom_currency_code);
920
921 IF (l_err_num <> 0) THEN
922 -- Error occured
923 raise PROCESS_ERROR;
924 ELSE
925
926 l_stmt_num := 20;
927
928 /* Bug 5241396.Need to update the pm_cost_collected to NULL only for direct interorg and sub
929 inventory txfrs and not for intransit receipts that will have a txnfr txn ID */
930
931 /* Bug #2623627. Updating group_id for the transfer transaction_id so
932 the transfer to projects field does not show "Not Applicable" */
933
934 If cpmtv_rec.transaction_action_id <> 12 then
935
936 UPDATE mtl_material_transactions mmt
937 SET mmt.pm_cost_collected = NULL,
938 mmt.pm_cost_collector_group_id = cpmtv_rec.pm_cost_collector_group_id,
939 mmt.last_update_date = sysdate,
940 mmt.last_updated_by = p_user_id,
941 mmt.last_update_login = p_login_id,
942 mmt.request_id = p_req_id,
943 mmt.program_application_id = p_prg_appl_id,
944 mmt.program_id = p_prg_id,
945 mmt.program_update_date = sysdate
946 WHERE mmt.transaction_id IN (p_transaction_id, cpmtv_rec.transfer_transaction_id);
947
948 else
949
950 UPDATE mtl_material_transactions mmt
951 SET mmt.pm_cost_collected = NULL,
952 mmt.pm_cost_collector_group_id = cpmtv_rec.pm_cost_collector_group_id,
953 mmt.last_update_date = sysdate,
954 mmt.last_updated_by = p_user_id,
955 mmt.last_update_login = p_login_id,
956 mmt.request_id = p_req_id,
957 mmt.program_application_id = p_prg_appl_id,
958 mmt.program_id = p_prg_id,
959 mmt.program_update_date = sysdate
960 WHERE mmt.transaction_id = p_transaction_id;
961
962 end If;
963
964 END IF;
965
966 END IF;
967
968 END LOOP;
969
970 EXCEPTION
971
972 WHEN PROCESS_ERROR THEN
973 IF l_err_num = 30000 THEN
974 /* Bug 2386069 - This situation will arise when a receiving txn
975 has not yet been costed but the sending txn is being cost collected. The sending txn is being updated with a warning but
976 pm_cost_collected flag is not being updated to error to prevent
977 user from manually resubmitting the txn for cost collection */
978 rollback to pm_cc_worker_mmt;
979
980 O_err_num := l_err_num;
981 O_err_code := l_err_code;
982 l_err_msg_temp := l_err_msg;
983 l_err_num := 0;
984
985 BEGIN
986
987 UPDATE mtl_material_transactions mmt
988 SET
989 mmt.error_explanation = l_err_msg,
990 mmt.pm_cost_collector_group_id = null,
991 mmt.last_update_date = sysdate,
992 mmt.last_updated_by = p_user_id,
993 mmt.last_update_login = p_login_id,
994 mmt.request_id = p_req_id,
995 mmt.program_application_id = p_prg_appl_id,
996 mmt.program_id = p_prg_id,
997 mmt.program_update_date = sysdate
998 WHERE mmt.transaction_id = p_transaction_id;
999
1000 O_err_msg := SUBSTR(l_err_msg_temp
1001 ||' * '
1002 ||'TXN MARKED IN MMT.'
1003 ,1,240);
1004 EXCEPTION
1005 WHEN OTHERS THEN
1006
1007 O_err_msg := SUBSTR(l_err_msg_temp
1008 ||' * '
1009 ||l_err_msg
1010 ||' * '
1011 ||l_err_code
1012 ||' * '
1013 ||'TXN NOT MARKED IN MMT!'
1014 ,1,240);
1015
1016 END;
1017 ELSE
1018 DECLARE
1019 l_actual_cost_profile VARCHAR2(80);
1020 BEGIN
1021
1022 IF l_err_num < 20000 THEN
1023 rollback to cmlcci_assign_task; --At MAT worker
1024 END IF;
1025
1026 O_err_num := l_err_num;
1027 O_err_code := l_err_code;
1028 l_err_msg_temp := l_err_msg;
1029 l_err_num := 0;
1030
1031 /* bug 3551579.Same IN and Out variables were being used */
1032
1033 l_error_explanation := substr(l_err_msg,1,240) ;
1034 l_error_code := l_err_code;
1035
1036 /* Fix for Bug#4239769
1037 * Need to check the profile value to determine if the zero
1038 * actual cost transactions should be marked as 'E' or not.
1039 */
1040 IF O_err_num = 20002 THEN
1041 l_actual_cost_profile := FND_PROFILE.VALUE('CST_ERROR_ZERO_ACTUAL_COST_TO_PROJECTS');
1042 END IF;
1043
1044 IF ( (O_err_num = 20002 and l_actual_cost_profile = 1)
1045 OR
1046 (O_err_num <> 20002)
1047 ) then
1048
1049 pm_mark_error_mmt(p_transaction_id,
1050 l_error_code,
1051 l_error_explanation,
1052 p_user_id,
1053 p_login_id,
1054 p_req_id,
1055 p_prg_appl_id,
1056 p_prg_id,
1057 l_err_num,
1058 l_err_code,
1059 l_err_msg);
1060 IF (l_err_num <> 0) THEN
1061 O_err_msg := SUBSTR(l_err_msg_temp
1062 ||' * '
1063 ||l_err_msg
1064 ||' * '
1065 ||l_err_code
1066 ||' * '
1067 ||'TXN NOT MARKED IN MMT!'
1068 ,1,240);
1069 ELSE
1070 O_err_msg := SUBSTR(l_err_msg_temp
1071 ||' * '
1072 ||'TXN MARKED IN MMT.'
1073 ,1,240);
1074
1075 END IF;
1076
1077 ELSE
1078
1079 UPDATE mtl_material_transactions mmt
1080 SET mmt.pm_cost_collected = NULL,
1081 mmt.pm_cost_collector_group_id = NULL,
1082 mmt.last_update_date = sysdate,
1083 mmt.last_updated_by = p_user_id,
1084 mmt.last_update_login = p_login_id,
1085 mmt.request_id = p_req_id,
1086 mmt.program_application_id = p_prg_appl_id,
1087 mmt.program_id = p_prg_id,
1088 mmt.program_update_date = sysdate
1089 WHERE mmt.transaction_id =p_transaction_id;
1090
1091 O_err_msg := SUBSTR(l_err_msg_temp ||'Zero Cost Txn. but not marked as error in MMT' ,1,240);
1092
1093 END IF;
1094 END;
1095
1096 END IF;
1097
1098 WHEN OTHERS THEN
1099 rollback to cmlcci_assign_task; --At MAT worker
1100 O_err_num := SQLCODE;
1101 O_err_code := NULL;
1102 l_err_msg_temp := 'CSTPPCCB.pm_cc_worker_mmt('
1103 || to_char(l_stmt_num)
1104 || '): '
1105 || substr(SQLERRM,1,150);
1106 l_err_num := 0;
1107
1108 /* bug 3551579.Same IN and Out variables were being used */
1109
1110 l_error_explanation := substr(l_err_msg,1,240) ;
1111 l_error_code := l_err_code;
1112
1113 pm_mark_error_mmt(p_transaction_id,
1114 l_error_code,
1115 l_error_explanation,
1116 p_user_id,
1117 p_login_id,
1118 p_req_id,
1119 p_prg_appl_id,
1120 p_prg_id,
1121 l_err_num,
1122 l_err_code,
1123 l_err_msg);
1124 IF (l_err_num <> 0) THEN
1125 O_err_msg := SUBSTR(l_err_msg_temp
1126 ||' * '
1127 ||l_err_msg
1128 ||' * '
1129 ||l_err_code
1130 ||' * '
1131 ||'TXN NOT MARKED IN MMT!'
1132 ,1,240);
1133 ELSE
1134 O_err_msg := SUBSTR(l_err_msg_temp
1135 ||' * '
1136 ||'TXN MARKED IN MMT.'
1137 ,1,240);
1138
1139 END IF;
1140 END pm_cc_worker_mmt;
1141
1142 /*----------------------------------------------------------------------------*
1143 | PRIVATE PROCEDURE |
1144 | assign_groups_to_wt_txns |
1145 | |
1146 | DESCRIPTION |
1147 | This procedure would for every record selected from the view, update the|
1148 | WT record to assign a group_id. The number of records to be updated is |
1149 | determined by the user_spec_group_size. Delete all 'WITE' records if any|
1150 | for the transactions that were assigned the group_id. |
1151 | |
1152 | Every Transaction that satisfies the conditions mentioned below gets |
1153 | a group id assigned to itself. |
1154 | |
1155 | - All transactions resulting from a job that is Project related |
1156 | |
1157 | - Select Txns: Resource, O/P and Overhead |
1158 | |
1159 | - Ensure that the transaction has not yet been assigned a group_id |
1160 | |
1161 | - Ensure that the transaction took place before the Date upto which the |
1162 | Cost Collection was desired |
1163 | |
1164 | - Ensure that the transaction took place in Org for which the Cost Coll |
1165 | was desired |
1166 | |
1167 | PARAMETERS |
1168 | p_Org_Id, |
1169 | p_prior_days, |
1170 | p_user_spec_group_size, |
1171 | p_rows_processed, |
1172 | p_group_id OUT, |
1173 | p_user_id, |
1174 | p_login_id, |
1175 | p_req_id, |
1176 | p_prg_appl_id, |
1177 | p_prg_id, |
1178 | O_err_num, |
1179 | O_err_code, |
1180 | O_err_msg |
1181 | |
1182 | HISTORY |
1183 | 07-SEP-96 Bhaskar Dasari Created. |
1184 | |
1185 | 21-NOV-97 Hemant Gosain Modified. Refer Bug# 589460 Regarding |
1186 | PJM Auto Task API. Get Prj/Tsk Ref from Table WT. |
1187 *----------------------------------------------------------------------------*/
1188 PROCEDURE assign_groups_to_wt_txns (
1189 p_Org_Id NUMBER,
1190 p_prior_days NUMBER,
1191 p_user_spec_group_size NUMBER,
1192 p_rows_processed OUT NOCOPY NUMBER,
1193 p_group_id OUT NOCOPY NUMBER,
1194 p_user_id NUMBER,
1195 p_login_id NUMBER,
1196 p_req_id NUMBER,
1197 p_prg_appl_id NUMBER,
1198 p_prg_id NUMBER,
1199 O_err_num OUT NOCOPY NUMBER,
1200 O_err_code OUT NOCOPY VARCHAR2,
1201 O_err_msg OUT NOCOPY VARCHAR2)
1202 IS
1203
1204 CURSOR sel_wt_trx ( c_Org_Id NUMBER,
1205 c_prior_days NUMBER,
1206 c_user_spec_group_size NUMBER) IS
1207 SELECT NULL
1208 FROM wip_transactions wt
1209 WHERE wt.organization_id = c_Org_Id
1210 AND wt.transaction_date <= ((trunc(sysdate) - c_prior_days) + 0.99999)
1211 AND wt.pm_cost_collected = 'N'
1212 AND wt.transaction_type in (1,2,3,17)
1213 AND wt.project_id IS NOT NULL -- Bug #589460
1214 AND wt.pm_cost_collector_group_id is NULL
1215 AND rownum <= c_user_spec_group_size
1216
1217 FOR UPDATE OF wt.pm_cost_collected NOWAIT;
1218
1219 l_group_id NUMBER;
1220 l_err_num NUMBER;
1221 l_err_code VARCHAR2(240);
1222 l_err_msg VARCHAR2(240);
1223 l_stmt_num NUMBER;
1224 l_rows NUMBER;
1225 l_debug VARCHAR2(80);
1226
1227 BEGIN
1228
1229 -- initialize local variables
1230 l_err_num := 0;
1231 l_err_code := '';
1232 l_err_msg := '';
1233 p_rows_processed := 0;
1234 l_stmt_num := 1;
1235
1236 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
1237 if (l_debug = 'Y') then
1238 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: assign_groups_to_wt_txns ...');
1239 end if;
1240
1241 l_stmt_num := 10;
1242
1243 SELECT wip_transactions_S.nextval
1244 INTO l_group_id
1245 FROM dual;
1246
1247 p_group_id := l_group_id;
1248 l_stmt_num := 20;
1249
1250 FOR sel_wt_rec IN sel_wt_trx( p_Org_Id,
1251 p_prior_days,
1252 p_user_spec_group_size) LOOP
1253
1254 UPDATE wip_transactions wt
1255 SET wt.pm_cost_collector_group_id = l_group_id,
1256 wt.last_update_date = sysdate,
1257 wt.last_updated_by = p_user_id,
1258 wt.last_update_login = p_login_id,
1259 wt.request_id = p_req_id,
1260 wt.program_application_id = p_prg_appl_id,
1261 wt.program_id = p_prg_id,
1262 wt.program_update_date = sysdate
1263 WHERE CURRENT of sel_wt_trx;
1264
1265 p_rows_processed := sel_wt_trx%ROWCOUNT;
1266 l_rows := sel_wt_trx%ROWCOUNT;
1267
1268 END LOOP;
1269
1270 l_stmt_num := 30;
1271
1272 DELETE wip_txn_interface_errors wite
1273 WHERE wite.transaction_id in
1274 ( SELECT wt.transaction_id
1275 FROM wip_transactions wt
1276 WHERE wt.pm_cost_collector_group_id = l_group_id
1277 AND wt.pm_cost_collected = 'N' )
1278 AND wite.error_column = 'PM_COST_COLLECTED';
1279
1280
1281 EXCEPTION
1282 WHEN OTHERS THEN
1283 rollback;
1284 O_err_num := SQLCODE;
1285 O_err_code := NULL;
1286 O_err_msg := 'CSTPPCCB.assign_groups_to_wt_txns('
1287 || to_char(l_stmt_num)
1288 || '): '
1289 || substr(SQLERRM,1,200);
1290
1291 END assign_groups_to_wt_txns;
1292 /*----------------------------------------------------------------------------*
1293 | PRIVATE PROCEDURE |
1294 | pm_cc_worker_wt |
1295 | |
1296 | DESCRIPTION |
1297 | This procedure would Cost Collect the given transaction id. The code |
1298 | would check if the transaction is with errors. If none, the code would |
1299 | to make a call to a procedure that would process the transaction. On |
1300 | successful return from the process_txn procedure, the transaction being |
1301 | is flagged as successfully cost collected by marking the flag |
1302 | 'pm_cost_collected' as NULL. |
1303 | |
1304 | PARAMETERS |
1305 | p_transaction_id |
1306 | p_wip_txn_source_literal |
1307 | p_wip_syslink_literal |
1308 | p_bur_syslink_literal |
1309 | p_denom_currency_code |
1310 | p_user_id, |
1311 | p_login_id, |
1312 | p_req_id, |
1313 | p_prg_appl_id, |
1314 | p_prg_id, |
1315 | O_err_num, |
1316 | O_err_code, |
1317 | O_err_msg |
1318 | |
1319 | HISTORY |
1320 | 07-SEP-96 Bhaskar Dasari Created. |
1321 | |
1322 | 30-JUL-97 Hemant Gosain Modified. |
1323 | Enhanced Selection criteria to include WTA reference account |
1324 | to support Project Capitalization. |
1325 | |
1326 | 21-NOV-97 Hemant Gosain Modified. |
1327 | Refer Bug# 589460. Get Prj/Tsk form WT Table. |
1328 *----------------------------------------------------------------------------*/
1329 PROCEDURE pm_cc_worker_wt (
1330 p_transaction_id NUMBER,
1331 p_Org_Id NUMBER,
1332 p_wip_txn_source_literal VARCHAR2,
1333 p_wip_straight_time_literal VARCHAR2,
1334 p_wip_syslink_literal VARCHAR2,
1335 p_bur_syslink_literal VARCHAR2,
1336 p_denom_currency_code VARCHAR2,
1337 p_user_id NUMBER,
1338 p_login_id NUMBER,
1339 p_req_id NUMBER,
1340 p_prg_appl_id NUMBER,
1341 p_prg_id NUMBER,
1342 O_err_num OUT NOCOPY NUMBER,
1343 O_err_code OUT NOCOPY VARCHAR2,
1344 O_err_msg OUT NOCOPY VARCHAR2)
1345 IS
1346 /* The CURSOR has been changed owing to Bug#589460 and the UNION of WDJ and CFM
1347 has been removed because we pick the prj/task reference from the WT Table
1348 rather than from the Entity Definition.
1349 */
1350
1351 /* Added DISTINCT clause because ppf could have multiple records based on
1352 effectivity dates for the same person_id Bug # 703956 */
1353
1354 /*Included the business_group_id parameter in the cursor bug 2124765 */
1355
1356 CURSOR sel_wt_trx_to_cost (C_transaction_id NUMBER,
1357 C_organization_id NUMBER) IS
1358 SELECT DISTINCT wta.transaction_date c_transaction_date,
1359 ppf.business_group_id c_business_group_id,
1360 ppf.employee_number c_employee_number,
1361 wta.base_transaction_value c_base_transaction_value,
1362 wt.primary_quantity c_primary_quantity,
1363 wta.resource_id c_resource_id,
1364 br.description c_resource_description,
1365 br.expenditure_type c_expenditure_type,
1366 wt.project_id c_project_id,
1367 wt.task_id c_task_id,
1368 bd.pa_expenditure_org_id c_pa_expenditure_org_id,
1369 wt.acct_period_id c_acct_period_id,
1370 wt.pm_cost_collector_group_id c_group_id,
1371 wt.department_id c_department_id,
1372 wt.transaction_type c_transaction_type,
1373 wta.cost_element_id c_cost_element_id,
1374 wt.wip_entity_id c_wip_entity_id,
1375 wta.accounting_line_type c_accounting_line_type,
1376 wt.primary_uom c_primary_uom,
1377 wta.basis_resource_id c_basis_resource_id,
1378 wta.reference_account c_reference_account,
1379 wta.wip_sub_ledger_id c_wip_dr_sub_ledger_id
1380 FROM wip_transaction_accounts wta,
1381 wip_transactions wt,
1382 bom_resources br,
1383 bom_departments bd,
1384 per_people_f ppf
1385 WHERE wt.transaction_type in (1,2,3)
1386 AND wta.accounting_line_type = 7
1387 AND wt.transaction_id = wta.transaction_id
1388 AND br.resource_id = wta.resource_id
1389 AND bd.department_id = wt.department_id
1390 AND bd.organization_id = wt.organization_id
1391 AND wt.transaction_id = C_transaction_id
1392 AND wt.organization_id = C_organization_id
1393 AND ppf.person_id (+) = wt.employee_id
1394 /* Bug:2395906*/
1395 AND ppf.effective_start_date(+) <= trunc(sysdate)
1396 AND ppf.effective_end_date(+) >= trunc(sysdate)
1397 AND (ppf.employee_number is not null or ppf.person_id is null)
1398
1399 /*Added the above and condition to check if the employee_number
1400 is not null.This is modified for porting bug #1573297 in 11.0
1401 to 11.5 Bug 1660313*/
1402
1403 UNION
1404 SELECT DISTINCT wta.transaction_date c_transaction_date,
1405 to_number(NULL) c_business_group_id,
1406 NULL c_employee_number,
1407 wta.base_transaction_value c_base_transaction_value,
1408 wt.primary_quantity c_primary_quantity,
1409 wta.resource_id c_resource_id,
1410 pla.item_description c_resource_description,
1411 ppp.dir_item_expenditure_type c_expenditure_type,
1412 wt.project_id c_project_id,
1413 wt.task_id c_task_id,
1414 wt.organization_id c_pa_expenditure_org_id,
1415 wt.acct_period_id c_acct_period_id,
1416 wt.pm_cost_collector_group_id c_group_id,
1417 wt.department_id c_department_id,
1418 wt.transaction_type c_transaction_type,
1419 wta.cost_element_id c_cost_element_id,
1420 wt.wip_entity_id c_wip_entity_id,
1421 wta.accounting_line_type c_accounting_line_type,
1422 wt.primary_uom c_primary_uom,
1423 wta.basis_resource_id c_basis_resource_id,
1424 wta.reference_account c_reference_account,
1425 wta.wip_sub_ledger_id c_wip_dr_sub_ledger_id
1426 FROM wip_transaction_accounts wta,
1427 wip_transactions wt,
1428 pjm_project_parameters ppp,
1429 po_lines_all pla
1430 WHERE wt.transaction_type = 17
1431 AND pla.po_line_id = wt.po_line_id
1432 AND wta.accounting_line_type = 7
1433 AND wt.transaction_id = wta.transaction_id
1434 AND ppp.organization_id = wt.organization_id
1435 AND ppp.project_id = wt.project_id
1436 AND wt.transaction_id = C_transaction_id
1437 AND wt.organization_id = C_organization_id;
1438
1439 l_process_yn NUMBER;
1440 l_err_num NUMBER;
1441 l_err_code VARCHAR2(240);
1442 l_err_msg VARCHAR2(240);
1443 l_err_msg_temp VARCHAR2(240);
1444 l_exp_org_name VARCHAR2(60);
1445 PROCESS_ERROR EXCEPTION;
1446 l_stmt_num NUMBER;
1447 l_accounting_line_type NUMBER;
1448 l_cr_code_combination_id NUMBER;
1449 l_wip_cr_sub_ledger_id NUMBER;
1450 l_debug VARCHAR2(80);
1451 l_business_group_name VARCHAR2(80) ;
1452
1453 /* Direct Item Enh Project */
1454 l_expenditure_type VARCHAR2(30) ;
1455 l_return_status VARCHAR2(1) ;
1456 l_msg_count NUMBER := 0;
1457 l_msg_data VARCHAR2(8000) ;
1458 l_api_message VARCHAR2(8000);
1459
1460 l_err_in_code VARCHAR2(240);
1461 l_err_in_msg VARCHAR2(240);
1462
1463 BEGIN
1464
1465 -- initialize local variables
1466 l_err_num := 0;
1467 l_err_code := '';
1468 l_err_msg := '';
1469 l_err_msg_temp := '';
1470 l_exp_org_name := '';
1471 l_accounting_line_type := 0;
1472 l_cr_code_combination_id := 0;
1473 l_stmt_num := 1;
1474 l_return_status := fnd_api.g_ret_sts_success;
1475
1476 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
1477 if (l_debug = 'Y') then
1478 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_cc_worker_wt');
1479 end if;
1480
1481 l_stmt_num := 10;
1482
1483 FOR wt_rec IN sel_wt_trx_to_cost(p_transaction_id, p_Org_Id) LOOP
1484
1485 if (l_debug = 'Y') then
1486 FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing transaction : '||to_char(p_transaction_id));
1487 end if;
1488
1489 savepoint pm_cc_worker_wt;
1490 pm_check_error_wt ( p_transaction_id,
1491 wt_rec.c_project_id,
1492 wt_rec.c_task_id,
1493 wt_rec.c_expenditure_type,
1494 p_Org_Id,
1495 wt_rec.c_department_id,
1496 wt_rec.c_employee_number,
1497 l_exp_org_name,
1498 l_process_yn ,
1499 p_user_id,
1500 p_login_id,
1501 p_req_id,
1502 p_prg_appl_id,
1503 p_prg_id,
1504 l_err_num,
1505 l_err_code,
1506 l_err_msg);
1507
1508 IF (l_err_num <> 0) THEN
1509 -- Error occured
1510 raise PROCESS_ERROR;
1511 END IF;
1512
1513 IF l_process_yn = 1 THEN
1514
1515 /* START WIP TXN CR ACCT */
1516 l_stmt_num := 12;
1517 -- Get the Cr Account for this Transaction
1518 SELECT decode(wt_rec.c_transaction_type,
1519 17, 5, --Rcv Inspection(Direct Item)
1520 decode(wt_rec.c_cost_element_id,
1521 3, 4, --RES ABSO;RES
1522 4, 4, --RES ABSO;OSP
1523 5, 3, --OVHD ABSO
1524 4))
1525 INTO l_accounting_line_type
1526 FROM DUAL;
1527
1528 l_stmt_num := 14;
1529
1530 /* Bug 2599649
1531 Added check for resource_id also to make
1532 sure to the correct overhead absorption account
1533 for a particular overhead is picked up
1534 */
1535
1536 SELECT NVL(reference_account,-99)
1537 INTO l_cr_code_combination_id
1538 FROM wip_transaction_accounts
1539 WHERE transaction_id = p_transaction_id
1540 AND organization_id = p_org_id
1541 AND cost_element_id = wt_rec.c_cost_element_id
1542 AND accounting_line_type = l_accounting_line_type
1543 AND NVL(resource_id,-99) = NVL(wt_rec.c_resource_id,-99);
1544
1545 /* changes to get the WIP credit sub Ledger ID from WTA */
1546
1547 l_stmt_num := 16;
1548
1549 SELECT MAX(WIP_SUB_LEDGER_ID)
1550 INTO l_wip_cr_sub_ledger_id
1551 FROM wip_transaction_accounts wta
1552 WHERE transaction_id = p_transaction_id
1553 AND reference_account = l_cr_code_combination_id
1554 AND organization_id = p_org_id
1555 AND cost_element_id = wt_rec.c_cost_element_id
1556 AND accounting_line_type = l_accounting_line_type
1557 AND NVL(resource_id,-99) = NVL(wt_rec.c_resource_id,-99);
1558
1559
1560 -- if CR account could not be obtained then
1561 -- set Cr account = dr account.
1562 l_stmt_num := 16;
1563 IF l_cr_code_combination_id = -99 THEN
1564 l_cr_code_combination_id := wt_rec.c_reference_account;
1565 l_wip_cr_sub_ledger_id := wt_rec.c_wip_dr_sub_ledger_id;
1566 END IF;
1567 /* END WIP TXN CR ACCT */
1568 l_stmt_num := 18;
1569
1570 /*Get the Business group Name from the business group Id and pass it
1571 for insertion into PA_TRANSACTION_INTERFACE.Bug Fix for
1572 Bug 2124765 */
1573
1574 if wt_rec.c_business_group_id is not null THEN
1575 Select haout.name into l_business_group_name
1576 From hr_all_organization_units_tl haout
1577 WHERE
1578 haout.organization_id = wt_rec.c_business_group_id
1579 AND haout.language = USERENV('LANG');
1580 end if;
1581
1582 /* Check to see if there is a defined expenditure type for the direct item procurement txn */
1583 l_stmt_num := 19;
1584 if (wt_rec.c_transaction_type = 17) then
1585 CST_eamCost_PUB.get_ExpType_for_DirectItem(
1586 p_api_version => 1.0,
1587 x_return_status => l_return_status,
1588 x_msg_count => l_msg_count,
1589 x_msg_data => l_msg_data,
1590 p_txn_id => p_transaction_id,
1591 x_expenditure_type => l_expenditure_type
1592 );
1593
1594 if (l_return_status <> fnd_api.g_ret_sts_success) then
1595 FND_FILE.put_line(FND_FILE.log, l_msg_data);
1596 l_api_message := 'get_ExpType_for_DirectItem returned unexpected error';
1597 FND_MESSAGE.set_name('BOM','CST_API_MESSAGE');
1598 FND_MESSAGE.set_token('TEXT', l_api_message);
1599 FND_MSG_pub.add;
1600 raise fnd_api.g_exc_unexpected_error;
1601 elsif (l_expenditure_type is not null and l_expenditure_type <> to_char(-1)) then
1602 wt_rec.c_expenditure_type := l_expenditure_type;
1603 end if;
1604 end if;
1605
1606 pm_process_txn_wt( wt_rec.c_group_id,
1607 l_business_group_name,
1608 p_transaction_id,
1609 p_Org_Id,
1610 wt_rec.c_employee_number,
1611 wt_rec.c_department_id,
1612 wt_rec.c_project_id,
1613 wt_rec.c_task_id,
1614 wt_rec.c_transaction_date,
1615 wt_rec.c_base_transaction_value,
1616 wt_rec.c_primary_quantity,
1617 wt_rec.c_acct_period_id,
1618 wt_rec.c_expenditure_type,
1619 wt_rec.c_resource_description,
1620 wt_rec.c_transaction_type,
1621 wt_rec.c_cost_element_id,
1622 l_exp_org_name,
1623 p_wip_txn_source_literal,
1624 p_wip_straight_time_literal,
1625 p_wip_syslink_literal,
1626 p_bur_syslink_literal,
1627 l_err_num,
1628 l_err_code,
1629 l_err_msg,
1630 wt_rec.c_reference_account,
1631 l_cr_code_combination_id,
1632 wt_rec.c_wip_dr_sub_ledger_id,
1633 l_wip_cr_sub_ledger_id,
1634 wt_rec.c_wip_entity_id,
1635 wt_rec.c_resource_id,
1636 wt_rec.c_basis_resource_id,
1637 p_denom_currency_code);
1638
1639 IF (l_err_num <> 0) THEN
1640 -- Error occured
1641 raise PROCESS_ERROR;
1642 ELSE
1643
1644 l_stmt_num := 20;
1645
1646 UPDATE wip_transactions wt
1647 SET wt.pm_cost_collected = NULL,
1648 wt.last_update_date = sysdate,
1649 wt.last_updated_by = p_user_id,
1650 wt.last_update_login = p_login_id,
1651 wt.request_id = p_req_id,
1652 wt.program_application_id = p_prg_appl_id,
1653 wt.program_id = p_prg_id,
1654 wt.program_update_date = sysdate
1655 WHERE wt.transaction_id = p_transaction_id;
1656 END IF;
1657 END IF;
1658
1659 END LOOP;
1660
1661 EXCEPTION
1662
1663 WHEN PROCESS_ERROR THEN
1664 IF l_err_num < 20000 THEN
1665 rollback to cmlccw_assign_task; --At WIP worker
1666 END IF;
1667 O_err_num := l_err_num;
1668 O_err_code := l_err_code;
1669 l_err_msg_temp := l_err_msg;
1670 l_err_num := 0;
1671 l_err_in_code := l_err_code;
1672 l_err_in_msg := l_err_msg;
1673 pm_mark_error_wt(p_transaction_id,
1674 l_err_in_code,
1675 l_err_in_msg,
1676 p_user_id,
1677 p_login_id,
1678 p_req_id,
1679 p_prg_appl_id,
1680 p_prg_id,
1681 l_err_num,
1682 l_err_code,
1683 l_err_msg);
1684 IF (l_err_num <> 0) THEN
1685 O_err_msg := SUBSTR(l_err_msg_temp
1686 ||' * '
1687 ||l_err_msg
1688 ||' * '
1689 ||l_err_code
1690 ||' * '
1691 ||'TXN NOT MARKED IN WTIE!'
1692 ,1,240);
1693 ELSE
1694 O_err_msg := SUBSTR(l_err_msg_temp
1695 ||' * '
1696 ||'TXN MARKED IN WTIE.'
1697 ,1,240);
1698
1699 END IF;
1700
1701 WHEN OTHERS THEN
1702 rollback to cmlccw_assign_task; --At WIP Worker
1703 O_err_num := SQLCODE;
1704 O_err_code := NULL;
1705 l_err_msg_temp := 'CSTPPCCB.pm_cc_worker_wt('
1706 || to_char(l_stmt_num)
1707 || '): '
1708 || substr(SQLERRM,1,150);
1709
1710 l_err_num := 0;
1711 l_err_in_code := l_err_code;
1712 l_err_in_msg := l_err_msg;
1713
1714 pm_mark_error_wt(p_transaction_id,
1715 l_err_in_code,
1716 l_err_in_msg,
1717 p_user_id,
1718 p_login_id,
1719 p_req_id,
1720 p_prg_appl_id,
1721 p_prg_id,
1722 l_err_num,
1723 l_err_code,
1724 l_err_msg);
1725 IF (l_err_num <> 0) THEN
1726 O_err_msg := SUBSTR(l_err_msg_temp
1727 ||' * '
1728 ||l_err_msg
1729 ||' * '
1730 ||l_err_code
1731 ||' * '
1732 ||'TXN NOT MARKED IN WTIE!'
1733 ,1,240);
1734 ELSE
1735 O_err_msg := SUBSTR(l_err_msg_temp
1736 ||' * '
1737 ||'TXN MARKED IN WTIE.'
1738 ,1,240);
1739
1740 END IF;
1741 END pm_cc_worker_wt;
1742 /*----------------------------------------------------------------------------*
1743 | PRIVATE PROCEDURE |
1744 | pm_process_txn_mmt |
1745 | |
1746 | DESCRIPTION |
1747 | The procedure cost collects the given transaction. The manner of cost |
1748 | collection is decided based on the type of transaction at hand. Below |
1749 | are the various transaction groups and their differences w.r.t cost |
1750 | collection. |
1751 | |
1752 | -- get the project costed flag for job if the txn is a job related |
1753 | -- assign transaction org as expenditure org |
1754 | -- get the schedule close date from acct_periods |
1755 | |
1756 | All Transactions in a Standard Costing Organization with transaction |
1757 | type having its type_class set to 1 implying that it refers to a Capital|
1758 | Project. Cost Collection is done at the specified cost at transaction |
1759 | time. |
1760 | |
1761 | PARAMETERS |
1762 | |
1763 | p_Group_Id, |
1764 | p_transaction_id, |
1765 | p_organization_id, |
1766 | p_transaction_action_id, |
1767 | p_transaction_source_type_id, |
1768 | p_type_class, |
1769 | p_project_id, |
1770 | p_task_id |
1771 | p_transaction_date |
1772 | p_primary_quantity |
1773 | p_expenditure_type |
1774 | p_item_description |
1775 | p_cost_group_id |
1776 | p_transfer_cost_group_id |
1777 | p_inventory_item_id |
1778 | p_transaction_source_id |
1779 | p_to_project_id, |
1780 | p_to_task_id |
1781 | p_source_project_id, |
1782 | p_source_task_id, |
1783 | p_transfer_transaction_id, |
1784 | p_primary_cost_method, |
1785 | p_std_cg_acct, Added for bug 3495967 |
1786 | p_acct_period_id, |
1787 | p_exp_org_id, |
1788 | p_distribution_account_id, |
1789 | p_proj_job_ind |
1790 | p_first_matl_se_exp_type |
1791 | p_inv_txn_source_literal |
1792 | p_cap_txn_source_literal |
1793 | p_inv_syslink_literal |
1794 | p_bur_syslink_literal |
1795 | p_wip_syslink_literal |
1796 | p_user_def_exp_type |
1797 | O_err_num, |
1798 | O_err_code, |
1799 | O_err_msg, |
1800 | p_transfer_organization_id, |
1801 | p_flow_schedule, |
1802 | p_si_asset_yes_no, |
1803 | p_transfer_si_asset_yes_no |
1804 | p_denom_currency_code |
1805 | |
1806 | CALLED FROM |
1807 | pm_cc_worker_mmt() |
1808 | |
1809 | HISTORY |
1810 | 07-SEP-96 Bhaskar Dasari Created. |
1811 | |
1812 | 30-JUL-97 Hemant Gosain Modified. |
1813 | Added Capitalization Support. |
1814 | Added support for -ve WIP component Transactions. |
1815 | |
1816 | 20-AUG-97 Hemant Gosain Modified. |
1817 | Added support for CFM. |
1818 | Changed Logic for Prj. Misc Txn. |
1819 | |
1820 | 21-NOV-97 Hemant Gosain Modified. |
1821 | Changed Logic for Direct IO Xfer. |
1822 | |
1823 | 22-APR-01 Hemant Gosain Modified. |
1824 | Added Support for Std PJM. |
1825 *----------------------------------------------------------------------------*/
1826
1827 PROCEDURE pm_process_txn_mmt (
1828 p_Group_Id NUMBER,
1829 p_transaction_id NUMBER,
1830 p_organization_id NUMBER,
1831 p_transaction_action_id NUMBER,
1832 p_transaction_source_type_id NUMBER,
1833 p_type_class NUMBER,
1834 p_project_id NUMBER,
1835 p_task_id NUMBER,
1836 p_transaction_date DATE,
1837 p_primary_quantity NUMBER,
1838 p_expenditure_type VARCHAR2,
1839 p_item_description VARCHAR2,
1840 p_cost_group_id NUMBER,
1841 p_transfer_cost_group_id NUMBER,
1842 p_inventory_item_id NUMBER,
1843 p_transaction_source_id NUMBER,
1844 p_to_project_id NUMBER,
1845 p_to_task_id NUMBER,
1846 p_source_project_id NUMBER,
1847 p_source_task_id NUMBER,
1848 p_transfer_transaction_id NUMBER,
1849 p_primary_cost_method NUMBER,
1850 p_std_cg_acct NUMBER, -- Added for bug 3495967
1851 p_acct_period_id NUMBER,
1852 p_exp_org_id NUMBER,
1853 p_distribution_account_id NUMBER,
1854 p_proj_job_ind NUMBER,
1855 p_first_matl_se_exp_type VARCHAR2,
1856 p_inv_txn_source_literal VARCHAR2,
1857 p_cap_txn_source_literal VARCHAR2,
1858 p_inv_syslink_literal VARCHAR2,
1859 p_bur_syslink_literal VARCHAR2,
1860 p_wip_syslink_literal VARCHAR2,
1861 p_user_def_exp_type NUMBER,
1862 O_err_num OUT NOCOPY NUMBER,
1863 O_err_code OUT NOCOPY VARCHAR2,
1864 O_err_msg OUT NOCOPY VARCHAR2,
1865 p_transfer_organization_id NUMBER,
1866 p_flow_schedule VARCHAR2,
1867 p_si_asset_yes_no NUMBER,
1868 p_transfer_si_asset_yes_no NUMBER,
1869 p_denom_currency_code VARCHAR2)
1870
1871 IS
1872
1873 l_err_num NUMBER;
1874 l_err_code VARCHAR2(240);
1875 l_err_msg VARCHAR2(240);
1876 l_stmt_num NUMBER;
1877
1878 l_batch VARCHAR2(15); --Increased width for Bug#2218654
1879 -- UTF8 changes l_organization_name VARCHAR2(60);
1880 l_organization_name hr_organization_units.name%TYPE;
1881 -- l_xfer_organization_name VARCHAR2(60);
1882 l_xfer_organization_name hr_organization_units.name%TYPE;
1883 l_proj_org_id NUMBER;
1884 l_to_proj_org_id NUMBER;
1885 l_source_proj_org_id NUMBER;
1886 l_project_number VARCHAR2(25);
1887 l_to_project_number VARCHAR2(25);
1888 l_source_project_number VARCHAR2(25);
1889 l_task_number VARCHAR2(25);
1890 l_to_task_number VARCHAR2(25);
1891 l_source_task_number VARCHAR2(25);
1892 /*l_gl_date DATE;*/ /* Commented for bug 6266553 */
1893 l_exp_end_date DATE;
1894 l_txn_of_misc_family NUMBER;
1895 l_rownum NUMBER;
1896 l_fob_point NUMBER;
1897 l_earn_moh NUMBER;
1898 l_earn_tomoh NUMBER;
1899 l_exp_type VARCHAR2(30);
1900 l_xfer_currency_code VARCHAR2(15);
1901 l_txn_type NUMBER;
1902 l_default_project NUMBER;
1903 /* Bug 2386069 */
1904 l_costed_flag VARCHAR2(1);
1905 ROW_NOT_COSTED EXCEPTION;
1906 /* Bug 2386069 */
1907 NO_ROWS_TO_INSERT EXCEPTION;
1908 CST_FAILED_GET_EXPENDDATE EXCEPTION;
1909 CST_FAILED_PROJTSK_VALID EXCEPTION;
1910 CST_FAILED_GET_EXP_TYPE EXCEPTION;
1911 CST_FAILED_INSERT_PTI EXCEPTION;
1912 CST_FAILED_STD_CG_FLAG EXCEPTION;
1913 CST_FAILED_TXN_SRC EXCEPTION;
1914
1915 -- UTF8 changes l_recv_iss_organization_name VARCHAR2(60);
1916 l_recv_iss_organization_name hr_all_organization_units.name%TYPE;
1917 l_primary_cost_method_snd NUMBER ;
1918 l_cost_collection_enabled_snd NUMBER ;
1919 l_return_status VARCHAR2(1);
1920 l_msg_count NUMBER;
1921 l_msg_data VARCHAR2(30);
1922
1923 l_std_cg_acct_snd NUMBER;
1924
1925 l_org_id NUMBER;
1926 l_inv_txn_src_literal VARCHAR2(30);
1927 l_transaction_source VARCHAR2(30);
1928 l_cap_inv_txn_src_literal VARCHAR2(30);
1929 l_blue_print_enabled_flag VARCHAR2(1);
1930 l_autoaccounting_flag VARCHAR2(1);
1931
1932
1933 ppv_txfr_flag NUMBER;
1934
1935 l_no_row_c_sel_prj NUMBER;
1936 l_no_row_c_sel_toprj NUMBER;
1937 l_no_ppv NUMBER;
1938 l_operating_unit NUMBER;
1939
1940
1941
1942 /* Cursor for STANDARD ORG Proj. Misc Txn */
1943 /* If the user does not specify an expenditure_type, it will be derived */
1944 /* from the Cost Element Associations */
1945 /* PJMSTD SUPPORT------------------------------ */
1946 /* This cursor is for Std Orgs which are not PJ enabled and hence only */
1947 /* Proj Misc transactions will be cost collected */
1948 /* PJMSTD SUPPORT------------------------------ */
1949 CURSOR c_sel_std_misc IS
1950 SELECT p_cap_txn_source_literal transaction_source,
1951 l_batch batch_name,
1952 l_exp_end_date expenditure_ending_date,
1953 NULL employee_number,
1954 l_organization_name organization_name,
1955 p_transaction_date expenditure_item_date,
1956 l_source_project_number project_number,
1957 l_source_task_number task_number,
1958 decode(mcacd.cost_element_id,
1959 2,0,
1960 5,0,
1961 (-1) * p_primary_quantity) quantity,
1962 decode(mcacd.cost_element_id,
1963 2,0,
1964 5,0,
1965 (-1)*sum(p_primary_quantity * mcacd.actual_cost))
1966 raw_cost,
1967 p_item_description expenditure_comment,
1968 to_char(p_transaction_id) orig_transaction_reference,
1969 decode(mcacd.cost_element_id,
1970 2,0,
1971 5,0,
1972 sum(mcacd.actual_cost)) raw_cost_rate,
1973 'Y' unmatched_negative_txn_flag,
1974 -999999 dr_code_combination_id,
1975 -999999 cr_code_combination_id,
1976 NULL cdl_system_reference1,
1977 NULL cdl_system_reference2,
1978 NULL cdl_system_reference3,
1979 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
1980 l_source_proj_org_id org_id,
1981 (-1)*sum(p_primary_quantity *
1982 mcacd.actual_cost) burdened_cost,
1983 sum(mcacd.actual_cost) burdened_cost_rate,
1984 decode( mcacd.cost_element_id,
1985 2, p_bur_syslink_literal,
1986 3, p_wip_syslink_literal,
1987 4, p_wip_syslink_literal,
1988 5, p_bur_syslink_literal,
1989 p_inv_syslink_literal) system_linkage,
1990 'P' transaction_status_code,
1991 mcacd.cost_element_id cost_element_id,
1992 p_denom_currency_code denom_currency_code
1993 FROM mtl_cst_actual_cost_details mcacd,
1994 mtl_material_transactions mmt
1995 WHERE mmt.transaction_id = p_transaction_id
1996 AND mmt.transaction_id = mcacd.transaction_id
1997 AND mcacd.organization_id = p_organization_id
1998 AND mcacd.inventory_item_id = p_inventory_item_id
1999 AND mcacd.actual_cost <> 0
2000 GROUP BY p_transaction_id,
2001 mcacd.cost_element_id;
2002
2003 /* Cursor for gathering Material Overhead Costs for txns like: */
2004 /* WIP-CFM Assy Comp/Return, InterOrg or PO */
2005 CURSOR c_sel_moh_txn IS
2006 SELECT p_inv_txn_source_literal transaction_source,
2007 l_batch batch_name,
2008 l_exp_end_date expenditure_ending_date,
2009 NULL employee_number,
2010 l_organization_name organization_name,
2011 p_transaction_date expenditure_item_date,
2012 l_project_number project_number,
2013 l_task_number task_number,
2014 br.EXPENDITURE_TYPE expenditure_type,
2015 0 quantity, /* Qty=0 if l=burden */
2016 0 raw_cost, /* RawCost=0 if l=burden */
2017 br.description expenditure_comment,
2018 to_char(p_transaction_id) orig_transaction_reference,
2019 0 raw_cost_rate, /*RawCostrate=0 if l=burden */
2020 'Y' unmatched_negative_txn_flag,
2021 -999999 dr_code_combination_id,
2022 -999999 cr_code_combination_id,
2023 NULL cdl_system_reference1,
2024 NULL cdl_system_reference2,
2025 NULL cdl_system_reference3,
2026 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2027 l_proj_org_id org_id,
2028 macs.ACTUAL_COST*p_primary_quantity burdened_cost,
2029 macs.ACTUAL_COST burdened_cost_rate,
2030 p_bur_syslink_literal system_linkage,
2031 'P' transaction_status_code,
2032 br.resource_id resource_id,
2033 macs.cost_element_id cost_element_id,
2034 p_denom_currency_code denom_currency_code
2035 FROM mtl_actual_cost_subelement macs,
2036 bom_resources br,
2037 mtl_parameters mp
2038 WHERE macs.transaction_id = p_transaction_id
2039 AND macs.ORGANIZATION_ID = mp.ORGANIZATION_ID
2040 AND mp.cost_organization_id = br.organization_id
2041 AND macs.cost_element_id = 2
2042 AND macs.level_type = 1
2043 AND macs.RESOURCE_ID = br.RESOURCE_ID
2044 AND macs.ACTUAL_COST <> 0;
2045
2046 /* Cursor for gathering the receiving side MOH absorption */
2047
2048 CURSOR c_sel_tomoh IS
2049 SELECT p_inv_txn_source_literal transaction_source,
2050 l_batch batch_name,
2051 l_exp_end_date expenditure_ending_date,
2052 NULL employee_number,
2053 l_xfer_organization_name organization_name,
2054 p_transaction_date expenditure_item_date,
2055 l_to_project_number project_number,
2056 l_to_task_number task_number,
2057 br.EXPENDITURE_TYPE expenditure_type,
2058 0 quantity, /* Qty=0 if l=burden */
2059 0 raw_cost, /* RawCost=0 if l=burden */
2060 br.description expenditure_comment,
2061 to_char(p_transfer_transaction_id) orig_transaction_reference,
2062 0 raw_cost_rate, /*RawCostrate=0 if l=burden */
2063 'Y' unmatched_negative_txn_flag,
2064 -999999 dr_code_combination_id,
2065 -999999 cr_code_combination_id,
2066 NULL cdl_system_reference1,
2067 NULL cdl_system_reference2,
2068 NULL cdl_system_reference3,
2069 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2070 l_to_proj_org_id org_id,
2071 (-1)*macs.ACTUAL_COST*p_primary_quantity burdened_cost,
2072 macs.ACTUAL_COST burdened_cost_rate,
2073 p_bur_syslink_literal system_linkage,
2074 'P' transaction_status_code,
2075 br.resource_id resource_id,
2076 macs.cost_element_id cost_element_id,
2077 l_xfer_currency_code denom_currency_code
2078 FROM mtl_actual_cost_subelement macs,
2079 bom_resources br
2080 WHERE macs.transaction_id = p_transfer_transaction_id
2081 AND macs.ORGANIZATION_ID = br.ORGANIZATION_ID
2082 AND macs.cost_element_id = 2
2083 AND macs.level_type = 1
2084 AND macs.RESOURCE_ID = br.RESOURCE_ID
2085 AND macs.ACTUAL_COST <> 0;
2086
2087
2088 /* Cursor for gathering Project related Locator txn costs for any txn */
2089 /* Bug#2580132 - Changed the join between ccicv and mcacd to outer join */
2090 CURSOR c_sel_prj_txn IS
2091 SELECT decode(p_type_class,1,
2092 p_cap_txn_source_literal,
2093 p_inv_txn_source_literal) transaction_source,
2094 l_batch batch_name,
2095 l_exp_end_date expenditure_ending_date,
2096 NULL employee_number,
2097 l_organization_name organization_name,
2098 p_transaction_date expenditure_item_date,
2099 l_project_number project_number,
2100 l_task_number task_number,
2101 decode(mcacd.cost_element_id,2,0,
2102 decode(mcacd.cost_element_id,5,0,p_primary_quantity
2103 )) quantity,
2104
2105 decode(mcacd.cost_element_id,2,0,
2106 decode(mcacd.cost_element_id,5,0,
2107 sum(mcacd.ACTUAL_COST)*p_primary_quantity
2108 )) raw_cost,
2109
2110 p_item_description expenditure_comment,
2111 to_char(p_transaction_id) orig_transaction_reference,
2112
2113 decode(mcacd.cost_element_id,2,0,
2114 decode(mcacd.cost_element_id,5,0,sum(mcacd.ACTUAL_COST)
2115 )) raw_cost_rate,
2116 'Y' unmatched_negative_txn_flag,
2117 -999999 dr_code_combination_id,
2118 -999999 cr_code_combination_id,
2119 NULL cdl_system_reference1,
2120 NULL cdl_system_reference2,
2121 NULL cdl_system_reference3,
2122 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2123 l_proj_org_id org_id,
2124 ((sum(mcacd.ACTUAL_COST)*p_primary_quantity) - (NVL((sum(temp.actual_cost)*p_primary_quantity),0))) burdened_cost,
2125 (sum(mcacd.ACTUAL_COST)-(NVL(sum(temp.actual_cost),0))) burdened_cost_rate,
2126
2127 decode(mcacd.cost_element_id,2, p_bur_syslink_literal,
2128 decode(mcacd.cost_element_id,3, p_wip_syslink_literal,
2129 decode(mcacd.cost_element_id,4, p_wip_syslink_literal,
2130 decode(mcacd.cost_element_id,5, p_bur_syslink_literal,
2131 p_inv_syslink_literal)))) system_linkage,
2132
2133 'P' transaction_status_code ,
2134 mcacd.cost_element_id cost_element_id,
2135 p_denom_currency_code denom_currency_code
2136 FROM mtl_cst_actual_cost_details mcacd,
2137 (Select SUM(actual_cost) actual_cost,
2138 transaction_id,
2139 organization_id,
2140 cost_element_id,
2141 level_type,
2142 layer_id
2143 from mtl_actual_cost_subelement macs
2144 where transaction_id = p_transaction_id
2145 and organization_id = p_organization_id
2146 group by transaction_id,
2147 organization_id,
2148 cost_element_id,
2149 level_type,
2150 layer_id
2151 ) temp,
2152 cst_cg_item_costs_view ccicv --PJMSTD
2153 WHERE mcacd.transaction_id = p_transaction_id
2154 AND mcacd.organization_id = p_organization_id
2155 AND mcacd.inventory_item_id = p_inventory_item_id
2156 AND mcacd.actual_cost <> 0
2157 AND mcacd.layer_id = decode(p_primary_cost_method,
2158 1, -1,ccicv.layer_id) --PJMSTD
2159 AND temp.transaction_id(+) =
2160 mcacd.transaction_id
2161 AND temp.organization_id(+) = mcacd.organization_id
2162 AND temp.cost_element_id(+) = mcacd.cost_element_id
2163 AND temp.level_type(+) = mcacd.level_type
2164 AND ccicv.organization_id = p_organization_id
2165 AND ccicv.inventory_item_id = p_inventory_item_id
2166 AND ccicv.cost_group_id = decode(p_primary_cost_method,
2167 1, 1, p_cost_group_id) --PJMSTD
2168 GROUP BY mcacd.transaction_id,
2169 mcacd.cost_element_id
2170 UNION ALL /* BUG #2972878, 2580132 */
2171 SELECT decode(p_type_class,1,
2172 p_cap_txn_source_literal,
2173 p_inv_txn_source_literal) transaction_source,
2174 l_batch batch_name,
2175 l_exp_end_date expenditure_ending_date,
2176 NULL employee_number,
2177 l_organization_name organization_name,
2178 p_transaction_date expenditure_item_date,
2179 l_project_number project_number,
2180 l_task_number task_number,
2181 decode(mcacd.cost_element_id,2,0,
2182 decode(mcacd.cost_element_id,5,0,p_primary_quantity)) quantity,
2183
2184 decode(mcacd.cost_element_id,2,0,
2185 decode(mcacd.cost_element_id,5,0,
2186 sum(mcacd.ACTUAL_COST)*p_primary_quantity
2187 ))raw_cost,
2188
2189 p_item_description expenditure_comment,
2190 to_char(p_transaction_id) orig_transaction_reference,
2191
2192 decode(mcacd.cost_element_id,2,0,
2193 decode(mcacd.cost_element_id,5,0,sum(mcacd.ACTUAL_COST)
2194 )) raw_cost_rate,
2195
2196 'Y' unmatched_negative_txn_flag,
2197 -999999 dr_code_combination_id,
2198 -999999 cr_code_combination_id,
2199 NULL cdl_system_reference1,
2200 NULL cdl_system_reference2,
2201 NULL cdl_system_reference3,
2202 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2203 l_proj_org_id org_id,
2204 ((sum(mcacd.ACTUAL_COST)*p_primary_quantity) - (NVL((sum(temp.actual_cost)*p_primary_quantity),0))) burdened_cost,
2205 (sum(mcacd.ACTUAL_COST)-(NVL(sum(temp.actual_cost),0))) burdened_cost_rate,
2206
2207 decode(mcacd.cost_element_id,2, p_bur_syslink_literal,
2208 decode(mcacd.cost_element_id,3, p_wip_syslink_literal,
2209 decode(mcacd.cost_element_id,4, p_wip_syslink_literal,
2210 decode(mcacd.cost_element_id,5, p_bur_syslink_literal,
2211 p_inv_syslink_literal)))) system_linkage,
2212
2213 'P' transaction_status_code ,
2214 mcacd.cost_element_id cost_element_id,
2215 p_denom_currency_code denom_currency_code
2216 FROM mtl_cst_actual_cost_details mcacd,
2217 (Select SUM(actual_cost) actual_cost,
2218 transaction_id,
2219 organization_id,
2220 cost_element_id,
2221 level_type,
2222 layer_id
2223 from mtl_actual_cost_subelement macs
2224 where transaction_id = p_transaction_id
2225 and organization_id = p_organization_id
2226 group by transaction_id,
2227 organization_id,
2228 cost_element_id,
2229 level_type,
2230 layer_id
2231 ) temp,
2232 mtl_system_items msi
2233 WHERE mcacd.transaction_id = p_transaction_id
2234 AND mcacd.organization_id = p_organization_id
2235 AND mcacd.inventory_item_id = p_inventory_item_id
2236 AND mcacd.inventory_item_id = msi.inventory_item_id
2237 AND mcacd.organization_id = msi.organization_id
2238 AND msi.costing_enabled_flag = 'N'
2239 AND mcacd.actual_cost <> 0
2240 /* AND NOT EXISTS (
2241 SELECT null
2242 FROM mtl_actual_cost_subelement macs
2243 WHERE macs.transaction_id =
2244 mcacd.transaction_id
2245 AND macs.organization_id =
2246 mcacd.organization_id
2247 AND macs.cost_element_id =
2248 mcacd.cost_element_id
2249 AND macs.level_type = mcacd.level_type
2250 )*/
2251 AND temp.transaction_id(+) = mcacd.transaction_id
2252 AND temp.organization_id(+) = mcacd.organization_id
2253 AND temp.cost_element_id(+) = mcacd.cost_element_id
2254 AND temp.level_type(+) = mcacd.level_type
2255 GROUP BY mcacd.transaction_id,
2256 mcacd.cost_element_id;
2257
2258 -- bug#1036498 Changed below cursor . If sending org is std (proj enabled , cost
2259 -- collection not enabled) then need to collect matl cost for it. This will
2260 -- be done when cost collector is run on the receiving org.
2261
2262 -- std org --> avg org
2263 -- PJ enabled PJ enabled
2264 -- cost collection disabled cost collection disabled
2265 -- from Project P1 to project P2
2266
2267 -- the change made in this cursor is that joining to CQL is removed
2268 -- since for std org. there is no data in CQL.
2269
2270 -- Cursor changed for Alcatel Enhancements. Both Internal Order Issue
2271 -- to Expense and Receipt are cost collected.
2272 /* Cursor for gathering Transfer Side Locator Project Costs in Xfer Txns */
2273 /* Like Subinventory Xfer or Direct IO Xfer where TO_PROJECT_ID is populated */
2274 /* the cursor c_sel_tomoh has been put in to gather MOH absorption costs on the
2275 receiving side.SO the following cursor will be made to exclude those cost */
2276
2277 CURSOR c_sel_toprj_txn IS
2278 SELECT p_inv_txn_source_literal transaction_source,
2279 l_batch batch_name,
2280 l_exp_end_date expenditure_ending_date,
2281 NULL employee_number,
2282 decode(p_transaction_action_id,
2283 3, l_xfer_organization_name,
2284 l_organization_name) organization_name,
2285 p_transaction_date expenditure_item_date,
2286 l_to_project_number project_number,
2287 l_to_task_number task_number,
2288 decode(sign(p_primary_quantity),1, cceet.EXPENDITURE_TYPE_OUT,
2289 cceet.EXPENDITURE_TYPE_IN) expenditure_type,
2290 decode(mcacd.cost_element_id,2,0, decode(mcacd.cost_element_id,5,0,
2291 (-1) * p_primary_quantity)) quantity,
2292 decode(mcacd.cost_element_id,2,0,
2293 decode(mcacd.cost_element_id,5,0,
2294 (-1) * sum(mcacd.ACTUAL_COST)*p_primary_quantity)) raw_cost,
2295 p_item_description expenditure_comment,
2296 to_char(p_transfer_transaction_id)
2297 orig_transaction_reference,
2298 decode(mcacd.cost_element_id,2,0,
2299 decode(mcacd.cost_element_id,5,0,sum(mcacd.ACTUAL_COST)))
2300 raw_cost_rate,
2301 'Y' unmatched_negative_txn_flag,
2302 -999999 dr_code_combination_id,
2303 -999999 cr_code_combination_id,
2304 NULL cdl_system_reference1,
2305 NULL cdl_system_reference2,
2306 NULL cdl_system_reference3,
2307 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2308 l_to_proj_org_id org_id,
2309 (-1)*((sum(mcacd.ACTUAL_COST)*p_primary_quantity)-
2310 (NVL(sum(macs.actual_cost)*p_primary_quantity,0)))
2311 burdened_cost,
2312 (sum(mcacd.ACTUAL_COST)-
2313 (NVL(sum(macs.actual_cost),0))) burdened_cost_rate,
2314 decode(mcacd.cost_element_id,2, p_bur_syslink_literal,
2315 decode(mcacd.cost_element_id,3, p_wip_syslink_literal,
2316 decode(mcacd.cost_element_id,4, p_wip_syslink_literal,
2317 decode(mcacd.cost_element_id,5, p_bur_syslink_literal,
2318 p_inv_syslink_literal)))) system_linkage,
2319 'P' transaction_status_code,
2320 mcacd.cost_element_id cost_element_id,
2321 decode(p_transaction_action_id,
2322 3, l_xfer_currency_code,
2323 p_denom_currency_code) denom_currency_code
2324 FROM mtl_cst_actual_cost_details mcacd,
2325 cst_cost_elem_exp_types cceet,
2326 mtl_actual_cost_subelement macs
2327 WHERE mcacd.transaction_id = decode(p_transaction_action_id,
2328 3, p_transfer_transaction_id ,
2329 p_transaction_id)
2330 AND mcacd.organization_id = decode(p_transaction_action_id,
2331 3, p_transfer_organization_id,
2332 p_organization_id)
2333 AND cceet.cost_element_id = mcacd.cost_element_id
2334 AND mcacd.actual_cost <> 0
2335 AND ((l_primary_cost_method_snd = 1)
2336 OR
2337 EXISTS
2338 ( SELECT 'X' from cst_quantity_layers cql
2339 where mcacd.layer_id = cql.layer_id
2340 AND cql.organization_id = mcacd.organization_id
2341 AND cql.inventory_item_id = p_inventory_item_id
2342 AND cql.cost_group_id = nvl(p_transfer_cost_group_id,1)
2343 )
2344 )
2345 AND macs.transaction_id(+) = mcacd.transaction_id
2346 AND macs.organization_id(+) = mcacd.organization_id
2347 AND macs.cost_element_id(+) = mcacd.cost_element_id
2348 AND macs.level_type(+) = mcacd.level_type
2349 GROUP BY mcacd.cost_element_id,
2350 cceet.expenditure_type_in,
2351 cceet.expenditure_type_out;
2352
2353 /* CURSOR for source_side projects in txns like Misc Proj, WIP Comp iss/Rec */
2354 /* For Misc Txn, if exp_type is NULL then default associations are used. */
2355 CURSOR c_sel_src_txn IS
2356 SELECT decode(p_type_class,1,p_cap_txn_source_literal,
2357 p_inv_txn_source_literal) transaction_source,
2358 l_batch batch_name,
2359 l_exp_end_date expenditure_ending_date,
2360 NULL employee_number,
2361 l_organization_name organization_name,
2362 p_transaction_date expenditure_item_date,
2363 l_source_project_number project_number,
2364 l_source_task_number task_number,
2365 decode(mcacd.cost_element_id,2,0,
2366 decode(mcacd.cost_element_id,5,0,(-1) * p_primary_quantity)) quantity,
2367
2368 decode(mcacd.cost_element_id,2,0,
2369 decode(mcacd.cost_element_id,5,0,
2370 (-1) * sum(mcacd.ACTUAL_COST) * p_primary_quantity)) raw_cost,
2371
2372 p_item_description expenditure_comment,
2373 to_char(p_transaction_id) orig_transaction_reference,
2374
2375 decode(mcacd.cost_element_id,2,0,
2376 decode(mcacd.cost_element_id,5,0,sum(mcacd.ACTUAL_COST))) raw_cost_rate,
2377
2378 'Y' unmatched_negative_txn_flag,
2379 -999999 dr_code_combination_id,
2380 -999999 cr_code_combination_id,
2381 NULL cdl_system_reference1,
2382 NULL cdl_system_reference2,
2383 NULL cdl_system_reference3,
2384 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2385 l_source_proj_org_id org_id,
2386 (-1) * sum(mcacd.ACTUAL_COST)*p_primary_quantity burdened_cost,
2387 sum(mcacd.ACTUAL_COST) burdened_cost_rate,
2388
2389 decode(mcacd.cost_element_id,2, p_bur_syslink_literal,
2390 decode(mcacd.cost_element_id,3, p_wip_syslink_literal,
2391 decode(mcacd.cost_element_id,4, p_wip_syslink_literal,
2392 decode(mcacd.cost_element_id,5, p_bur_syslink_literal,
2393 p_inv_syslink_literal)))) system_linkage,
2394
2395 'P' transaction_status_code,
2396 mcacd.cost_element_id cost_element_id,
2397 p_denom_currency_code denom_currency_code
2398 FROM mtl_cst_actual_cost_details mcacd,
2399 cst_cg_item_costs_view ccicv
2400 WHERE mcacd.transaction_id = p_transaction_id
2401 AND mcacd.organization_id = p_organization_id
2402 AND mcacd.inventory_item_id = p_inventory_item_id
2403 AND mcacd.actual_cost <> 0
2404 AND mcacd.layer_id = decode(p_primary_cost_method,
2405 1, -1, ccicv.layer_id) --PJMSTD
2406 AND NOT EXISTS (
2407 SELECT null
2408 FROM mtl_actual_cost_subelement macs
2409 WHERE macs.transaction_id =
2410 mcacd.transaction_id
2411 AND macs.organization_id =
2412 mcacd.organization_id
2413 AND macs.cost_element_id =
2414 mcacd.cost_element_id
2415 AND macs.level_type = mcacd.level_type )
2416 AND ccicv.organization_id = p_organization_id
2417 AND ccicv.inventory_item_id = p_inventory_item_id
2418 AND ccicv.cost_group_id = decode(p_primary_cost_method,
2419 1,1, p_cost_group_id) --PJMSTD
2420 GROUP BY mcacd.transaction_id,
2421 mcacd.cost_element_id;
2422
2423 -- borrow / payback
2424 CURSOR c_sel_bp_txn IS
2425 SELECT p_inv_txn_source_literal transaction_source,
2426 l_batch batch_name,
2427 l_exp_end_date expenditure_ending_date,
2428 NULL employee_number,
2429 l_organization_name organization_name,
2430 p_transaction_date expenditure_item_date,
2431 l_project_number project_number,
2432 l_task_number task_number,
2433 decode(sign(p_primary_quantity),1, cceet.EXPENDITURE_TYPE_OUT,
2434 cceet.EXPENDITURE_TYPE_IN) expenditure_type,
2435 -- bug 923134
2436 decode(mcacd.cost_element_id,
2437 2,0,
2438 5,0,p_primary_quantity) quantity,
2439
2440 decode(mcacd.cost_element_id,
2441 2,0,
2442 5,0,
2443 sum(mcacd.payback_variance_amount)* abs(p_primary_quantity))
2444 raw_cost,
2445 p_item_description expenditure_comment,
2446 to_char(p_transaction_id) orig_transaction_reference,
2447
2448 decode(mcacd.cost_element_id,
2449 2,0,
2450 5,0,
2451 sum(mcacd.payback_variance_amount)) raw_cost_rate,
2452 'Y' unmatched_negative_txn_flag,
2453 -999999 dr_code_combination_id,
2454 -999999 cr_code_combination_id,
2455 NULL cdl_system_reference1,
2456 NULL cdl_system_reference2,
2457 NULL cdl_system_reference3,
2458 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2459 l_proj_org_id org_id,
2460 sum(mcacd.payback_variance_amount)* abs(p_primary_quantity)
2461 burdened_cost,
2462 sum(mcacd.payback_variance_amount) burdened_cost_rate,
2463
2464 decode(mcacd.cost_element_id,2, p_bur_syslink_literal,
2465 decode(mcacd.cost_element_id,3, p_wip_syslink_literal,
2466 decode(mcacd.cost_element_id,4, p_wip_syslink_literal,
2467 decode(mcacd.cost_element_id,5, p_bur_syslink_literal,
2468 p_inv_syslink_literal)))) system_linkage,
2469
2470 'P' transaction_status_code ,
2471 mcacd.cost_element_id cost_element_id,
2472 p_denom_currency_code denom_currency_code
2473 FROM mtl_cst_actual_cost_details mcacd,
2474 cst_cost_elem_exp_types cceet,
2475 cst_cg_item_costs_view ccicv
2476 WHERE mcacd.transaction_id = p_transaction_id
2477 AND mcacd.organization_id = p_organization_id
2478 AND mcacd.inventory_item_id = p_inventory_item_id
2479 AND mcacd.payback_variance_amount <> 0
2480 AND mcacd.layer_id = decode(p_primary_cost_method,
2481 1, -1, ccicv.layer_id) --PJMSTD
2482 AND cceet.cost_element_id = mcacd.cost_element_id
2483 AND ccicv.organization_id = p_organization_id
2484 AND ccicv.inventory_item_id = p_inventory_item_id
2485 AND ccicv.cost_group_id = decode(p_primary_cost_method,
2486 1,1, p_cost_group_id) --PJMSTD
2487 GROUP BY mcacd.transaction_id,
2488 mcacd.cost_element_id,
2489 cceet.expenditure_type_in,
2490 cceet.expenditure_type_out;
2491
2492
2493 -- borrow /payback end
2494
2495 ----------------------------------------------------------------------------
2496 -- PJMSTD
2497 -- This Cursor is for PO and IO Organization of Standard Cost Organizations
2498 -- The PPV is passed to project under Inventory system linkage (Material)
2499 -- Need to see how this will work for IO transactions
2500 -- For IO MMT.Variance_amount will be NOT NULL depending on FOB Point
2501 ----------------------------------------------------------------------------
2502
2503 CURSOR c_sel_ppv IS
2504 SELECT decode(p_type_class,1,
2505 p_cap_txn_source_literal,
2506 p_inv_txn_source_literal) transaction_source,
2507 l_batch batch_name,
2508 l_exp_end_date expenditure_ending_date,
2509 NULL employee_number,
2510 decode(sign(p_primary_quantity),-1,
2511 decode(p_transaction_action_id,
2512 1, l_organization_name,
2513 29, l_organization_name, l_xfer_organization_name),
2514 l_organization_name) organization_name,
2515 p_transaction_date expenditure_item_date,
2516 decode(sign(p_primary_quantity),-1,
2517 decode(p_transaction_action_id,
2518 1, l_project_number,
2519 29, l_project_number, l_to_project_number),
2520 l_project_number) project_number,
2521 decode(sign(p_primary_quantity),-1,
2522 decode(p_transaction_action_id,
2523 1, l_task_number,
2524 29, l_task_number, l_to_task_number),
2525 l_task_number) task_number,
2526 nvl(ppp.ppv_expenditure_type, pop.ppv_expenditure_type) expenditure_type,
2527 decode(sign(p_primary_quantity),-1,
2528 decode(p_transaction_action_id,
2529 1, p_primary_quantity,
2530 29, p_primary_quantity, (-1)*p_primary_quantity),
2531 p_primary_quantity) quantity,
2532 mmt.variance_amount raw_cost,
2533 p_item_description expenditure_comment,
2534 decode(sign(p_primary_quantity),-1,
2535 decode(p_transaction_action_id,
2536 1, to_char(p_transaction_id),
2537 29, to_char(p_transaction_id),
2538 21, to_char(p_transaction_id),
2539 to_char(p_transfer_transaction_id)),
2540 to_char(p_transaction_id)) orig_transaction_reference,
2541 decode(sign(p_primary_quantity),-1,
2542 decode(p_transaction_action_id,
2543 1, mmt.variance_amount/p_primary_quantity,
2544 29, mmt.variance_amount/p_primary_quantity,
2545 (-1)*mmt.variance_amount/p_primary_quantity),
2546 mmt.variance_amount/p_primary_quantity) raw_cost_rate,
2547 'Y' unmatched_negative_txn_flag,
2548 -999999 dr_code_combination_id,
2549 -999999 cr_code_combination_id,
2550 NULL cdl_system_reference1,
2551 NULL cdl_system_reference2,
2552 NULL cdl_system_reference3,
2553 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
2554 l_proj_org_id org_id,
2555 mmt.variance_amount burdened_cost,
2556 decode(sign(p_primary_quantity),-1,
2557 decode(p_transaction_action_id,
2558 1, mmt.variance_amount/p_primary_quantity,
2559 29, mmt.variance_amount/p_primary_quantity,
2560 (-1)* mmt.variance_amount/p_primary_quantity),
2561 mmt.variance_amount/p_primary_quantity) burdened_cost_rate,
2562 p_inv_syslink_literal system_linkage,
2563 'P' transaction_status_code ,
2564 NULL cost_element_id,
2565 p_denom_currency_code denom_currency_code
2566 FROM mtl_material_transactions mmt,
2567 pjm_project_parameters ppp,
2568 pjm_org_parameters pop
2569 WHERE mmt.transaction_id = decode(ppv_txfr_flag,1, p_transfer_transaction_id,
2570 p_transaction_id)
2571 AND mmt.organization_id = decode(ppv_txfr_flag,1,p_transfer_organization_id,
2572 p_organization_id)
2573 AND NVL(mmt.variance_amount,0) <> 0
2574 AND pop.organization_id = decode(sign(p_primary_quantity),-1,
2575 decode( p_transaction_action_id,
2576 1, p_organization_id,
2577 29, p_organization_id,
2578 p_transfer_organization_id),
2579 p_organization_id)
2580 AND ppp.organization_id (+) = pop.organization_id
2581 AND ppp.project_id (+) = decode(sign(p_primary_quantity),-1,
2582 decode( p_transaction_action_id,
2583 1, p_project_id,
2584 29, p_project_id, p_to_project_id),
2585 p_project_id);
2586 l_debug VARCHAR2(80);
2587
2588 BEGIN
2589 -- initialize local variables
2590 l_err_num := 0;
2591 l_err_code := '';
2592 l_err_msg := '';
2593 l_rownum := 0;
2594 l_fob_point := 0;
2595 l_earn_moh := 0;
2596 l_earn_tomoh := 0;
2597 l_stmt_num := 1;
2598 ppv_txfr_flag := 0;
2599 l_costed_flag := null;
2600
2601
2602 /* bug 3978501 Set the variables to 0 and 1 accordingly */
2603 l_no_row_c_sel_prj := 0;
2604 l_no_row_c_sel_toprj := 0;
2605 l_no_ppv := 1;
2606
2607
2608 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
2609 if (l_debug = 'Y') then
2610 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_process_txn_mmt ...');
2611 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Transaction ID: '||to_char(p_transaction_id));
2612 end if;
2613
2614
2615
2616 l_stmt_num := 05;
2617
2618 -- bug #1036498, need to find out the costing method of the from org.
2619 -- bug 2095581, need pm_cost_collection_enabled flag for sending org.
2620 -- bug 3150050 staging Txfrs
2621 IF (p_transaction_action_id IN (2,3,12,28) ) THEN
2622 SELECT primary_cost_method, decode(pm_cost_collection_enabled, 1, 1, 0)
2623 INTO l_primary_cost_method_snd, l_cost_collection_enabled_snd
2624 FROM mtl_parameters
2625 WHERE organization_id = p_transfer_organization_id ;
2626 END IF;
2627
2628 -- Initialize the batch name as CC followed by group_id
2629
2630 l_stmt_num := 10;
2631 -- Modified for Bug#2218654
2632 -- Changed for Bug #2260708. PA import fails when you use a 15 character
2633 -- batch name. Instead I am using the last 8 characters of the group id
2634 -- so the batch name remains less than 10 chars. The likelihood of two
2635 -- batch numbers being the same is very low.
2636
2637 SELECT 'CC'|| substr( replace( lpad(
2638 to_char(p_Group_Id,'9999999999999'),14,'0') ,' ','0'),-8)
2639 INTO l_batch
2640 FROM DUAL;
2641
2642
2643
2644 -- Initialize local variable to be used in a decode later in the code,
2645 -- if the transaction is of Misc Family
2646
2647 l_stmt_num := 15;
2648 IF p_transaction_action_id in (1,27)
2649 AND p_transaction_source_type_id in (3,13,6) THEN
2650 l_txn_of_misc_family := 1;
2651 ELSE
2652 l_txn_of_misc_family := 0;
2653 END IF;
2654
2655 -- get exp ending date for the current transaction's transaction_date
2656
2657 l_stmt_num := 16;
2658 select org_information3
2659 into l_operating_unit
2660 from hr_organization_information
2661 where organization_id = p_organization_id
2662 and org_information_context ='Accounting Information';
2663
2664 l_stmt_num :=17;
2665 begin
2666 mo_global.set_policy_context('S',l_operating_unit);
2667 end;
2668
2669 l_stmt_num := 20;
2670
2671 l_exp_end_date := pa_utils.GetWeekEnding(p_transaction_date);
2672
2673 IF l_exp_end_date is NULL THEN
2674 RAISE CST_FAILED_GET_EXPENDDATE;
2675 END IF;
2676
2677 ----------------------------------------------------------------------
2678 -- bug 1036822
2679 -- get default project info;
2680 l_stmt_num := 20;
2681 -- bug 1291409, max is added to take care customer who
2682 -- does not have pjm installed but still wants to run cost collector
2683 ----------------------------------------------------------------------
2684
2685 l_stmt_num := 25;
2686
2687 SELECT max(pop.common_project_id)
2688 INTO l_default_project
2689 FROM pjm_org_parameters pop,
2690 mtl_material_transactions mmt
2691 WHERE pop.organization_id = mmt.organization_id
2692 AND mmt.transaction_id = p_transaction_id;
2693
2694 ----------------------------------------------------------------------
2695 -- assign transaction org as expenditure org
2696 -- Bug: 1350945 Use hr_organization_units instead of
2697 -- hr_all_organization_units. hou is a view on top of
2698 -- haou and haou_tl (haou is a multilingual table, it shouldnt
2699 -- even have the translated column "name" as an attribute)
2700 ----------------------------------------------------------------------
2701
2702 l_stmt_num := 30;
2703 SELECT hou.name
2704 INTO l_organization_name
2705 FROM hr_organization_units hou
2706 WHERE hou.organization_id = p_exp_org_id;
2707
2708 --bug2623664
2709
2710 l_stmt_num := 31;
2711 l_recv_iss_organization_name := null ;
2712 IF ( (p_transaction_action_id = 27 OR p_transaction_action_id = 1 OR
2713 p_transaction_action_id = 6)
2714 AND p_type_class = 1 ) THEN
2715 SELECT haou.name
2716 INTO l_recv_iss_organization_name
2717 FROM hr_all_organization_units haou
2718 WHERE haou.organization_id = p_organization_id;
2719 END IF;
2720
2721
2722 /* For Dir IO Xfer with TO_PROJECT_ID Populated */
2723 l_stmt_num := 35;
2724 IF (p_transfer_organization_id IS NOT NULL
2725 AND p_transaction_action_id = 3 AND p_to_project_id IS NOT NULL) THEN
2726 SELECT hou.name
2727 INTO l_xfer_organization_name
2728 FROM hr_organization_units hou
2729 WHERE hou.organization_id = p_transfer_organization_id;
2730
2731 l_stmt_num := 40;
2732
2733 SELECT currency_code
2734 INTO l_xfer_currency_code
2735 FROM cst_organization_definitions cod
2736 WHERE cod.organization_id = p_transfer_organization_id;
2737
2738 END IF;
2739
2740 ----------------------------------------------------------------------
2741 -- assign multi_org_id
2742
2743 -- Get Proj/Task Numbers for Proj/Task ids.
2744 -- This is added because between the time the transaction was done
2745 -- and cost collection was run the Project/Task could have become
2746 -- Obsolete. Therefore, we need to catch if there is an exception.
2747
2748 -- ** Query from PJM_PROJECTS_V and PJM_TASKS_V
2749 --instead of MTL_PROJECT_V bnd MTL_TASK_V because
2750 -- MTL_PROJECT_V shows only those projects that have been associated
2751 -- with a CG (in Project Parameters). However, for Capital Txns
2752 -- we need all valid projects irrespective of whether they are
2753 -- set up in Project Parameters (PJM_PROJECT_PARAMETERS) or not.
2754 -- Refer to Bug# 571127 **
2755 ----------------------------------------------------------------------
2756
2757 ----------------------------------------------------------------------
2758 -- MOAC Changes for R12:
2759 -- References to PJM_PROJECTS_V and PJM_TASKS_V has been removed and
2760 -- their base table pa_projects_all and pa_tasks are used instead.
2761 ----------------------------------------------------------------------
2762
2763 BEGIN
2764 l_stmt_num := 45;
2765 IF p_project_id is NOT NULL then
2766 SELECT ppa.org_id,
2767 ppa.segment1 -- project number
2768 INTO l_proj_org_id,
2769 l_project_number
2770 FROM pa_projects_all ppa
2771 WHERE ppa.project_id = p_project_id;
2772 /* l_stmt_num := 50;
2773 SELECT segment1 -- project number
2774 INTO l_project_number
2775 FROM pa_projects_all
2776 WHERE project_id = p_project_id; */
2777 l_stmt_num := 55;
2778 SELECT task_number
2779 INTO l_task_number
2780 FROM pa_tasks
2781 WHERE project_id = p_project_id
2782 AND task_id = p_task_id;
2783 END IF;
2784
2785 l_stmt_num := 60;
2786
2787 IF p_to_project_id is NOT NULL then
2788 SELECT ppa.org_id,
2789 ppa.segment1 -- project number
2790 INTO l_to_proj_org_id,
2791 l_to_project_number
2792 FROM pa_projects_all ppa
2793 WHERE ppa.project_id = p_to_project_id;
2794 /* l_stmt_num := 65;
2795 SELECT segment1 -- project number
2796 INTO l_to_project_number
2797 FROM pa_projects_all
2798 WHERE project_id = p_to_project_id; */
2799 l_stmt_num := 70;
2800 SELECT task_number
2801 INTO l_to_task_number
2802 FROM pa_tasks
2803 WHERE project_id = p_to_project_id
2804 AND task_id = p_to_task_id;
2805 END IF;
2806
2807 l_stmt_num := 75;
2808 IF p_source_project_id is NOT NULL then
2809 SELECT ppa.org_id,
2810 segment1
2811 INTO l_source_proj_org_id,
2812 l_source_project_number
2813 FROM pa_projects_all ppa
2814 WHERE ppa.project_id = p_source_project_id;
2815 /* l_stmt_num := 80;
2816 SELECT segment1 -- project number
2817 INTO l_source_project_number
2818 FROM pa_projects_all
2819 WHERE project_id = p_source_project_id; */
2820 l_stmt_num := 85;
2821 SELECT task_number
2822 INTO l_source_task_number
2823 FROM pa_tasks
2824 WHERE project_id = p_source_project_id
2825 AND task_id = p_source_task_id;
2826 END IF;
2827 EXCEPTION
2828 WHEN OTHERS THEN
2829 l_err_msg := SUBSTR(SQLERRM,1,200);
2830 RAISE CST_FAILED_PROJTSK_VALID;
2831 END;
2832
2833 -- get FOB POINT for Intransit Transactions
2834
2835 l_stmt_num := 90;
2836
2837 -- Modified for fob stamping project
2838 IF (p_transfer_organization_id IS NOT NULL) THEN
2839 IF p_transaction_action_id = 21 THEN /* Intransit Shipment */
2840 SELECT nvl(MMT.fob_point, MSNV.fob_point) INTO l_fob_point
2841 FROM mtl_shipping_network_view MSNV, mtl_material_transactions MMT
2842 WHERE MSNV.from_organization_id = p_organization_id
2843 AND MSNV.to_organization_id = p_transfer_organization_id
2844 AND MMT.transaction_id = p_transaction_id;
2845 ELSIF p_transaction_action_id = 12 THEN /* Intransit Receipt */
2846 SELECT nvl(MMT.fob_point, MSNV.fob_point) INTO l_fob_point
2847 FROM mtl_shipping_network_view MSNV, mtl_material_transactions MMT
2848 WHERE MSNV.from_organization_id = p_transfer_organization_id
2849 AND MSNV.to_organization_id = p_organization_id
2850 AND MMT.transaction_id = p_transaction_id;
2851 END IF;
2852
2853 -- PJMSTD
2854
2855 l_stmt_num := 95;
2856
2857 CST_Utility_Pub.GET_STD_CG_ACCT_FLAG
2858 (p_api_version => 1.0,
2859 p_organization_id => p_transfer_organization_id,
2860 x_cg_acct_flag => l_std_cg_acct_snd,
2861 x_return_status => l_return_status,
2862 x_msg_count => l_msg_count,
2863 x_msg_data => l_msg_data );
2864
2865 IF (l_return_status = FND_API.G_RET_STS_ERROR OR
2866 l_return_status = FND_API.G_RET_STS_UNEXP_ERROR)
2867
2868 THEN
2869
2870 RAISE CST_FAILED_STD_CG_FLAG;
2871
2872 END IF;
2873
2874
2875 END IF;
2876
2877 -- get the schedule close date from acct_periods
2878
2879 /* Commented for bug 6266553
2880 l_stmt_num := 100;
2881 SELECT schedule_close_date
2882 INTO l_gl_date
2883 FROM org_acct_periods oac
2884 WHERE oac.organization_id = p_organization_id
2885 AND oac.acct_period_id = p_acct_period_id;*/
2886
2887 ----------------------------------------------------------------------
2888 --This Select Statement is added to ascertain whether "This
2889 --Level MOH" is earned by the transaction. If it is not
2890 --earned then there is no need to go through CURSOR
2891 --c_sel_moh_txn. It is necessary to
2892 --bypass the cursor if the transaction did not
2893 --earn "This Level MOH" (say no MOH subelements were
2894 --defaulted or defined for the item) because the Cursor then
2895 --raises the Exception NO_ROWS_TO_INSERT and abandons the txn.
2896 ----------------------------------------------------------------------
2897
2898 l_stmt_num := 105;
2899
2900 /* Bug #1944099. Only this level MOH costs are collected. */
2901 SELECT NVL(MAX(macs.transaction_id),-99)
2902 INTO l_earn_moh
2903 FROM mtl_actual_cost_subelement macs
2904 WHERE macs.transaction_id = p_transaction_id
2905 AND macs.organization_id = p_organization_id
2906 AND macs.actual_cost <> 0
2907 AND macs.level_type = 1
2908 AND macs.cost_element_id = 2;
2909
2910 /* If it is a direct interorg then check if the c_sel_tomoh has
2911 anything to insert */
2912 /* bug 4655264. Need to make sure that p_to_project_id is not nULL before transferring */
2913 l_stmt_num := 106;
2914
2915 If (p_transaction_action_id = 3 AND p_to_project_id is not NULL) then
2916 select NVL(MAX(macs.transaction_id),-99)
2917 into l_earn_tomoh
2918 from mtl_actual_cost_subelement macs
2919 WHERE macs.transaction_id = p_transfer_transaction_id
2920 AND macs.organization_id = p_transfer_organization_id
2921 AND macs.actual_cost <> 0
2922 AND macs.level_type = 1
2923 AND macs.cost_element_id = 2;
2924
2925 else
2926 l_earn_tomoh := -99;
2927
2928 end if;
2929
2930
2931 l_stmt_num := 110;
2932 SELECT transaction_type_id
2933 INTO l_txn_type
2934 FROM mtl_material_transactions
2935 WHERE transaction_id = p_transaction_id;
2936
2937 l_stmt_num := 120;
2938
2939 IF ( p_primary_cost_method = 1
2940 AND p_type_class = 1
2941 AND p_std_cg_acct <> 1 --PJMSTD
2942 )
2943 THEN
2944
2945 ----------------------------------------------------------------
2946 /* START:CC ALL ELE AS PER FROZEN COST IN STD COST ORG */
2947
2948 -- All Transactions in a Standard Costing Organization with
2949 -- transaction type having its type_class set to 1 implying that
2950 -- it refers to a Capital Project.
2951
2952 -- If no expenditure_type is specified at the time of txn
2953 -- CC will report elemental costs by deriving the default
2954 -- CE-ET associations defined in Costing SetUp.
2955
2956 -- Check is added for std_cg_acct so that only std orgs that
2957 -- are not CG Acct enabled will use this cursor
2958 ----------------------------------------------------------------
2959
2960 l_rownum := 0;
2961
2962 l_stmt_num := 125;
2963
2964 if (l_debug = 'Y') then
2965 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Processing Project Miscellaneous Transactions ...');
2966 end if;
2967
2968 FOR c_rec1 IN c_sel_std_misc LOOP
2969
2970 ----------------------------------------------------------
2971 -- bug 888190
2972 -- the condition is for capital project,
2973 -- if expenditure type is user entered, get it from
2974 -- p_expenditure_type otherwise derived it
2975 -- from the system using cceet.
2976 -- 0 System derived
2977 -- 1 User Entered
2978 ----------------------------------------------------------
2979 l_stmt_num := 130;
2980
2981 IF (p_user_def_exp_type = 1) THEN
2982
2983 IF (p_expenditure_type is null) THEN
2984
2985 RAISE CST_FAILED_GET_EXP_TYPE;
2986
2987 ELSE
2988
2989 l_exp_type := p_expenditure_type;
2990
2991 END IF;
2992
2993 ELSE -- system derived
2994
2995 l_stmt_num := 135;
2996
2997 SELECT
2998 DECODE(sign(p_primary_quantity),1,
2999 cceet.EXPENDITURE_TYPE_OUT,
3000 cceet.EXPENDITURE_TYPE_IN)
3001 INTO l_exp_type
3002 FROM cst_cost_elem_exp_types cceet
3003 WHERE cceet.cost_element_id = c_rec1.cost_element_id;
3004
3005 END IF;
3006
3007 l_rownum := l_rownum + 1;
3008
3009 l_stmt_num := 140;
3010
3011 pm_insert_pti_pvt
3012 (p_transaction_source =>
3013 c_rec1.transaction_source,
3014 p_batch_name =>c_rec1.batch_name,
3015 p_expenditure_ending_date =>
3016 c_rec1.expenditure_ending_date,
3017 p_employee_number =>c_rec1.employee_number,
3018 p_organization_name =>
3019 c_rec1.organization_name,
3020 p_expenditure_item_date =>
3021 c_rec1.expenditure_item_date,
3022 p_project_number =>c_rec1.project_number,
3023 p_task_number =>c_rec1.task_number,
3024 p_expenditure_type =>l_exp_type,
3025 p_pa_quantity =>c_rec1.quantity,
3026 p_raw_cost =>c_rec1.raw_cost,
3027 p_expenditure_comment =>
3028 c_rec1.expenditure_comment,
3029 p_orig_transaction_reference =>
3030 c_rec1.orig_transaction_reference,
3031 p_raw_cost_rate =>c_rec1.raw_cost_rate,
3032 p_unmatched_negative_txn_flag=>
3033 c_rec1.unmatched_negative_txn_flag,
3034 p_gl_date =>c_rec1.gl_date,
3035 p_org_id =>c_rec1.org_id,
3036 p_burdened_cost =>c_rec1.burdened_cost,
3037 p_burdened_cost_rate =>
3038 c_rec1.burdened_cost_rate,
3039 p_system_linkage =>c_rec1.system_linkage,
3040 p_transaction_status_code =>
3041 c_rec1.transaction_status_code,
3042 p_denom_currency_code =>
3043 c_rec1.denom_currency_code,
3044 p_transaction_id =>p_transaction_id,
3045
3046 p_transaction_action_id =>p_transaction_action_id,
3047 p_transaction_source_type_id =>
3048 p_transaction_source_type_id,
3049 p_organization_id =>p_organization_id,
3050 p_inventory_item_id =>p_inventory_item_id,
3051 p_cost_element_id =>c_rec1.cost_element_id,
3052 p_resource_id =>NULL,
3053 p_source_flag =>1,
3054 p_variance_flag =>-1,
3055 p_primary_quantity =>p_primary_quantity ,
3056 p_transfer_organization_id =>
3057 p_transfer_organization_id,
3058 p_fob_point =>l_fob_point,
3059 p_wip_entity_id =>NULL,
3060 p_basis_resource =>NULL,
3061
3062 p_type_class =>p_type_class,
3063 p_project_id =>p_project_id,
3064 p_task_id =>p_task_id,
3065 p_transaction_date =>p_transaction_date,
3066 p_cost_group_id =>p_cost_group_id,
3067 p_transfer_cost_group_id =>
3068 p_transfer_cost_group_id,
3069 p_transaction_source_id =>
3070 p_transaction_source_id,
3071 p_to_project_id =>p_to_project_id,
3072 p_to_task_id =>p_to_task_id,
3073 p_source_project_id =>p_source_project_id,
3074 p_source_task_id =>p_source_task_id,
3075 p_transfer_transaction_id =>
3076 p_transfer_transaction_id,
3077 p_primary_cost_method =>p_primary_cost_method,
3078 p_acct_period_id =>p_acct_period_id,
3079 p_exp_org_id =>p_exp_org_id,
3080 p_distribution_account_id =>
3081 p_distribution_account_id,
3082 p_proj_job_ind =>p_proj_job_ind,
3083 p_first_matl_se_exp_type =>
3084 p_first_matl_se_exp_type,
3085 p_inv_txn_source_literal =>
3086 p_inv_txn_source_literal,
3087 p_cap_txn_source_literal =>
3088 p_cap_txn_source_literal,
3089 p_inv_syslink_literal =>p_inv_syslink_literal,
3090 p_bur_syslink_literal =>p_bur_syslink_literal,
3091 p_wip_syslink_literal =>p_wip_syslink_literal,
3092 p_user_def_exp_type =>p_user_def_exp_type,
3093 p_flow_schedule =>p_flow_schedule,
3094 p_si_asset_yes_no =>p_si_asset_yes_no,
3095 p_transfer_si_asset_yes_no =>
3096 p_transfer_si_asset_yes_no,
3097
3098 O_err_num =>l_err_num,
3099 O_err_code =>l_err_code,
3100 O_err_msg =>l_err_msg
3101 );
3102
3103 IF (l_err_num <> 0) THEN
3104
3105 RAISE CST_FAILED_INSERT_PTI;
3106
3107 END IF;
3108
3109 END LOOP;
3110
3111 IF l_rownum = 0 THEN
3112
3113 RAISE NO_ROWS_TO_INSERT;
3114
3115 END IF;
3116
3117
3118 /* END: CC ALL ELE AS PER FROZEN COST IN STD COST ORG */
3119
3120 ELSE
3121 /* START: CC ALL TXNS OF AN CGSTD + AVG COSTING ORG */
3122
3123
3124
3125 /*CC MO SE ET START*/
3126
3127 -- CASE 1: Those Assy Completion/Rtn Transactions involving an
3128 -- Issue / Rtn from/to a Sub that project costed as 'Y'
3129 -- which implies that this level MO is reported on a
3130 -- SE basis.
3131 --
3132 -- CASE 2: Direct or Intransit receipt transactions into an
3133 -- asset SI of the receiving Organization irrespective
3134 -- of type of SI the shipment transaction refers to,
3135 -- imply that this level MO is reported on a SE basis.
3136 --
3137 -- CASE 3: TXNS ARE: PO Delivery,adjustment,RTV
3138 --
3139 -- CASE 4: Consigned ownership transfer transactions
3140 --
3141 /*
3142 QUESTION: Should CASE 3 restrict itself to the asset items and asset SI,
3143 as MO is earned or unearned only on a PO family transaction involving an
3144 asset item and an asset SI
3145
3146 ADD INTERORG CONDITION if MO is to be earned only when receipt refers
3147 a asset sub-inventory and not if referring to an exp sub
3148 CONFIRMED BY JENNY that txns involving expense subs do not earn MO
3149
3150 For both the questions above, the decision is to not make any explicit
3151 check in the CC code, since the Cost processor would create rows in
3152 macs for records only when above stated conditions are satisfied.
3153 */
3154 IF (l_earn_moh <> -99) /* MOH was earned */
3155 AND (
3156 ( p_transaction_action_id in (31,32) /* CASE 1 */
3157 AND p_project_id is not null
3158 )
3159 OR p_transaction_action_id in (12,3) /* CASE 2 */
3160 OR p_transaction_source_type_id = 1 /* CASE 3 */
3161 OR p_transaction_action_id = 6 /* CASE 4 ownership transfer transaction */
3162 )
3163 THEN
3164
3165 l_rownum := 0;
3166
3167 l_stmt_num := 145;
3168
3169 if (l_debug = 'Y') then
3170 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting MOH costs ...');
3171 end if;
3172
3173 FOR c_rec2 IN c_sel_moh_txn LOOP
3174
3175 l_rownum := l_rownum + 1;
3176
3177 l_stmt_num := 150;
3178
3179 pm_insert_pti_pvt
3180 (p_transaction_source =>
3181 c_rec2.transaction_source,
3182 p_batch_name =>c_rec2.batch_name,
3183 p_expenditure_ending_date =>
3184 c_rec2.expenditure_ending_date,
3185 p_employee_number =>c_rec2.employee_number,
3186 p_organization_name =>
3187 c_rec2.organization_name,
3188 p_expenditure_item_date =>
3189 c_rec2.expenditure_item_date,
3190 p_project_number =>c_rec2.project_number,
3191 p_task_number =>c_rec2.task_number,
3192 p_expenditure_type =>c_rec2.expenditure_type,
3193 p_pa_quantity =>c_rec2.quantity,
3194 p_raw_cost =>c_rec2.raw_cost,
3195 p_expenditure_comment =>
3196 c_rec2.expenditure_comment,
3197 p_orig_transaction_reference =>
3198 c_rec2.orig_transaction_reference,
3199 p_raw_cost_rate =>c_rec2.raw_cost_rate,
3200 p_unmatched_negative_txn_flag=>
3201 c_rec2.unmatched_negative_txn_flag,
3202 p_gl_date =>c_rec2.gl_date,
3203 p_org_id =>c_rec2.org_id,
3204 p_burdened_cost =>c_rec2.burdened_cost,
3205 p_burdened_cost_rate =>
3206 c_rec2.burdened_cost_rate,
3207 p_system_linkage =>c_rec2.system_linkage,
3208 p_transaction_status_code =>
3209 c_rec2.transaction_status_code,
3210 p_denom_currency_code =>
3211 c_rec2.denom_currency_code,
3212 p_transaction_id =>p_transaction_id,
3213
3214 p_transaction_action_id =>p_transaction_action_id,
3215 p_transaction_source_type_id =>
3216 p_transaction_source_type_id,
3217 p_organization_id =>p_organization_id,
3218 p_inventory_item_id =>p_inventory_item_id,
3219 p_cost_element_id =>c_rec2.cost_element_id,
3220 p_resource_id =>c_rec2.resource_id,
3221 p_source_flag =>-1,
3222 p_variance_flag =>-1,
3223 p_primary_quantity =>p_primary_quantity ,
3224 p_transfer_organization_id =>
3225 p_transfer_organization_id,
3226 p_fob_point =>l_fob_point,
3227 p_wip_entity_id =>NULL,
3228 p_basis_resource =>NULL,
3229
3230 p_type_class =>p_type_class,
3231 p_project_id =>p_project_id,
3232 p_task_id =>p_task_id,
3233 p_transaction_date =>p_transaction_date,
3234 p_cost_group_id =>p_cost_group_id,
3235 p_transfer_cost_group_id =>
3236 p_transfer_cost_group_id,
3237 p_transaction_source_id =>
3238 p_transaction_source_id,
3239 p_to_project_id =>p_to_project_id,
3240 p_to_task_id =>p_to_task_id,
3241 p_source_project_id =>p_source_project_id,
3242 p_source_task_id =>p_source_task_id,
3243 p_transfer_transaction_id =>
3244 p_transfer_transaction_id,
3245 p_primary_cost_method =>p_primary_cost_method,
3246 p_acct_period_id =>p_acct_period_id,
3247 p_exp_org_id =>p_exp_org_id,
3248 p_distribution_account_id =>
3249 p_distribution_account_id,
3250 p_proj_job_ind =>p_proj_job_ind,
3251 p_first_matl_se_exp_type =>
3252 p_first_matl_se_exp_type,
3253 p_inv_txn_source_literal =>
3254 p_inv_txn_source_literal,
3255 p_cap_txn_source_literal =>
3256 p_cap_txn_source_literal,
3257 p_inv_syslink_literal =>p_inv_syslink_literal,
3258 p_bur_syslink_literal =>p_bur_syslink_literal,
3259 p_wip_syslink_literal =>p_wip_syslink_literal,
3260 p_user_def_exp_type =>p_user_def_exp_type,
3261 p_flow_schedule =>p_flow_schedule,
3262 p_si_asset_yes_no =>p_si_asset_yes_no,
3263 p_transfer_si_asset_yes_no =>
3264 p_transfer_si_asset_yes_no,
3265
3266 O_err_num =>l_err_num,
3267 O_err_code =>l_err_code,
3268 O_err_msg =>l_err_msg
3269 );
3270
3271 IF (l_err_num <> 0) THEN
3272
3273 RAISE CST_FAILED_INSERT_PTI;
3274
3275 END IF;
3276
3277 END LOOP;
3278
3279 IF l_rownum = 0 THEN
3280
3281 RAISE NO_ROWS_TO_INSERT;
3282
3283 END IF;
3284
3285 END IF; /*CC MO SE ET END*/
3286
3287 /* Insert Material Overhead absorption for the receiving side in a direct
3288 interorg transaction */
3289
3290 If (l_earn_tomoh <> -99 AND p_transaction_id <> -99 ) then
3291
3292 FND_FILE.PUT_LINE(FND_FILE.LOG,'Collecting the MOH absorption on the receiving side');
3293
3294 l_rownum := 0;
3295
3296 For c_rec9 in c_sel_tomoh LOOP
3297
3298 l_rownum := l_rownum + 1;
3299
3300 l_stmt_num := 151;
3301
3302
3303 /* changes to support the Blue print organizations */
3304
3305 /* get the org ID on the transfer Txn */
3306 select organization_id into l_org_id
3307 from mtl_material_transactions
3308 where transaction_id = c_rec9.orig_transaction_reference;
3309
3310 /* set the transaction source accordingly if the org is BP */
3311
3312 select NVL(pa_posting_flag,'N'),
3313 NVL(pa_autoaccounting_flag,'N')
3314 into l_blue_print_enabled_flag,
3315 l_autoaccounting_flag
3316 from pjm_org_parameters
3317 where organization_id = l_org_id ;
3318
3319 If l_blue_print_enabled_flag = 'Y' then
3320
3321 FND_FILE.PUT_LINE(FND_FILE.LOG,'Blue print org ' || l_org_id);
3322 If l_autoaccounting_flag = 'Y' then
3323
3324 /* BP and autoaccounting */
3325 Select pts1.transaction_source,
3326 pts1.transaction_source,
3327 pts1.transaction_source
3328 into l_transaction_source,
3329 l_inv_txn_src_literal,
3330 l_cap_inv_txn_src_literal
3331 From pa_transaction_sources pts1
3332 Where pts1.transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS';
3333 If (l_transaction_source is NULL) then
3334
3335 RAISE CST_FAILED_TXN_SRC;
3336
3337 end If;
3338 else
3339 /* BP and no autoaccounting */
3340 Select pts1.transaction_source,
3341 pts1.transaction_source,
3342 pts1.transaction_source
3343 into l_transaction_source,
3344 l_inv_txn_src_literal,
3345 l_cap_inv_txn_src_literal
3346 From pa_transaction_sources pts1
3347 Where pts1.transaction_source = 'PJM_CSTBP_INV_ACCOUNTS';
3348
3349 If (l_transaction_source is NULL ) then
3350
3351 RAISE CST_FAILED_TXN_SRC;
3352
3353 end If;
3354 end if; /* end of check for auto accounting */
3355
3356 ELSE /* non BP org */
3357
3358 SELECT pts1.transaction_source,
3359 pts1.transaction_source,
3360 pts2.transaction_source
3361 INTO l_inv_txn_src_literal,
3362 l_transaction_source,
3363 l_cap_inv_txn_src_literal
3364 FROM pa_transaction_sources pts1,
3365 pa_transaction_sources pts2
3366 WHERE pts1.transaction_source = 'Inventory'
3367 AND pts2.transaction_source = 'Inventory Misc';
3368
3369 END IF; /* check for BP org */
3370
3371 l_stmt_num := 152;
3372
3373 /* Now call insert routine to insert into interface */
3374
3375 pm_insert_pti_pvt
3376 (p_transaction_source =>
3377 l_transaction_source,
3378 p_batch_name =>c_rec9.batch_name,
3379 p_expenditure_ending_date =>
3380 c_rec9.expenditure_ending_date,
3381 p_employee_number =>c_rec9.employee_number,
3382 p_organization_name =>
3383 c_rec9.organization_name,
3384 p_expenditure_item_date =>
3385 c_rec9.expenditure_item_date,
3386 p_project_number =>c_rec9.project_number,
3387 p_task_number =>c_rec9.task_number,
3388 p_expenditure_type =>c_rec9.expenditure_type,
3389 p_pa_quantity =>c_rec9.quantity,
3390 p_raw_cost =>c_rec9.raw_cost,
3391 p_expenditure_comment =>
3392 c_rec9.expenditure_comment,
3393 p_orig_transaction_reference =>
3394 c_rec9.orig_transaction_reference,
3395 p_raw_cost_rate =>c_rec9.raw_cost_rate,
3396 p_unmatched_negative_txn_flag=>
3397 c_rec9.unmatched_negative_txn_flag,
3398 p_gl_date =>c_rec9.gl_date,
3399 p_org_id =>c_rec9.org_id,
3400 p_burdened_cost =>c_rec9.burdened_cost,
3401 p_burdened_cost_rate =>
3402 c_rec9.burdened_cost_rate,
3403 p_system_linkage =>c_rec9.system_linkage,
3404 p_transaction_status_code =>
3405 c_rec9.transaction_status_code,
3406 p_denom_currency_code =>
3407 c_rec9.denom_currency_code,
3408 p_transaction_id =>p_transaction_id,
3409 p_transaction_action_id =>p_transaction_action_id,
3410 p_transaction_source_type_id =>
3411 p_transaction_source_type_id,
3412 p_organization_id =>p_organization_id,
3413 p_inventory_item_id =>p_inventory_item_id,
3414 p_cost_element_id =>c_rec9.cost_element_id,
3415 p_resource_id =>c_rec9.resource_id,
3416 p_source_flag =>1,
3417 p_variance_flag =>-1,
3418 p_primary_quantity =>p_primary_quantity ,
3419 p_transfer_organization_id =>
3420 p_transfer_organization_id,
3421 p_fob_point =>l_fob_point,
3422 p_wip_entity_id =>NULL,
3423 p_basis_resource =>NULL,
3424 p_type_class =>p_type_class,
3425 p_project_id =>p_project_id,
3426 p_task_id =>p_task_id,
3427 p_transaction_date =>p_transaction_date,
3428 p_cost_group_id =>p_cost_group_id,
3429 p_transfer_cost_group_id =>
3430 p_transfer_cost_group_id,
3431 p_transaction_source_id =>
3432 p_transaction_source_id,
3433 p_to_project_id =>p_to_project_id,
3434 p_to_task_id =>p_to_task_id,
3435 p_source_project_id =>p_source_project_id,
3436 p_source_task_id =>p_source_task_id,
3437 p_transfer_transaction_id =>
3438 p_transfer_transaction_id,
3439 p_primary_cost_method =>p_primary_cost_method,
3440 p_acct_period_id =>p_acct_period_id,
3441 p_exp_org_id =>p_exp_org_id,
3442 p_distribution_account_id =>
3443 p_distribution_account_id,
3444 p_proj_job_ind =>p_proj_job_ind,
3445 p_first_matl_se_exp_type =>
3446 p_first_matl_se_exp_type,
3447 p_inv_txn_source_literal =>
3448 l_inv_txn_src_literal,
3449 p_cap_txn_source_literal =>
3450 l_cap_inv_txn_src_literal,
3451 p_inv_syslink_literal =>p_inv_syslink_literal,
3452 p_bur_syslink_literal =>p_bur_syslink_literal,
3453 p_wip_syslink_literal =>p_wip_syslink_literal,
3454 p_user_def_exp_type =>p_user_def_exp_type,
3455 p_flow_schedule =>p_flow_schedule,
3456 p_si_asset_yes_no =>p_si_asset_yes_no,
3457 p_transfer_si_asset_yes_no =>
3458 p_transfer_si_asset_yes_no,
3459
3460 O_err_num =>l_err_num,
3461 O_err_code =>l_err_code,
3462 O_err_msg =>l_err_msg
3463 );
3464
3465 IF (l_err_num <> 0) THEN
3466
3467 RAISE CST_FAILED_INSERT_PTI;
3468
3469 END IF;
3470
3471 END LOOP;
3472
3473 l_stmt_num := 154;
3474
3475 IF l_rownum = 0 THEN
3476
3477 RAISE NO_ROWS_TO_INSERT;
3478
3479 END IF;
3480
3481 END IF; /* end of check for l_earn_tomoh */
3482
3483 --------------------------------------------------------------
3484 -- CASE 0: All Transactions having the SI as project costed 'Y'
3485 -- Misc Family Transactions referring a Proj SI
3486 -- PO Family referring Proj SI
3487 -- WIP Component Issue/Rtn referring a Proj SI
3488 -- Issue side of a Sub-Trf referring a Proj SI
3489 -- ( only neg Txn )
3490 -- Cycle Count referring a Proj SI
3491 -- Physical Inv referring a Proj SI
3492 -- Issue side of Direct Org Trf referring a Proj SI
3493 -- Receipt side of Direct Org Trf referring a Proj SI
3494 -- Issue/Receipt side of Inter Org Trf referring a Proj
3495 -- SI and being cost collected Organization
3496 --
3497 -- Exclude all Assy Completion and Returns that have
3498 -- both the Job and SI as Project Costed 'Y' in which
3499 -- case one needs earn only the MO earnings. The same
3500 -- is being taken care in the previous IF statement.
3501 --
3502 -- CASE 1: Those Assy Completion/Rtn Transactions involving an
3503 -- Issue / Rtn from/to a Sub that project costed as 'Y'
3504 -- and the job as not to be project costed which
3505 -- implies that this level MO is reported on a SE basis
3506 -- and all the elements other than this level MO
3507 -- are reported elementally.
3508 --
3509
3510 -- It is assumed that cost_element_id will not be null in
3511 -- mta for accounting_line_type = 1 for an average cost org.
3512 --------------------------------------------------------------
3513
3514
3515 --------------------------------------------------------------
3516 -- this part is added for bug 1036822
3517 -- this if statement is one level higher
3518 -- then the older code because
3519 -- it is trying to exclude the
3520 -- DEFAULT PROJECT ASSEMBLY COMPLETION/RETURN
3521 -- transactions which would be pick up by CASE 0 in the follow.
3522 -- so this one level higher if statement will exclude those
3523 -- transaction before it got picked up by CASE 0
3524 -- bug#1036498
3525 -- For Direct Interorg trf , sending org is std
3526 --(no cost collection enabled,
3527 -- proj ref enab)
3528 -- and recv org is average (cc enabled , proj ref enabled)
3529 -- then can trf
3530 -- betwn same proj and task.
3531 -- Because cost collection is disabled from sending org,
3532 -- so cost collection
3533 -- has to be done on the receiving org.
3534 ---------------------------------------------------------------
3535
3536 ---------------------------------------------------------------
3537 -- for bug 781967, make sure that txn within the same project
3538 -- will not get posted into pa_transaction_interface_all
3539 -- bug 862689
3540 -- bug 1036822
3541 -- with DEFAULT
3542 -- PROJECT OPTION set, the WIP COMPLETION from a common job
3543 -- does notget pick up by cost collector.
3544 ---------------------------------------------------------------
3545
3546 IF NOT( l_default_project is not null
3547 AND p_transaction_action_id in (31,32)
3548 AND p_proj_job_ind = 0)
3549 THEN
3550
3551
3552 l_stmt_num := 155;
3553 -- Bug 2095581
3554 -- In case of an interorg transfer,
3555 -- Cost Collection is done if sending organization in the
3556 -- interorg transfer is not cost collection enabled.
3557
3558 /* Bug #2349027. Interorg transfers should be cost collected
3559 even if the project_id = to_project_id because expenditure
3560 orgs are different. */
3561
3562 IF ((p_transaction_action_id in (3,12,21) and
3563 p_project_id is not null)
3564 -- p_to_project_id is not null and
3565 -- l_cost_collection_enabled_snd <> 1)
3566 -- l_primary_cost_method_snd = 1)
3567 OR
3568 --bug#1036498
3569 ( p_project_id is not null /* CASE 0 */
3570 AND NOT ( p_transaction_action_id in (31,32)
3571 AND p_project_id is not null
3572 AND p_proj_job_ind = 1
3573 )
3574 AND NOT( p_project_id = nvl(p_to_project_id,-9)
3575 and p_task_id = nvl(p_to_task_id,-9)
3576 )
3577 )
3578 OR
3579 /* Consigned ownership trasfers */
3580 ( p_project_id is not null
3581 AND p_transaction_action_id = 6)
3582
3583 /* changes for the PJM Blue print project and drop ship*/
3584 OR
3585 ( p_project_id is not null
3586 AND p_transaction_action_id = 26
3587 )
3588
3589 OR ( p_transaction_action_id in (31,32)
3590 AND p_project_id is not null
3591 AND p_proj_job_ind = 0 /* CASE 1 */
3592 AND l_default_project is NULL
3593 ))
3594 THEN
3595 /* CC ELE ET START INCLUSIVE OF All Filetered 31,32*/
3596
3597 l_rownum := 0;
3598
3599
3600 /* bug 3978501 */
3601 l_no_row_c_sel_prj := 0;
3602
3603 l_stmt_num := 160;
3604
3605
3606 if (l_debug = 'Y') then
3607 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting Project related Locator txn costs ...');
3608 end if;
3609
3610 FOR c_rec3 IN c_sel_prj_txn LOOP
3611
3612 --------------------------------------------------------
3613 -- bug 888190
3614 -- if it is capital project and expenditure type
3615 -- is user entered,
3616 -- then get it from p_expenditure_type
3617 -- otherwise derived it from the system using cceet.
3618 -- proj. misc txn with user entered expenditure type
3619 -- p_user_def_exp_type: 0 is system derived,
3620 -- 1 is user entered
3621 --------------------------------------------------------
3622
3623 IF (p_type_class = 1) and (p_user_def_exp_type = 1) THEN
3624
3625 IF (p_expenditure_type is null) THEN
3626
3627 RAISE CST_FAILED_GET_EXP_TYPE;
3628
3629 ELSE
3630
3631 l_exp_type := p_expenditure_type;
3632
3633 END IF;
3634
3635 ELSE
3636
3637 l_stmt_num := 165;
3638 IF p_transaction_action_id = 17 THEN
3639 SELECT
3640 EXPENDITURE_TYPE
3641 INTO
3642 l_exp_type
3643 FROM
3644 MTL_MATERIAL_TRANSACTIONS
3645 WHERE
3646 transaction_id = p_transaction_id;
3647 ELSE
3648 SELECT
3649 decode(c_rec3.cost_element_id,1,
3650 decode(p_transaction_source_type_id,1,
3651 p_first_matl_se_exp_type,
3652 decode(sign(p_primary_quantity),1,
3653 cceet.EXPENDITURE_TYPE_IN,
3654 cceet.EXPENDITURE_TYPE_OUT)),
3655 decode(sign(p_primary_quantity),1,
3656 cceet.EXPENDITURE_TYPE_IN,
3657 cceet.EXPENDITURE_TYPE_OUT))
3658 INTO l_exp_type
3659 FROM cst_cost_elem_exp_types cceet
3660 WHERE cceet.cost_element_id = c_rec3.cost_element_id;
3661 END IF; -- action_id = 7
3662
3663 END IF;
3664
3665 l_rownum := l_rownum + 1;
3666
3667 l_stmt_num := 170;
3668
3669
3670 If c_rec3.burdened_cost = 0 then
3671 fnd_file.put_line(fnd_file.log,'Burdened cost is zero');
3672 end if;
3673
3674 If c_rec3.burdened_cost <> 0 then
3675
3676 pm_insert_pti_pvt
3677 (p_transaction_source =>
3678 c_rec3.transaction_source,
3679 p_batch_name =>c_rec3.batch_name,
3680 p_expenditure_ending_date =>
3681 c_rec3.expenditure_ending_date,
3682 p_employee_number =>c_rec3.employee_number,
3683 p_organization_name =>
3684 NVL(l_recv_iss_organization_name,
3685 c_rec3.organization_name),
3686 p_expenditure_item_date =>
3687 c_rec3.expenditure_item_date,
3688 p_project_number =>c_rec3.project_number,
3689 p_task_number =>c_rec3.task_number,
3690 p_expenditure_type =>l_exp_type,
3691 p_pa_quantity =>c_rec3.quantity,
3692 p_raw_cost =>c_rec3.raw_cost,
3693 p_expenditure_comment =>
3694 c_rec3.expenditure_comment,
3695 p_orig_transaction_reference =>
3696 c_rec3.orig_transaction_reference,
3697 p_raw_cost_rate =>c_rec3.raw_cost_rate,
3698 p_unmatched_negative_txn_flag=>
3699 c_rec3.unmatched_negative_txn_flag,
3700 p_gl_date =>c_rec3.gl_date,
3701 p_org_id =>c_rec3.org_id,
3702 p_burdened_cost =>c_rec3.burdened_cost,
3703 p_burdened_cost_rate =>
3704 c_rec3.burdened_cost_rate,
3705 p_system_linkage =>c_rec3.system_linkage,
3706 p_transaction_status_code =>
3707 c_rec3.transaction_status_code,
3708 p_denom_currency_code =>
3709 c_rec3.denom_currency_code,
3710 p_transaction_id =>p_transaction_id,
3711
3712 p_transaction_action_id =>p_transaction_action_id,
3713 p_transaction_source_type_id =>
3714 p_transaction_source_type_id,
3715 p_organization_id =>p_organization_id,
3716 p_inventory_item_id =>p_inventory_item_id,
3717 p_cost_element_id =>c_rec3.cost_element_id,
3718 p_resource_id =>NULL,
3719 p_source_flag =>-1,
3720 p_variance_flag =>-1,
3721 p_primary_quantity =>p_primary_quantity ,
3722 p_transfer_organization_id =>
3723 p_transfer_organization_id,
3724 p_fob_point =>l_fob_point,
3725 p_wip_entity_id =>NULL,
3726 p_basis_resource =>NULL,
3727
3728 p_type_class =>p_type_class,
3729 p_project_id =>p_project_id,
3730 p_task_id =>p_task_id,
3731 p_transaction_date =>p_transaction_date,
3732 p_cost_group_id =>p_cost_group_id,
3733 p_transfer_cost_group_id =>
3734 p_transfer_cost_group_id,
3735 p_transaction_source_id =>
3736 p_transaction_source_id,
3737 p_to_project_id =>p_to_project_id,
3738 p_to_task_id =>p_to_task_id,
3739 p_source_project_id =>p_source_project_id,
3740 p_source_task_id =>p_source_task_id,
3741 p_transfer_transaction_id =>
3742 p_transfer_transaction_id,
3743 p_primary_cost_method =>p_primary_cost_method,
3744 p_acct_period_id =>p_acct_period_id,
3745 p_exp_org_id =>p_exp_org_id,
3746 p_distribution_account_id =>
3747 p_distribution_account_id,
3748 p_proj_job_ind =>p_proj_job_ind,
3749 p_first_matl_se_exp_type =>
3750 p_first_matl_se_exp_type,
3751 p_inv_txn_source_literal =>
3752 p_inv_txn_source_literal,
3753 p_cap_txn_source_literal =>
3754 p_cap_txn_source_literal,
3755 p_inv_syslink_literal =>p_inv_syslink_literal,
3756 p_bur_syslink_literal =>p_bur_syslink_literal,
3757 p_wip_syslink_literal =>p_wip_syslink_literal,
3758 p_user_def_exp_type =>p_user_def_exp_type,
3759 p_flow_schedule =>p_flow_schedule,
3760 p_si_asset_yes_no =>p_si_asset_yes_no,
3761 p_transfer_si_asset_yes_no =>
3762 p_transfer_si_asset_yes_no,
3763
3764 O_err_num =>l_err_num,
3765 O_err_code =>l_err_code,
3766 O_err_msg =>l_err_msg
3767 );
3768
3769 IF (l_err_num <> 0) THEN
3770
3771 RAISE CST_FAILED_INSERT_PTI;
3772
3773 END IF;
3774
3775 END IF; /* end of check for burdened cost to be 0 */
3776
3777 END LOOP;
3778
3779 IF l_rownum = 0 THEN
3780
3781 /* bug 3978501 commenting out the excpetion raise as there maybe PPV to insert */
3782
3783 /* RAISE NO_ROWS_TO_INSERT; */
3784 l_no_row_c_sel_prj := 1;
3785
3786 END IF;
3787
3788 END IF;
3789
3790 END IF; -- bug 1036822
3791
3792 ---------------------------------------------------------------
3793 -- for bug 781967, make sure that txn within the same
3794 -- project won't
3795 -- get posted into pa_transaction_interface_all
3796 -- bug 930565, added nvl to take care sub-inventory transaction
3797 -- from common subinventory to project subinventory
3798 ---------------------------------------------------------------
3799
3800 IF (-- p_transaction_action_id IN (2 , 3)
3801 p_to_project_id is not null /* CASE 0 */
3802 AND ((p_transaction_action_id = 2
3803 AND NOT( nvl(p_project_id,-9) = p_to_project_id
3804 and nvl(p_task_id,-9) = p_to_task_id
3805 )
3806 )
3807 OR
3808 p_transaction_action_id = 3
3809 /* bug fix for bug 3150050 */
3810 OR
3811 p_transaction_action_id = 28
3812 )
3813 )
3814 THEN
3815 /* CC ELE ET START FILTERED 2 TRFSIDE */
3816
3817 ------------------------------------------------------
3818 -- CASE 0: All Transactions having the TRF SI as
3819 -- project costed 'Y' . Transaction is looked
3820 -- from the receiving SI perspective. The SI
3821 -- would be the Transfer SI for a -ve qty Txn.
3822 -- Only the -ve qty txns are picked since the
3823 -- is based on them and not the +ve ones.
3824 --
3825 -- Direct IO Xfer with TO_PROJECT NOT NULL
3826 ------------------------------------------------------
3827
3828 l_rownum := 0;
3829
3830 /* bug 3978501 set the variable to 0 to start off */
3831
3832 l_no_row_c_sel_toprj := 0;
3833
3834 l_stmt_num := 175;
3835
3836 if (l_debug = 'Y') then
3837 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting Transfer Side Locator Project costs ...');
3838 end if;
3839
3840 FOR c_rec4 IN c_sel_toprj_txn LOOP
3841
3842 l_rownum := l_rownum + 1;
3843 /* Get Expenditure Type from MMT for Internal SO
3844 Issue and Receipt to Expense */
3845 l_stmt_num := 177;
3846
3847 IF( ( p_transaction_action_id = 1 AND p_transaction_source_type_id = 8 )
3848 OR p_transaction_action_id = 17 ) THEN
3849 SELECT EXPENDITURE_TYPE
3850 INTO c_rec4.EXPENDITURE_TYPE
3851 FROM MTL_MATERIAL_TRANSACTIONS
3852 WHERE transaction_id = p_transaction_id;
3853 END IF;
3854
3855 l_stmt_num := 180;
3856
3857 /* changes to support the Blue print organizations */
3858
3859 /* get the org ID on the transfer Txn */
3860 select organization_id into l_org_id
3861 from mtl_material_transactions
3862 where transaction_id = c_rec4.orig_transaction_reference;
3863
3864 /* set the transaction source accordingly if the org is BP */
3865
3866 select NVL(pa_posting_flag,'N'),
3867 NVL(pa_autoaccounting_flag,'N')
3868 into l_blue_print_enabled_flag,
3869 l_autoaccounting_flag
3870 from pjm_org_parameters
3871 where organization_id = l_org_id ;
3872
3873 If l_blue_print_enabled_flag = 'Y' then
3874
3875 If l_autoaccounting_flag = 'Y' then
3876
3877 /* BP and autoaccounting */
3878 Select pts1.transaction_source,
3879 pts1.transaction_source,
3880 pts1.transaction_source
3881 into l_transaction_source,
3882 l_inv_txn_src_literal,
3883 l_cap_inv_txn_src_literal
3884 From pa_transaction_sources pts1
3885 Where pts1.transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS';
3886 If (l_transaction_source is NULL) then
3887
3888 RAISE CST_FAILED_TXN_SRC;
3889
3890 end If;
3891 else
3892
3893 /* BP and no autoaccounting */
3894 Select pts1.transaction_source,
3895 pts1.transaction_source,
3896 pts1.transaction_source
3897 into l_transaction_source,
3898 l_inv_txn_src_literal,
3899 l_cap_inv_txn_src_literal
3900 From pa_transaction_sources pts1
3901 Where pts1.transaction_source = 'PJM_CSTBP_INV_ACCOUNTS';
3902
3903 If (l_transaction_source is NULL ) then
3904
3905 RAISE CST_FAILED_TXN_SRC;
3906
3907 end If;
3908 end if; /* end of check for auto accounting */
3909
3910 ELSE /* non BP org */
3911
3912 SELECT pts1.transaction_source,
3913 pts1.transaction_source,
3914 pts2.transaction_source
3915 INTO l_inv_txn_src_literal,
3916 l_transaction_source,
3917 l_cap_inv_txn_src_literal
3918 FROM pa_transaction_sources pts1,
3919 pa_transaction_sources pts2
3920 WHERE pts1.transaction_source = 'Inventory'
3921 AND pts2.transaction_source = 'Inventory Misc';
3922
3923 END IF; /* check for BP org */
3924
3925 If c_rec4.burdened_cost = 0 then
3926 fnd_file.put_line(fnd_file.log,'Burdened cost is zero');
3927 end if;
3928
3929 If c_rec4.burdened_cost <> 0 then
3930
3931 pm_insert_pti_pvt
3932 (p_transaction_source =>
3933 l_transaction_source,
3934 p_batch_name =>c_rec4.batch_name,
3935 p_expenditure_ending_date =>
3936 c_rec4.expenditure_ending_date,
3937 p_employee_number =>c_rec4.employee_number,
3938 p_organization_name =>
3939 c_rec4.organization_name,
3940 p_expenditure_item_date =>
3941 c_rec4.expenditure_item_date,
3942 p_project_number =>c_rec4.project_number,
3943 p_task_number =>c_rec4.task_number,
3944 p_expenditure_type =>c_rec4.expenditure_type,
3945 p_pa_quantity =>c_rec4.quantity,
3946 p_raw_cost =>c_rec4.raw_cost,
3947 p_expenditure_comment =>
3948 c_rec4.expenditure_comment,
3949 p_orig_transaction_reference =>
3950 c_rec4.orig_transaction_reference,
3951 p_raw_cost_rate =>c_rec4.raw_cost_rate,
3952 p_unmatched_negative_txn_flag=>
3953 c_rec4.unmatched_negative_txn_flag,
3954 p_gl_date =>c_rec4.gl_date,
3955 p_org_id =>c_rec4.org_id,
3956 p_burdened_cost =>c_rec4.burdened_cost,
3957 p_burdened_cost_rate =>
3958 c_rec4.burdened_cost_rate,
3959 p_system_linkage =>c_rec4.system_linkage,
3960 p_transaction_status_code =>
3961 c_rec4.transaction_status_code,
3962 p_denom_currency_code =>
3963 c_rec4.denom_currency_code,
3964 p_transaction_id =>p_transaction_id,
3965
3966 p_transaction_action_id =>p_transaction_action_id,
3967 p_transaction_source_type_id =>
3968 p_transaction_source_type_id,
3969 p_organization_id =>p_organization_id,
3970 p_inventory_item_id =>p_inventory_item_id,
3971 p_cost_element_id =>c_rec4.cost_element_id,
3972 p_resource_id =>NULL,
3973 p_source_flag =>1,
3974 p_variance_flag =>-1,
3975 p_primary_quantity =>p_primary_quantity ,
3976 p_transfer_organization_id =>
3977 p_transfer_organization_id,
3978 p_fob_point =>l_fob_point,
3979 p_wip_entity_id =>NULL,
3980 p_basis_resource =>NULL,
3981
3982 p_type_class =>p_type_class,
3983 p_project_id =>p_project_id,
3984 p_task_id =>p_task_id,
3985 p_transaction_date =>p_transaction_date,
3986 p_cost_group_id =>p_cost_group_id,
3987 p_transfer_cost_group_id =>
3988 p_transfer_cost_group_id,
3989 p_transaction_source_id =>
3990 p_transaction_source_id,
3991 p_to_project_id =>p_to_project_id,
3992 p_to_task_id =>p_to_task_id,
3993 p_source_project_id =>p_source_project_id,
3994 p_source_task_id =>p_source_task_id,
3995 p_transfer_transaction_id =>
3996 p_transfer_transaction_id,
3997 p_primary_cost_method =>p_primary_cost_method,
3998 p_acct_period_id =>p_acct_period_id,
3999 p_exp_org_id =>p_exp_org_id,
4000 p_distribution_account_id =>
4001 p_distribution_account_id,
4002 p_proj_job_ind =>p_proj_job_ind,
4003 p_first_matl_se_exp_type =>
4004 p_first_matl_se_exp_type,
4005 p_inv_txn_source_literal =>
4006 l_inv_txn_src_literal,
4007 p_cap_txn_source_literal =>
4008 l_cap_inv_txn_src_literal,
4009 p_inv_syslink_literal =>p_inv_syslink_literal,
4010 p_bur_syslink_literal =>p_bur_syslink_literal,
4011 p_wip_syslink_literal =>p_wip_syslink_literal,
4012 p_user_def_exp_type =>p_user_def_exp_type,
4013 p_flow_schedule =>p_flow_schedule,
4014 p_si_asset_yes_no =>p_si_asset_yes_no,
4015 p_transfer_si_asset_yes_no =>
4016 p_transfer_si_asset_yes_no,
4017
4018 O_err_num =>l_err_num,
4019 O_err_code =>l_err_code,
4020 O_err_msg =>l_err_msg
4021 );
4022
4023 IF (l_err_num <> 0) THEN
4024
4025 RAISE CST_FAILED_INSERT_PTI;
4026
4027 END IF;
4028
4029 END IF; /* End of check for burdened cost to be 0 */
4030
4031 END LOOP;
4032
4033 IF l_rownum = 0 THEN
4034 /* Bug 2386069
4035 If the receiving txn has not been costed yet, update MMT with a
4036 warning but do not reset the pm_cost_collected flag to error.
4037 */
4038 SELECT mmt.costed_flag
4039 INTO l_costed_flag
4040 FROM mtl_material_transactions mmt
4041 WHERE mmt.transaction_id = decode(p_transaction_action_id,
4042 3, p_transfer_transaction_id ,
4043 p_transaction_id)
4044 AND mmt.organization_id = decode(p_transaction_action_id,
4045 3, p_transfer_organization_id,
4046 p_organization_id);
4047
4048 IF (l_costed_flag = 'N') THEN
4049 if (l_debug = 'Y') then
4050 fnd_file.put_line(fnd_file.log, 'Receving Txn not yet costed!!!!');
4051 end if;
4052 RAISE ROW_NOT_COSTED;
4053 ELSE
4054
4055 /* bug 3978501 commenting out the excpetion part as there may be PPV to insert */
4056
4057 /* RAISE NO_ROWS_TO_INSERT; */
4058 l_no_row_c_sel_toprj := 1;
4059
4060 END IF;
4061
4062 END IF;
4063
4064 END IF; /* CC ALL ELE ET START FILTERED 2 TRFSIDE */
4065
4066 ---------------------------------------------------------------
4067 /* CC ALL ELE ET START FILTERED WIPCompIss/Rtn,31,32 TRFSIDE */
4068
4069 -- CASE 1: All WIP/CFM Issue/Return and -ve WIP/CFM
4070 -- Issue/Return Transactions having the
4071 -- JOB as project costed 'Y', imply their CC
4072 -- w.r.t the source project and task
4073 --
4074 -- CASE 2: All Transactions having the JOB/CFM project
4075 -- costed 'Y' and SI as project costed 'N' ,
4076 -- belonging to group of WIP Assy Completion
4077 -- or Returns, implying their CC w.r.t the
4078 -- source project and task
4079 --
4080 -- CASE 3: All Misc Family Transactions belonging to
4081 -- Capital Project transaction type
4082 -- ( User given project and task information
4083 -- at transaction time are stored in the
4084 -- source project and source task fields )
4085 -- If user does not specify an expenditure_type
4086 -- the default associations will be used.
4087 --
4088 -- NOTE: The Cost Group being used is cost_group_id and
4089 -- the transfer_cost_group_id although the project
4090 -- and task being used are source project and
4091 -- source task, because MCACD has one for the Txn
4092 -- and that is w.r.t the SI's cost_group
4093 --
4094 ---------------------------------------------------------------
4095
4096
4097 IF ( p_transaction_action_id in (1,27,33,34)
4098 AND p_transaction_source_type_id = 5
4099 AND p_proj_job_ind = 1 /* CASE 1 */
4100 )
4101 OR ( p_transaction_action_id in (31,32)
4102 AND p_transaction_source_type_id = 5
4103 AND p_project_id is null
4104 AND p_proj_job_ind = 1 /* CASE 2 */
4105 )
4106 OR (p_type_class = 1) /* CASE 3 */
4107
4108 THEN
4109
4110 l_rownum := 0;
4111
4112 l_stmt_num := 185;
4113
4114 if (l_debug = 'Y') then
4115 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting source side project costs ...');
4116 end if;
4117
4118 FOR c_rec5 IN c_sel_src_txn LOOP
4119
4120 ---------------------------------------------------------
4121 -- bug 888190
4122 -- if it is capital project and expenditure type is user
4123 -- entered,
4124 -- then get it from p_expenditure_type
4125 -- otherwise derived it from the system using cceet.
4126 ---------------------------------------------------------
4127
4128 IF (p_type_class = 1) and (p_user_def_exp_type = 1) THEN
4129
4130 -- proj. misc txn with user entered expenditure type
4131 -- p_user_def_exp_type: 0 is system derived,
4132 -- 1 is user entered
4133
4134 IF (p_expenditure_type is null) THEN
4135
4136 RAISE CST_FAILED_GET_EXP_TYPE;
4137
4138 ELSE
4139
4140 l_exp_type := p_expenditure_type;
4141
4142 END IF;
4143
4144 ELSE
4145
4146 SELECT
4147 decode(sign(p_primary_quantity),1,
4148 cceet.EXPENDITURE_TYPE_OUT,
4149 cceet.EXPENDITURE_TYPE_IN)
4150 INTO l_exp_type
4151 FROM cst_cost_elem_exp_types cceet
4152 WHERE cceet.cost_element_id = c_rec5.cost_element_id;
4153
4154 END IF;
4155
4156 l_rownum := l_rownum + 1;
4157
4158 l_stmt_num := 190;
4159
4160 pm_insert_pti_pvt
4161 (p_transaction_source =>
4162 c_rec5.transaction_source,
4163 p_batch_name =>c_rec5.batch_name,
4164 p_expenditure_ending_date =>
4165 c_rec5.expenditure_ending_date,
4166 p_employee_number =>c_rec5.employee_number,
4167 p_organization_name =>
4168 c_rec5.organization_name,
4169 p_expenditure_item_date =>
4170 c_rec5.expenditure_item_date,
4171 p_project_number =>c_rec5.project_number,
4172 p_task_number =>c_rec5.task_number,
4173 p_expenditure_type =>l_exp_type,
4174 p_pa_quantity =>c_rec5.quantity,
4175 p_raw_cost =>c_rec5.raw_cost,
4176 p_expenditure_comment =>
4177 c_rec5.expenditure_comment,
4178 p_orig_transaction_reference =>
4179 c_rec5.orig_transaction_reference,
4180 p_raw_cost_rate =>c_rec5.raw_cost_rate,
4181 p_unmatched_negative_txn_flag=>
4182 c_rec5.unmatched_negative_txn_flag,
4183 p_gl_date =>c_rec5.gl_date,
4184 p_org_id =>c_rec5.org_id,
4185 p_burdened_cost =>c_rec5.burdened_cost,
4186 p_burdened_cost_rate =>
4187 c_rec5.burdened_cost_rate,
4188 p_system_linkage =>c_rec5.system_linkage,
4189 p_transaction_status_code =>
4190 c_rec5.transaction_status_code,
4191 p_denom_currency_code =>
4192 c_rec5.denom_currency_code,
4193 p_transaction_id =>p_transaction_id,
4194
4195 p_transaction_action_id =>p_transaction_action_id,
4196 p_transaction_source_type_id =>
4197 p_transaction_source_type_id,
4198 p_organization_id =>p_organization_id,
4199 p_inventory_item_id =>p_inventory_item_id,
4200 p_cost_element_id =>c_rec5.cost_element_id,
4201 p_resource_id =>NULL,
4202 p_source_flag =>1,
4203 p_variance_flag =>-1,
4204 p_primary_quantity =>p_primary_quantity ,
4205 p_transfer_organization_id =>
4206 p_transfer_organization_id,
4207 p_fob_point =>l_fob_point,
4208 p_wip_entity_id =>NULL,
4209 p_basis_resource =>NULL,
4210
4211 p_type_class =>p_type_class,
4212 p_project_id =>p_project_id,
4213 p_task_id =>p_task_id,
4214 p_transaction_date =>p_transaction_date,
4215 p_cost_group_id =>p_cost_group_id,
4216 p_transfer_cost_group_id =>
4217 p_transfer_cost_group_id,
4218 p_transaction_source_id =>
4219 p_transaction_source_id,
4220 p_to_project_id =>p_to_project_id,
4221 p_to_task_id =>p_to_task_id,
4222 p_source_project_id =>p_source_project_id,
4223 p_source_task_id =>p_source_task_id,
4224 p_transfer_transaction_id =>
4225 p_transfer_transaction_id,
4226 p_primary_cost_method =>p_primary_cost_method,
4227 p_acct_period_id =>p_acct_period_id,
4228 p_exp_org_id =>p_exp_org_id,
4229 p_distribution_account_id =>
4230 p_distribution_account_id,
4231 p_proj_job_ind =>p_proj_job_ind,
4232 p_first_matl_se_exp_type =>
4233 p_first_matl_se_exp_type,
4234 p_inv_txn_source_literal =>
4235 p_inv_txn_source_literal,
4236 p_cap_txn_source_literal =>
4237 p_cap_txn_source_literal,
4238 p_inv_syslink_literal =>p_inv_syslink_literal,
4239 p_bur_syslink_literal =>p_bur_syslink_literal,
4240 p_wip_syslink_literal =>p_wip_syslink_literal,
4241 p_user_def_exp_type =>p_user_def_exp_type,
4242 p_flow_schedule =>p_flow_schedule,
4243 p_si_asset_yes_no =>p_si_asset_yes_no,
4244 p_transfer_si_asset_yes_no =>
4245 p_transfer_si_asset_yes_no,
4246
4247 O_err_num =>l_err_num,
4248 O_err_code =>l_err_code,
4249 O_err_msg =>l_err_msg
4250 );
4251
4252
4253 IF (l_err_num <> 0) THEN
4254
4255 RAISE CST_FAILED_INSERT_PTI;
4256
4257 END IF;
4258
4259 END LOOP;
4260
4261 IF l_rownum = 0 THEN
4262
4263 RAISE NO_ROWS_TO_INSERT;
4264
4265 END IF;
4266
4267 END IF; /*CC ALL ELE END FILTERED WIPCompIss/Rtn,31,32 TRFSIDE*/
4268
4269 ---- borrow payback
4270
4271 /* Borrow Payback Enhancements - Bug 2665290 */
4272
4273 IF (p_transaction_action_id = 2) AND (l_txn_type = 68)
4274 /*AND (p_cost_group_id <> p_transfer_cost_group_id) */
4275 THEN
4276
4277 l_rownum := 0;
4278 l_stmt_num := 200;
4279
4280 if (l_debug = 'Y') then
4281 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting Borrow Payback transactions ...');
4282 end if;
4283
4284 FOR c_rec6 IN c_sel_bp_txn LOOP
4285
4286 l_rownum := l_rownum + 1;
4287
4288 l_stmt_num := 205;
4289
4290 pm_insert_pti_pvt
4291 (p_transaction_source =>
4292 c_rec6.transaction_source,
4293 p_batch_name =>c_rec6.batch_name,
4294 p_expenditure_ending_date =>
4295 c_rec6.expenditure_ending_date,
4296 p_employee_number =>c_rec6.employee_number,
4297 p_organization_name =>
4298 c_rec6.organization_name,
4299 p_expenditure_item_date =>
4300 c_rec6.expenditure_item_date,
4301 p_project_number =>c_rec6.project_number,
4302 p_task_number =>c_rec6.task_number,
4303 p_expenditure_type =>c_rec6.expenditure_type,
4304 p_pa_quantity =>c_rec6.quantity,
4305 p_raw_cost =>c_rec6.raw_cost,
4306 p_expenditure_comment =>
4307 c_rec6.expenditure_comment,
4308 p_orig_transaction_reference =>
4309 c_rec6.orig_transaction_reference,
4310 p_raw_cost_rate =>c_rec6.raw_cost_rate,
4311 p_unmatched_negative_txn_flag=>
4312 c_rec6.unmatched_negative_txn_flag,
4313 p_gl_date =>c_rec6.gl_date,
4314 p_org_id =>c_rec6.org_id,
4315 p_burdened_cost =>c_rec6.burdened_cost,
4316 p_burdened_cost_rate =>
4317 c_rec6.burdened_cost_rate,
4318 p_system_linkage =>c_rec6.system_linkage,
4319 p_transaction_status_code =>
4320 c_rec6.transaction_status_code,
4321 p_denom_currency_code =>
4322 c_rec6.denom_currency_code,
4323 p_transaction_id =>p_transaction_id,
4324
4325 p_transaction_action_id =>p_transaction_action_id,
4326 p_transaction_source_type_id =>
4327 p_transaction_source_type_id,
4328 p_organization_id =>p_organization_id,
4329 p_inventory_item_id =>p_inventory_item_id,
4330 p_cost_element_id =>c_rec6.cost_element_id,
4331 p_resource_id =>NULL,
4332 p_source_flag =>-1,
4333 p_variance_flag =>1,
4334 p_primary_quantity =>p_primary_quantity ,
4335 p_transfer_organization_id =>
4336 p_transfer_organization_id,
4337 p_fob_point =>l_fob_point,
4338 p_wip_entity_id =>NULL,
4339 p_basis_resource =>NULL,
4340
4341 p_type_class =>p_type_class,
4342 p_project_id =>p_project_id,
4343 p_task_id =>p_task_id,
4344 p_transaction_date =>p_transaction_date,
4345 p_cost_group_id =>p_cost_group_id,
4346 p_transfer_cost_group_id =>
4347 p_transfer_cost_group_id,
4348 p_transaction_source_id =>
4349 p_transaction_source_id,
4350 p_to_project_id =>p_to_project_id,
4351 p_to_task_id =>p_to_task_id,
4352 p_source_project_id =>p_source_project_id,
4353 p_source_task_id =>p_source_task_id,
4354 p_transfer_transaction_id =>
4355 p_transfer_transaction_id,
4356 p_primary_cost_method =>p_primary_cost_method,
4357 p_acct_period_id =>p_acct_period_id,
4358 p_exp_org_id =>p_exp_org_id,
4359 p_distribution_account_id =>
4360 p_distribution_account_id,
4361 p_proj_job_ind =>p_proj_job_ind,
4362 p_first_matl_se_exp_type =>
4363 p_first_matl_se_exp_type,
4364 p_inv_txn_source_literal =>
4365 p_inv_txn_source_literal,
4366 p_cap_txn_source_literal =>
4367 p_cap_txn_source_literal,
4368 p_inv_syslink_literal =>p_inv_syslink_literal,
4369 p_bur_syslink_literal =>p_bur_syslink_literal,
4370 p_wip_syslink_literal =>p_wip_syslink_literal,
4371 p_user_def_exp_type =>p_user_def_exp_type,
4372 p_flow_schedule =>p_flow_schedule,
4373 p_si_asset_yes_no =>p_si_asset_yes_no,
4374 p_transfer_si_asset_yes_no =>
4375 p_transfer_si_asset_yes_no,
4376
4377 O_err_num =>l_err_num,
4378 O_err_code =>l_err_code,
4379 O_err_msg =>l_err_msg
4380 );
4381
4382 /* For standard costing orgs, the borrow payback variance has to
4383 be applied to both the borrowing and the lending projects*/
4384 /* Patchset J - Borrow Payback Enhancements - In actual organizations, BPV
4385 against payback transactions across the same cost group has to be collected
4386 against both the borrowing and lending project Adding OR condition*/
4387 IF ((p_std_cg_acct = 1 AND p_primary_cost_method = 1) OR
4388 (p_primary_cost_method <> 1 and p_cost_group_id = p_transfer_cost_group_id))
4389 THEN
4390
4391 SELECT
4392 decode(sign(-1 * p_primary_quantity),1,
4393 cceet.EXPENDITURE_TYPE_OUT,
4394 cceet.EXPENDITURE_TYPE_IN)
4395 INTO l_exp_type
4396 FROM cst_cost_elem_exp_types cceet
4397 WHERE cceet.cost_element_id = c_rec6.cost_element_id;
4398
4399 pm_insert_pti_pvt
4400 (p_transaction_source =>
4401 c_rec6.transaction_source,
4402 p_batch_name =>c_rec6.batch_name,
4403 p_expenditure_ending_date =>
4404 c_rec6.expenditure_ending_date,
4405 p_employee_number =>c_rec6.employee_number,
4406 p_organization_name =>
4407 c_rec6.organization_name,
4408 p_expenditure_item_date =>
4409 c_rec6.expenditure_item_date,
4410 p_project_number =>l_to_project_number,
4411 p_task_number =>l_to_task_number,
4412 p_expenditure_type =>l_exp_type,
4413 p_pa_quantity =>-1 * c_rec6.quantity,
4414 p_raw_cost =>-1 * c_rec6.raw_cost,
4415 p_expenditure_comment =>
4416 c_rec6.expenditure_comment,
4417 p_orig_transaction_reference =>to_char(p_transfer_transaction_id),
4418 p_raw_cost_rate =>-1 * c_rec6.raw_cost_rate,
4419 p_unmatched_negative_txn_flag=>
4420 c_rec6.unmatched_negative_txn_flag,
4421 p_gl_date =>c_rec6.gl_date,
4422 p_org_id =>l_to_proj_org_id,
4423 p_burdened_cost =>-1 * c_rec6.burdened_cost,
4424 p_burdened_cost_rate =>
4425 -1 * c_rec6.burdened_cost_rate,
4426 p_system_linkage =>c_rec6.system_linkage,
4427 p_transaction_status_code =>
4428 c_rec6.transaction_status_code,
4429 p_denom_currency_code =>
4430 c_rec6.denom_currency_code,
4431 p_transaction_id =>p_transaction_id,
4432
4433 p_transaction_action_id =>p_transaction_action_id,
4434 p_transaction_source_type_id =>
4435 p_transaction_source_type_id,
4436 p_organization_id =>p_organization_id,
4437 p_inventory_item_id =>p_inventory_item_id,
4438 p_cost_element_id =>c_rec6.cost_element_id,
4439 p_resource_id =>NULL,
4440 p_source_flag =>-1,
4441 p_variance_flag =>1,
4442 p_primary_quantity =>-1 * p_primary_quantity ,
4443 p_transfer_organization_id =>
4444 p_organization_id,
4445 p_fob_point =>l_fob_point,
4446 p_wip_entity_id =>NULL,
4447 p_basis_resource =>NULL,
4448
4449 p_type_class =>p_type_class,
4450 p_project_id =>p_to_project_id,
4451 p_task_id =>p_to_task_id,
4452 p_transaction_date =>p_transaction_date,
4453 p_cost_group_id =>p_transfer_cost_group_id,
4454 p_transfer_cost_group_id =>
4455 p_cost_group_id,
4456 p_transaction_source_id =>
4457 p_transaction_source_id,
4458 p_to_project_id =>p_project_id,
4459 p_to_task_id =>p_task_id,
4460 p_source_project_id =>p_source_project_id,
4461 p_source_task_id =>p_source_task_id,
4462 p_transfer_transaction_id =>
4463 p_transaction_id,
4464 p_primary_cost_method =>p_primary_cost_method,
4465 p_acct_period_id =>p_acct_period_id,
4466 p_exp_org_id =>p_exp_org_id,
4467 p_distribution_account_id =>
4468 p_distribution_account_id,
4469 p_proj_job_ind =>p_proj_job_ind,
4470 p_first_matl_se_exp_type =>
4471 p_first_matl_se_exp_type,
4472 p_inv_txn_source_literal =>
4473 p_inv_txn_source_literal,
4474 p_cap_txn_source_literal =>
4475 p_cap_txn_source_literal,
4476 p_inv_syslink_literal =>p_inv_syslink_literal,
4477 p_bur_syslink_literal =>p_bur_syslink_literal,
4478 p_wip_syslink_literal =>p_wip_syslink_literal,
4479 p_user_def_exp_type =>p_user_def_exp_type,
4480 p_flow_schedule =>p_flow_schedule,
4481 p_si_asset_yes_no =>p_si_asset_yes_no,
4482 p_transfer_si_asset_yes_no =>
4483 p_transfer_si_asset_yes_no,
4484
4485 O_err_num =>l_err_num,
4486 O_err_code =>l_err_code,
4487 O_err_msg =>l_err_msg
4488 );
4489 END IF;
4490
4491 IF (l_err_num <> 0) THEN
4492
4493 RAISE CST_FAILED_INSERT_PTI;
4494
4495 END IF;
4496
4497 END LOOP;
4498
4499 /* Commenting this out - borrow payback transactions need not
4500 have borrow payback variance. */
4501
4502 /* IF l_rownum = 0 THEN
4503
4504 RAISE NO_ROWS_TO_INSERT;
4505
4506 END IF;*/
4507
4508 END IF; /*CC ALL BORROW PAYBACK TXN */
4509
4510
4511 l_no_ppv := 1; --bug 3978501 setting the variable to 1 initially
4512
4513 -- PJMSTD_PPV
4514 /* Bug # 2349027. For interorg transfers, collect PPV if project_id is the same
4515 as to_project_id since the expenditure orgs are different. */
4516 IF (((p_std_cg_acct = 1 AND p_primary_cost_method = 1) OR
4517 (l_primary_cost_method_snd = 1)) AND
4518 (
4519 /* Transfer org does not have cost collection enabled */
4520 /*(p_transaction_action_id in (3,12,21) and
4521 p_to_project_id is not null and
4522 l_cost_collection_enabled_snd <> 1)
4523 OR */
4524 /* PO Receipt */
4525 p_transaction_source_type_id = 1
4526 OR
4527 /* Interorg transfer between two different project/tasks. */
4528 (p_transaction_action_id IN (12,21,3)
4529 /* AND NOT( p_project_id = nvl(p_to_project_id,-9)
4530 and p_task_id = nvl(p_to_task_id,-9))*/
4531 )
4532 OR
4533 /* Consigned ownership transfer transaction */
4534 p_transaction_action_id = 6
4535 ))
4536 THEN
4537 /* For direct interorg transfers from standard org to a standard org,
4538 the PPV is always generated against the sending organization.
4539 For direct interorg transfers from average org to a standard org,
4540 the PPV is always generated against the receiving organization.
4541 */
4542 IF (
4543 (p_primary_cost_method=1 AND l_primary_cost_method_snd = 1 AND
4544 p_transaction_action_id=3 AND p_primary_quantity >0) OR
4545 (p_primary_cost_method <> 1 AND l_primary_cost_method_snd = 1 AND
4546 p_transaction_action_id = 3 AND p_primary_quantity < 0)) THEN
4547 ppv_txfr_flag := 1;
4548 ELSE
4549 ppv_txfr_flag := 0;
4550 END IF;
4551
4552 l_rownum := 0;
4553
4554 if (l_debug = 'Y') then
4555 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Collecting purchase price variances ...');
4556 FND_FILE.PUT_LINE(FND_FILE.LOG,'ppv_txfr_flag : '||ppv_txfr_flag||
4557 'p_primary_cost_method : '||p_primary_cost_method||
4558 'l_primary_cost_method_snd : '||l_primary_cost_method_snd||
4559 ' p_organization_id : '||p_organization_id||
4560 ' p_transaction_id : '||p_transaction_id||
4561 ' p_transfer_organization_id : '||p_transfer_organization_id||
4562 ' p_transfer_transaction_id : '||p_transfer_transaction_id||
4563 ' p_primary_quantity : '||p_primary_quantity||
4564 ' p_project_id : '||p_project_id||
4565 ' p_to_project_id : '||p_to_project_id);
4566 end if;
4567
4568 FOR c_rec7 IN c_sel_ppv LOOP
4569
4570 l_rownum := l_rownum + 1;
4571
4572 l_stmt_num := 210;
4573
4574
4575 /* changes to support the Blue print organizations */
4576
4577 /* get the org ID on the transfer Txn if direct interorg*/
4578
4579 If p_transaction_action_id = 3 then
4580
4581 select organization_id into l_org_id
4582 from mtl_material_transactions
4583 where transaction_id = c_rec7.orig_transaction_reference;
4584
4585 /* set the transaction source accordingly if the org is BP */
4586
4587 select NVL(pa_posting_flag,'N'),
4588 NVL(pa_autoaccounting_flag,'N')
4589 into l_blue_print_enabled_flag,
4590 l_autoaccounting_flag
4591 from pjm_org_parameters
4592 where organization_id = l_org_id ;
4593
4594 If l_blue_print_enabled_flag = 'Y' then
4595
4596 If l_autoaccounting_flag = 'Y' then
4597
4598 /* BP and autoaccounting */
4599 Select pts1.transaction_source,
4600 pts1.transaction_source,
4601 pts1.transaction_source
4602 into l_transaction_source,
4603 l_inv_txn_src_literal,
4604 l_cap_inv_txn_src_literal
4605 From pa_transaction_sources pts1
4606 Where pts1.transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS';
4607 If (l_transaction_source is NULL) then
4608
4609 RAISE CST_FAILED_TXN_SRC;
4610
4611 end If;
4612 else
4613 /* BP and no autoaccounting */
4614 Select pts1.transaction_source,
4615 pts1.transaction_source,
4616 pts1.transaction_source
4617 into l_transaction_source,
4618 l_inv_txn_src_literal,
4619 l_cap_inv_txn_src_literal
4620 From pa_transaction_sources pts1
4621 Where pts1.transaction_source = 'PJM_CSTBP_INV_ACCOUNTS';
4622
4623 If (l_transaction_source is NULL ) then
4624
4625 RAISE CST_FAILED_TXN_SRC;
4626
4627 end If;
4628 end if; /* end of check for auto accounting */
4629
4630 ELSE /* non BP org */
4631
4632 SELECT pts1.transaction_source,
4633 pts2.transaction_source
4634 INTO l_inv_txn_src_literal,
4635 l_cap_inv_txn_src_literal
4636 FROM pa_transaction_sources pts1,
4637 pa_transaction_sources pts2
4638 WHERE pts1.transaction_source = 'Inventory'
4639 AND pts2.transaction_source = 'Inventory Misc';
4640
4641 SELECT decode(p_type_class,1,
4642 l_cap_inv_txn_src_literal,
4643 l_inv_txn_src_literal)
4644 INTO l_transaction_source
4645 from dual;
4646
4647
4648 END IF; /* check for BP org */
4649
4650 ELSE /* transaction action iD <> 3 */
4651
4652 l_transaction_source := c_rec7.transaction_source ;
4653 l_inv_txn_src_literal := p_inv_txn_source_literal ;
4654 l_cap_inv_txn_src_literal := p_cap_txn_source_literal;
4655
4656 END IF ; /* check for direct inter org txns */
4657
4658
4659 pm_insert_pti_pvt
4660 (p_transaction_source =>
4661 l_transaction_source,
4662 p_batch_name =>c_rec7.batch_name,
4663 p_expenditure_ending_date =>
4664 c_rec7.expenditure_ending_date,
4665 p_employee_number =>c_rec7.employee_number,
4666 p_organization_name =>
4667 c_rec7.organization_name,
4668 p_expenditure_item_date =>
4669 c_rec7.expenditure_item_date,
4670 p_project_number =>c_rec7.project_number,
4671 p_task_number =>c_rec7.task_number,
4672 p_expenditure_type =>c_rec7.expenditure_type,
4673 p_pa_quantity =>c_rec7.quantity,
4674 p_raw_cost =>c_rec7.raw_cost,
4675 p_expenditure_comment =>
4676 c_rec7.expenditure_comment,
4677 p_orig_transaction_reference =>
4678 c_rec7.orig_transaction_reference,
4679 p_raw_cost_rate =>c_rec7.raw_cost_rate,
4680 p_unmatched_negative_txn_flag=>
4681 c_rec7.unmatched_negative_txn_flag,
4682 p_gl_date =>c_rec7.gl_date,
4683 p_org_id =>c_rec7.org_id,
4684 p_burdened_cost =>c_rec7.burdened_cost,
4685 p_burdened_cost_rate =>
4686 c_rec7.burdened_cost_rate,
4687 p_system_linkage =>c_rec7.system_linkage,
4688 p_transaction_status_code =>
4689 c_rec7.transaction_status_code,
4690 p_denom_currency_code =>
4691 c_rec7.denom_currency_code,
4692 p_transaction_id =>p_transaction_id,
4693
4694 p_transaction_action_id =>p_transaction_action_id,
4695 p_transaction_source_type_id =>
4696 p_transaction_source_type_id,
4697 p_organization_id =>p_organization_id,
4698 p_inventory_item_id =>p_inventory_item_id,
4699 p_cost_element_id =>c_rec7.cost_element_id,
4700 p_resource_id =>NULL,
4701 p_source_flag =>-1,
4702 p_variance_flag =>1,
4703 p_primary_quantity =>p_primary_quantity ,
4704 p_transfer_organization_id =>
4705 p_transfer_organization_id,
4706 p_fob_point =>l_fob_point,
4707 p_wip_entity_id =>NULL,
4708 p_basis_resource =>NULL,
4709
4710 p_type_class =>p_type_class,
4711 p_project_id =>p_project_id,
4712 p_task_id =>p_task_id,
4713 p_transaction_date =>p_transaction_date,
4714 p_cost_group_id =>p_cost_group_id,
4715 p_transfer_cost_group_id =>
4716 p_transfer_cost_group_id,
4717 p_transaction_source_id =>
4718 p_transaction_source_id,
4719 p_to_project_id =>p_to_project_id,
4720 p_to_task_id =>p_to_task_id,
4721 p_source_project_id =>p_source_project_id,
4722 p_source_task_id =>p_source_task_id,
4723 p_transfer_transaction_id =>
4724 p_transfer_transaction_id,
4725 p_primary_cost_method =>p_primary_cost_method,
4726 p_acct_period_id =>p_acct_period_id,
4727 p_exp_org_id =>p_exp_org_id,
4728 p_distribution_account_id =>
4729 p_distribution_account_id,
4730 p_proj_job_ind =>p_proj_job_ind,
4731 p_first_matl_se_exp_type =>
4732 p_first_matl_se_exp_type,
4733 p_inv_txn_source_literal =>
4734 l_inv_txn_src_literal,
4735 p_cap_txn_source_literal =>
4736 l_cap_inv_txn_src_literal,
4737 p_inv_syslink_literal =>p_inv_syslink_literal,
4738 p_bur_syslink_literal =>p_bur_syslink_literal,
4739 p_wip_syslink_literal =>p_wip_syslink_literal,
4740 p_user_def_exp_type =>p_user_def_exp_type,
4741 p_flow_schedule =>p_flow_schedule,
4742 p_si_asset_yes_no =>p_si_asset_yes_no,
4743 p_transfer_si_asset_yes_no =>
4744 p_transfer_si_asset_yes_no,
4745
4746 O_err_num =>l_err_num,
4747 O_err_code =>l_err_code,
4748 O_err_msg =>l_err_msg
4749 );
4750
4751 IF (l_err_num <> 0) THEN
4752
4753 RAISE CST_FAILED_INSERT_PTI;
4754
4755 END IF;
4756
4757 END LOOP; --c_rec7
4758
4759
4760 /* bug 3978501. check to see if r have been inserted and update l_no_ppv */
4761
4762 if l_rownum <> 0 then
4763
4764 l_no_ppv := 0;
4765
4766 end If;
4767
4768
4769 END IF; -- Check for PPV of PO or IO Txn
4770
4771
4772 /* bug 3978501 check to see the 3 flags and decide whether to raise the no rows exception or not */
4773
4774 IF l_no_ppv = 1 then
4775 IF l_no_row_c_sel_prj = 1 or l_no_row_c_sel_toprj = 1 then
4776 RAISE NO_ROWS_TO_INSERT;
4777 END IF;
4778 END IF;
4779
4780
4781 END IF; /* END: CC ALL TXNS OF AN AVG+PJMSTD COSTING ORG */
4782
4783 EXCEPTION
4784
4785 WHEN CST_FAILED_GET_EXPENDDATE THEN
4786
4787 O_err_num := 20001;
4788
4789 fnd_message.set_name('BOM','CST_FAILED_GET_EXPENDDATE');
4790 l_err_msg := fnd_message.get ;
4791 O_err_msg := substr(l_err_msg,1,240) ;
4792
4793 O_err_code := 'CSTPPCCB.pm_process_txn_mmt('
4794 || to_char(l_stmt_num)
4795 || '): ';
4796
4797 WHEN NO_ROWS_TO_INSERT THEN
4798
4799 O_err_num := 20002;
4800
4801 fnd_message.set_name('BOM',
4802 'CST_NO_PROJ_COSTS_REPORTED');
4803 l_err_msg := fnd_message.get ;
4804 O_err_msg := substr(l_err_msg,1,240) ;
4805
4806 O_err_code := 'CSTPPCCB.pm_process_txn_mmt('
4807 || to_char(l_stmt_num)
4808 || '): ';
4809
4810 WHEN ROW_NOT_COSTED THEN
4811
4812 O_err_num := 30000;
4813
4814 fnd_message.set_name('BOM',
4815 'CST_TXN_NOT_COSTED');
4816 l_err_msg := fnd_message.get ;
4817 O_err_msg := substr(l_err_msg,1,240) ;
4818
4819 O_err_code := 'CSTPPCCB.pm_process_txn_mmt('
4820 || to_char(l_stmt_num)
4821 || '): ';
4822
4823
4824 WHEN CST_FAILED_PROJTSK_VALID THEN
4825
4826 O_err_num := 20003;
4827
4828 /* fnd_message.set_name('BOM','CST_FAILED_PROJTSK_VALID');
4829 l_err_msg := fnd_message.get ;
4830 O_err_msg := substr(l_err_msg,1,240) ;
4831 */
4832 O_err_msg:='Project/Task Invalid for Cost Collection.';
4833 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4834 ||to_char(l_stmt_num)
4835 ||'): '
4836 ||l_err_msg,1,240);
4837
4838 -- bug 888190, new exception is added
4839 -- to handle expenditure type not found
4840 WHEN CST_FAILED_GET_EXP_TYPE THEN
4841 O_err_num := 20004;
4842 O_err_code := NULL;
4843 O_err_msg := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4844 ||to_char(l_stmt_num)
4845 ||'): '
4846 ||'Failed to get expenditure type.',1,240);
4847
4848 WHEN CST_FAILED_INSERT_PTI THEN
4849 O_err_num := 20005;
4850 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4851 ||to_char(l_stmt_num)
4852 ||'): '
4853 ||l_err_code, 1,240);
4854 O_err_msg := SUBSTR(l_err_msg,1,240);
4855
4856 WHEN CST_FAILED_STD_CG_FLAG THEN
4857
4858 O_err_num := 20006;
4859 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4860 ||to_char(l_stmt_num)
4861 ||'): ',1,240);
4862 O_err_msg :=
4863 'Failed CST_UTILITY_PUB.GET_STD_CG_ACCT_FLAG';
4864
4865 WHEN CST_FAILED_TXN_SRC THEN
4866
4867 O_err_num := 20007;
4868 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4869 || to_char(l_stmt_num)
4870 ||'): ',1,240);
4871 O_err_msg := 'failed to get TXN source' ;
4872
4873
4874
4875 WHEN OTHERS THEN
4876
4877 O_err_num := SQLCODE;
4878 O_err_code := NULL;
4879 O_err_msg := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
4880 || to_char(l_stmt_num)
4881 || '): '
4882 ||SQLERRM,1,240);
4883
4884 END pm_process_txn_mmt;
4885
4886 /*----------------------------------------------------------------------------*
4887 | PRIVATE PROCEDURE |
4888 | pm_check_error_mmt |
4889 | |
4890 | DESCRIPTION |
4891 | The procedure validates the transaction to cost collect. The validations|
4892 | it performs are |
4893 | 1. Both the project and task columns for the txn are NOT NULL |
4894 | 2. If the txn is of PO family,the first material SE Exp_type is NOT NULL|
4895 | 3. If the txn is Assy Rtn or Completion or PO Family, the MO SE should |
4896 | all be having their expenditure_type as NOT NULL |
4897 | |
4898 | |
4899 | |
4900 | PARAMETERS |
4901 | |
4902 | p_transaction_id, |
4903 | p_organization_id, |
4904 | p_inventory_item_id, |
4905 | p_avg_rates_cost_type_id, |
4906 | p_transaction_action_id, |
4907 | p_transaction_source_type_id, |
4908 | p_type_class, |
4909 | p_project_id, |
4910 | p_task_id |
4911 | p_to_project_id, |
4912 | p_to_task_id |
4913 | p_source_project_id, |
4914 | p_source_task_id |
4915 | p_transaction_source_id |
4916 | p_proj_job_ind |
4917 | p_process_yn |
4918 | p_first_matl_se_exp_type |
4919 | p_user_id, |
4920 | p_login_id, |
4921 | p_req_id, |
4922 | p_prg_appl_id, |
4923 | p_prg_id, |
4924 | O_err_num, |
4925 | O_err_code, |
4926 | O_err_msg, |
4927 | p_flow_schedule |
4928 | p_cost_group_id |
4929 | |
4930 | CALLED FROM |
4931 | pm_cc_worker_mmt() |
4932 | |
4933 | HISTORY |
4934 | 07-SEP-96 Bhaskar Dasari Created. |
4935 | |
4936 | 20-AUG-97 Hemant Gosain Modified. |
4937 | Added CFM Support by passing parameter p_flow_schedule. |
4938 *----------------------------------------------------------------------------*/
4939
4940 PROCEDURE pm_check_error_mmt (
4941 p_transaction_id NUMBER,
4942 p_organization_id NUMBER,
4943 p_cost_method NUMBER,
4944 p_inventory_item_id NUMBER,
4945 p_avg_rates_cost_type_id NUMBER,
4946 p_transaction_action_id NUMBER,
4947 p_transaction_source_type_id NUMBER,
4948 p_type_class NUMBER,
4949 p_project_id NUMBER,
4950 p_task_id NUMBER,
4951 p_to_project_id NUMBER,
4952 p_to_task_id NUMBER,
4953 p_source_project_id NUMBER,
4954 p_source_task_id NUMBER,
4955 p_transaction_source_id NUMBER,
4956 p_proj_job_ind OUT NOCOPY NUMBER,
4957 p_process_yn OUT NOCOPY NUMBER,
4958 p_first_matl_se_exp_type OUT NOCOPY VARCHAR2,
4959 p_user_id NUMBER,
4960 p_login_id NUMBER,
4961 p_req_id NUMBER,
4962 p_prg_appl_id NUMBER,
4963 p_prg_id NUMBER,
4964 O_err_num OUT NOCOPY NUMBER,
4965 O_err_code OUT NOCOPY VARCHAR2,
4966 O_err_msg OUT NOCOPY VARCHAR2,
4967 p_flow_schedule VARCHAR2,
4968 p_cost_group_id NUMBER)--PJMSTD
4969 IS
4970
4971 l_err_num NUMBER;
4972 l_err_code VARCHAR2(240);
4973 l_err_msg VARCHAR2(240);
4974 l_err_msg_temp VARCHAR2(240);
4975 l_stmt_num NUMBER;
4976 l_proj_job_ind NUMBER;
4977
4978 l_exp_type VARCHAR2(30);
4979 l_error_code VARCHAR2(240);
4980 l_error_explanation VARCHAR2(240);
4981
4982 PROCESS_ERROR EXCEPTION;
4983 SE_EXP_TYPE_NULL EXCEPTION;
4984 NO_FMSE_DEFINED EXCEPTION;
4985 l_debug VARCHAR2(80);
4986
4987 BEGIN
4988 -- initialize local variables
4989 l_err_num := 0;
4990 l_err_code := '';
4991 l_err_msg := '';
4992 l_err_msg_temp := '';
4993 l_stmt_num := 1;
4994
4995 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
4996 if (l_debug = 'Y') then
4997 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_check_error_mmt');
4998 end if;
4999
5000 IF(p_transaction_source_type_id = 5 AND p_source_project_id IS NOT NULL) THEN
5001 l_proj_job_ind := 1;
5002 ELSE
5003 l_proj_job_ind := 0;
5004 END IF;
5005
5006 p_proj_job_ind := l_proj_job_ind;
5007
5008 p_process_yn := 1; /* 1 Implies Process the Txn */
5009 --
5010 -- GENERIC CHECKS
5011 --
5012 -- TXNS demanding knowledge of both project and task ie. NOT NULL
5013
5014 IF p_project_id is not null AND
5015 p_task_id is NULL THEN
5016
5017 l_stmt_num := 20;
5018 fnd_message.set_name('BOM','CST_NO_PROJ_OR_TASK');
5019 l_err_msg := fnd_message.get ;
5020 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5021 || to_char(l_stmt_num)
5022 || '): ';
5023
5024 l_error_explanation := substr(l_err_msg,1,240) ;
5025 l_error_code := l_err_code;
5026
5027
5028 pm_mark_error_mmt ( p_transaction_id,
5029 l_error_code,
5030 l_error_explanation,
5031 p_user_id,
5032 p_login_id,
5033 p_req_id,
5034 p_prg_appl_id,
5035 p_prg_id,
5036 l_err_num,
5037 l_err_code,
5038 l_err_msg);
5039
5040 IF (l_err_num <> 0) THEN
5041 -- Error occured
5042 raise PROCESS_ERROR;
5043 ELSE
5044 p_process_yn := 2;
5045 l_err_num := 20003;
5046 l_err_code := l_error_code;
5047 l_err_msg := l_error_explanation;
5048 raise PROCESS_ERROR;
5049 END IF;
5050 END IF;
5051
5052
5053 IF p_to_project_id is not null AND
5054 p_to_task_id is NULL THEN
5055
5056 l_stmt_num := 30;
5057 fnd_message.set_name('BOM','CST_NO_TRF_PROJ_OR_TASK');
5058 l_err_msg := fnd_message.get ;
5059 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5060 || to_char(l_stmt_num)
5061 || '): ';
5062
5063 l_error_explanation := substr(l_err_msg,1,240) ;
5064 l_error_code := l_err_code;
5065
5066 pm_mark_error_mmt ( p_transaction_id,
5067 l_error_code,
5068 l_error_explanation,
5069 p_user_id,
5070 p_login_id,
5071 p_req_id,
5072 p_prg_appl_id,
5073 p_prg_id,
5074 l_err_num,
5075 l_err_code,
5076 l_err_msg);
5077
5078 IF (l_err_num <> 0) THEN
5079 -- Error occured
5080 raise PROCESS_ERROR;
5081 ELSE
5082 p_process_yn := 2;
5083 l_err_num := 20004;
5084 l_err_code := l_error_code;
5085 l_err_msg := l_error_explanation;
5086 raise PROCESS_ERROR;
5087 END IF;
5088 END IF;
5089
5090 IF ( p_type_class = 1 OR l_proj_job_ind = 1 )
5091 AND ( p_source_project_id is null OR p_source_task_id is NULL ) THEN
5092
5093 l_stmt_num := 40;
5094 fnd_message.set_name('BOM','CST_NO_SOURCE_PROJ_OR_TASK');
5095 l_err_msg := fnd_message.get ;
5096 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5097 || to_char(l_stmt_num)
5098 || '): ';
5099
5100 l_error_explanation := substr(l_err_msg,1,240) ;
5101 l_error_code := l_err_code;
5102
5103 pm_mark_error_mmt ( p_transaction_id,
5104 l_error_code,
5105 l_error_explanation,
5106 p_user_id,
5107 p_login_id,
5108 p_req_id,
5109 p_prg_appl_id,
5110 p_prg_id,
5111 l_err_num,
5112 l_err_code,
5113 l_err_msg);
5114
5115 IF (l_err_num <> 0) THEN
5116 -- Error occured
5117 raise PROCESS_ERROR;
5118 ELSE
5119 p_process_yn := 2;
5120 l_err_num := 20005;
5121 l_err_code := l_error_code;
5122 l_err_msg := l_error_explanation;
5123 raise PROCESS_ERROR;
5124 END IF;
5125 END IF;
5126
5127 -- PJMSTD
5128 IF (p_cost_group_id IS NULL) THEN
5129
5130 l_stmt_num := 45;
5131 fnd_message.set_name('BOM','CST_PAC_CG_INVALID');
5132 l_err_msg := fnd_message.get ;
5133 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5134 || to_char(l_stmt_num)
5135 || '): ';
5136
5137 l_error_explanation := substr(l_err_msg,1,240) ;
5138 l_error_code := l_err_code;
5139
5140 pm_mark_error_mmt ( p_transaction_id,
5141 l_error_code,
5142 l_error_explanation,
5143 p_user_id,
5144 p_login_id,
5145 p_req_id,
5146 p_prg_appl_id,
5147 p_prg_id,
5148 l_err_num,
5149 l_err_code,
5150 l_err_msg);
5151
5152 IF (l_err_num <> 0) THEN
5153 -- Error occured
5154 raise PROCESS_ERROR;
5155 ELSE
5156 p_process_yn := 2;
5157 l_err_num := 20008;
5158 l_err_code := l_error_code;
5159 l_err_msg := l_error_explanation;
5160 raise PROCESS_ERROR;
5161 END IF;
5162
5163 END IF; -- check for NULL CG
5164
5165 --
5166 -- TRANSACTION SPECIFIC CHECKS ----
5167 --
5168 -- TXN requires using the first matl SE logic and the routine returns
5169 -- no valid expenditure type
5170 --
5171 IF (p_transaction_source_type_id = 1
5172 OR p_transaction_action_id = 6)
5173 THEN /*PO Famly FMSE logic,
5174 consigned ownership transfer transaction
5175 --START*/
5176
5177 l_exp_type := NULL;
5178 l_stmt_num := 50;
5179
5180 BEGIN
5181
5182 SELECT decode(br.expenditure_type,NULL,
5183 decode(br1.expenditure_type,NULL,'NO VALUE',
5184 br1.expenditure_type),
5185 br.expenditure_type)
5186 INTO l_exp_type
5187 FROM mtl_parameters mp,
5188 cst_item_cost_details cicd,
5189 bom_resources br,
5190 bom_resources br1
5191 WHERE mp.organization_id = p_organization_id
5192 AND mp.cost_organization_id = cicd.organization_id (+)
5193 AND cicd.inventory_item_id (+) = p_inventory_item_id
5194 AND cicd.cost_type_id (+) = decode(p_cost_method, 1, 1,
5195 p_avg_rates_cost_type_id)
5196 AND cicd.cost_element_id (+) = 1
5197 AND cicd.organization_id = br.organization_id (+)
5198 AND cicd.resource_id = br.resource_id (+)
5199 AND mp.cost_organization_id = br1.organization_id (+)
5200 AND mp.default_material_cost_id = br1.resource_id (+)
5201 AND rownum=1;
5202
5203 EXCEPTION
5204 when NO_DATA_FOUND then
5205 l_exp_type := 'NO VALUE';
5206 END;
5207
5208 IF l_exp_type = 'NO VALUE' THEN
5209
5210 RAISE NO_FMSE_DEFINED;
5211 ELSE
5212 p_first_matl_se_exp_type := l_exp_type;
5213
5214 END IF;
5215
5216 END IF; /* PO Family FMSE logic -- END */
5217
5218 -- TXN demands cost collecting the mo sub-elementally and the ET for
5219 -- the SE was found to be NULL
5220 -- TXNS ARE: PO receipt,adjustment,RTV,Assy completion and Return
5221 -- Consigned ownership transfer transactions
5222
5223 IF (p_transaction_action_id in (31,32)
5224 OR p_transaction_source_type_id = 1
5225 OR p_transaction_action_id = 6)
5226 THEN /*Check MO SE ET START*/
5227
5228
5229 l_stmt_num := 60;
5230 l_exp_type := NULL;
5231
5232 BEGIN
5233 SELECT 'NO VALUE'
5234 INTO l_exp_type
5235 FROM mtl_actual_cost_subelement macs,
5236 bom_resources br
5237 WHERE macs.transaction_id = p_transaction_id
5238 AND macs.organization_id = p_organization_id
5239 AND macs.cost_element_id = 2
5240 AND macs.level_type = 1
5241 AND br.RESOURCE_ID = macs.RESOURCE_ID
5242 AND br.ORGANIZATION_ID = macs.ORGANIZATION_ID
5243 AND br.expenditure_type IS NULL;
5244 EXCEPTION
5245 when NO_DATA_FOUND then
5246 l_exp_type := NULL;
5247 END;
5248
5249 IF l_exp_type = 'NO VALUE' THEN
5250 RAISE SE_EXP_TYPE_NULL;
5251 END IF;
5252
5253 END IF; /*Check MO SE ET END*/
5254
5255 EXCEPTION
5256 WHEN SE_EXP_TYPE_NULL THEN
5257
5258 fnd_message.set_name('BOM','CST_SE_ET_IS_NULL');
5259 l_err_msg := fnd_message.get ;
5260 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5261 || to_char(l_stmt_num)
5262 || '): ';
5263
5264 l_error_explanation := substr(l_err_msg,1,240) ;
5265 l_error_code := l_err_code;
5266
5267 pm_mark_error_mmt ( p_transaction_id,
5268 l_error_code,
5269 l_error_explanation,
5270 p_user_id,
5271 p_login_id,
5272 p_req_id,
5273 p_prg_appl_id,
5274 p_prg_id,
5275 l_err_num,
5276 l_err_code,
5277 l_err_msg);
5278
5279 IF (l_err_num <> 0) THEN
5280 O_err_num := l_err_num;
5281 O_err_code := l_err_code;
5282 O_err_msg := l_err_msg;
5283 ELSE
5284 p_process_yn := 2;
5285 O_err_num := 20006;
5286 O_err_code := l_error_code;
5287 O_err_msg := l_error_explanation;
5288 END IF;
5289
5290 WHEN NO_FMSE_DEFINED THEN
5291
5292 fnd_message.set_name('BOM','CST_NO_FMSE_DEFINED');
5293 l_err_msg := fnd_message.get ;
5294 l_err_code := 'CSTPPCCB.pm_check_error_mmt('
5295 || to_char(l_stmt_num)
5296 || '): ';
5297
5298 l_error_explanation := substr(l_err_msg,1,240) ;
5299 l_error_code := l_err_code;
5300
5301 pm_mark_error_mmt ( p_transaction_id,
5302 l_error_code,
5303 l_error_explanation,
5304 p_user_id,
5305 p_login_id,
5306 p_req_id,
5307 p_prg_appl_id,
5308 p_prg_id,
5309 l_err_num,
5310 l_err_code,
5311 l_err_msg);
5312 p_process_yn := 2;
5313
5314 IF (l_err_num <> 0) THEN
5315 O_err_num := l_err_num;
5316 O_err_code := l_err_code;
5317 O_err_msg := l_err_msg;
5318 ELSE
5319 p_process_yn := 2;
5320 O_err_num := 20007;
5321 O_err_code := l_error_code;
5322 O_err_msg := l_error_explanation;
5323 END IF;
5324
5325 WHEN PROCESS_ERROR THEN
5326 O_err_num := l_err_num;
5327 O_err_code := l_err_code;
5328 O_err_msg := l_err_msg;
5329
5330 WHEN OTHERS THEN
5331 O_err_num := SQLCODE;
5332 O_err_code := NULL;
5333 l_err_msg_temp := 'CSTPPCCB.pm_check_error_mmt('
5334 || to_char(l_stmt_num)
5335 || '): '
5336 || substr(SQLERRM,1,150);
5337
5338 l_err_num := 0;
5339
5340 l_error_explanation := substr(l_err_msg,1,240) ;
5341 l_error_code := l_err_code;
5342
5343 pm_mark_error_mmt(p_transaction_id,
5344 l_error_code,
5345 l_error_explanation,
5346 p_user_id,
5347 p_login_id,
5348 p_req_id,
5349 p_prg_appl_id,
5350 p_prg_id,
5351 l_err_num,
5352 l_err_code,
5353 l_err_msg);
5354 IF (l_err_num <> 0) THEN
5355 O_err_msg := SUBSTR(l_err_msg_temp
5356 ||' * '
5357 ||l_err_msg
5358 ||' * '
5359 ||l_err_code
5360 ||' * '
5361 ||'TXN NOT MARKED IN MMT!'
5362 ,1,240);
5363 ELSE
5364 O_err_msg := SUBSTR(l_err_msg_temp
5365 ||' * '
5366 ||'TXN MARKED IN MMT.'
5367 ,1,240);
5368
5369 END IF;
5370 END pm_check_error_mmt;
5371
5372 /*----------------------------------------------------------------------------*
5373 | PRIVATE PROCEDURE |
5374 | pm_mark_error_mmt |
5375 | |
5376 | DESCRIPTION |
5377 | |
5378 | |
5379 | PARAMETERS |
5380 | |
5381 | p_transaction_id, |
5382 | p_error_code, |
5383 | p_error_explanation, |
5384 | p_user_id, |
5385 | p_login_id, |
5386 | p_req_id, |
5387 | p_prg_appl_id, |
5388 | p_prg_id, |
5389 | O_err_num, |
5390 | O_err_code, |
5391 | O_err_msg |
5392 | |
5393 | CALLED FROM |
5394 | pm_check_error_mmt() |
5395 | |
5396 | HISTORY |
5397 | 07-SEP-96 Bhaskar Dasari Created. |
5398 *----------------------------------------------------------------------------*/
5399
5400 PROCEDURE pm_mark_error_mmt (
5401 p_transaction_id NUMBER,
5402 p_error_code VARCHAR2,
5403 p_error_explanation VARCHAR2,
5404 p_user_id NUMBER,
5405 p_login_id NUMBER,
5406 p_req_id NUMBER,
5407 p_prg_appl_id NUMBER,
5408 p_prg_id NUMBER,
5409 O_err_num OUT NOCOPY NUMBER,
5410 O_err_code OUT NOCOPY VARCHAR2,
5411 O_err_msg OUT NOCOPY VARCHAR2 )
5412
5413 IS
5414
5415 l_err_num NUMBER;
5416 l_err_code VARCHAR2(240);
5417 l_err_msg VARCHAR2(240);
5418 l_stmt_num NUMBER;
5419 l_debug VARCHAR2(80);
5420
5421 BEGIN
5422 -- initialize local variables
5423 l_err_num := 0;
5424 l_err_code := '';
5425 l_err_msg := '';
5426
5427
5428 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
5429 if (l_debug = 'Y') then
5430 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_mark_error_mmt');
5431 end if;
5432
5433 l_stmt_num := 10;
5434
5435 /* update the errorcode and error_explanation fields inspite of the
5436 maintenance of the log file */
5437
5438 UPDATE mtl_material_transactions mmt
5439 SET mmt.pm_cost_collected = 'E',
5440 mmt.error_code = p_error_code,
5441 mmt.error_explanation = p_error_explanation,
5442 mmt.last_update_date = sysdate,
5443 mmt.last_updated_by = p_user_id,
5444 mmt.last_update_login = p_login_id,
5445 mmt.request_id = p_req_id,
5446 mmt.program_application_id = p_prg_appl_id,
5447 mmt.program_id = p_prg_id,
5448 mmt.program_update_date = sysdate
5449 WHERE mmt.transaction_id = p_transaction_id ;
5450 EXCEPTION
5451 WHEN OTHERS THEN
5452 O_err_num := SQLCODE;
5453 O_err_code := NULL;
5454 O_err_msg := 'CSTPPCCB.pm_mark_error_mmt('
5455 || to_char(l_stmt_num)
5456 || '): '
5457 || substr(SQLERRM,1,200);
5458 END pm_mark_error_mmt;
5459
5460 /*----------------------------------------------------------------------------*
5461 | PRIVATE PROCEDURE |
5462 | pm_process_txn_wt |
5463 | |
5464 | DESCRIPTION |
5465 | |
5466 | |
5467 | PARAMETERS |
5468 | |
5469 | p_Group_Id,
5470 p_business_group_name, |
5471 | p_transaction_id, |
5472 | p_organization_id, |
5473 | p_employee_number, |
5474 | p_department_id, |
5475 | p_project_id, |
5476 | p_task_id, |
5477 | p_transaction_date, |
5478 | p_base_transaction_value, |
5479 | p_primary_quantity, |
5480 | p_acct_period_id, |
5481 | p_expenditure_type, |
5482 | p_resource_description, |
5483 | p_wt_transaction_type, |
5484 | p_cost_element_id |
5485 | p_exp_org_name, |
5486 | p_wip_txn_source_literal, |
5487 | p_wip_syslink_literal, |
5488 | p_bur_syslink_literal, |
5489 | O_err_num, |
5490 | O_err_code, |
5491 | O_err_msg, |
5492 | p_reference_account, |
5493 | p_cr_account, |
5494 | p_wip_entity_id, |
5495 | p_resource_id, |
5496 | p_basis_resource_id, |
5497 | p_denom_currency_code |
5498 | |
5499 | CALLED FROM |
5500 | pm_cc_worker_wt() |
5501 | |
5502 | HISTORY |
5503 | 07-SEP-96 Bhaskar Dasari Created. |
5504 | |
5505 | 30-JUL-97 Hemant Gosain Modified. |
5506 | Enhanced to pass accounting information parameters as support|
5507 | for capitalization of projects. |
5508 *----------------------------------------------------------------------------*/
5509
5510 PROCEDURE pm_process_txn_wt (
5511 p_Group_Id NUMBER,
5512 p_business_group_name VARCHAR2,
5513 p_transaction_id NUMBER,
5514 p_organization_id NUMBER,
5515 p_employee_number VARCHAR2,
5516 p_department_id NUMBER,
5517 p_project_id NUMBER,
5518 p_task_id NUMBER,
5519 p_transaction_date DATE,
5520 p_base_transaction_value NUMBER,
5521 p_primary_quantity NUMBER,
5522 p_acct_period_id NUMBER,
5523 p_expenditure_type VARCHAR2,
5524 p_resource_description VARCHAR2,
5525 p_wt_transaction_type NUMBER,
5526 p_cost_element_id NUMBER,
5527 p_exp_org_name VARCHAR2,
5528 p_wip_txn_source_literal VARCHAR2,
5529 p_wip_straight_time_literal VARCHAR2,
5530 p_wip_syslink_literal VARCHAR2,
5531 p_bur_syslink_literal VARCHAR2,
5532 O_err_num OUT NOCOPY NUMBER,
5533 O_err_code OUT NOCOPY VARCHAR2,
5534 O_err_msg OUT NOCOPY VARCHAR2,
5535 p_reference_account NUMBER,
5536 p_cr_account NUMBER,
5537 p_wip_dr_sub_ledger_id NUMBER,
5538 p_wip_cr_sub_ledger_id NUMBER,
5539 p_wip_entity_id NUMBER,
5540 p_resource_id NUMBER,
5541 p_basis_resource_id NUMBER,
5542 p_denom_currency_code VARCHAR2)
5543
5544 IS
5545
5546 l_err_num NUMBER;
5547 l_err_code VARCHAR2(240);
5548 l_err_msg VARCHAR2(240);
5549 l_stmt_num NUMBER;
5550 PROCESS_ERROR EXCEPTION;
5551 CST_FAILED_GET_EXPENDDATE EXCEPTION;
5552 CST_FAILED_HOOK_ACCT EXCEPTION;
5553 CST_FAILED_PROJTSK_VALID EXCEPTION;
5554 l_batch VARCHAR2(15);--Increased width for Bug2218654
5555 l_multi_org_id NUMBER;
5556 /*l_gl_date DATE;*/ /* Commented for bug 6266553 */
5557 l_exp_end_date DATE;
5558 l_project_number VARCHAR2(25);
5559 l_task_number VARCHAR2(25);
5560 l_use_hook_acct BOOLEAN;
5561 l_debug VARCHAR2(80);
5562
5563 l_transaction_source VARCHAR2(30);
5564 l_raw_cost NUMBER;
5565 l_raw_cost_rate NUMBER;
5566 l_burdened_cost_rate NUMBER;
5567 l_burdened_cost NUMBER;
5568 l_dr_code_combination_id NUMBER;
5569 l_cr_code_combination_id NUMBER;
5570 l_wip_cr_sub_ledger_id NUMBER;
5571 l_wip_dr_sub_ledger_id NUMBER;
5572 l_syslinkage VARCHAR2(240);
5573
5574 l_uom_code VARCHAR2(30) ;
5575 l_operating_unit NUMBER;
5576
5577 /* For service line types delivered to shop floor, stamp the amount
5578 in the quantity column and set the cost_rate to 1
5579 (eAM Requirements Project - R12) */
5580
5581 CURSOR c_sel_wt IS
5582
5583 SELECT p_wip_txn_source_literal transaction_source,
5584 l_batch batch_name,
5585 l_exp_end_date expenditure_ending_date,
5586 p_employee_number employee_number,
5587 p_exp_org_name organization_name,
5588 p_transaction_date expenditure_item_date,
5589 l_project_number project_number,
5590 l_task_number task_number,
5591 p_expenditure_type expenditure_type,
5592 p_denom_currency_code denom_currency_code,
5593
5594 decode(p_cost_element_id,
5595 5,0,
5596 decode(p_primary_quantity,
5597 NULL,p_base_transaction_value,
5598 p_primary_quantity)) quantity,
5599 decode(p_cost_element_id,5,0, p_base_transaction_value)
5600 raw_cost,
5601
5602 p_resource_description expenditure_comment,
5603 to_char(p_transaction_id) orig_transaction_reference,
5604
5605 decode(p_cost_element_id,
5606 5,0,
5607 decode(p_primary_quantity,
5608 NULL, 1,
5609 0, p_base_transaction_value,
5610 p_base_transaction_value / p_primary_quantity))
5611 raw_cost_rate,
5612
5613 'Y' unmatched_negative_txn_flag,
5614 p_reference_account dr_code_combination_id,
5615 p_cr_account cr_code_combination_id,
5616 p_wip_dr_sub_ledger_id wip_dr_sub_ledger_id,
5617 p_wip_cr_sub_ledger_id wip_cr_sub_ledger_id,
5618 NULL cdl_system_reference1,
5619 NULL cdl_system_reference2,
5620 NULL cdl_system_reference3,
5621 /*l_gl_date*/ /* Commented for bug 6266553 */ p_transaction_date gl_date,
5622 l_multi_org_id org_id,
5623
5624 p_base_transaction_value burdened_cost,
5625
5626 decode(p_base_transaction_value,0,0,
5627 decode(p_primary_quantity,
5628 NULL,1,
5629 0,p_base_transaction_value,
5630 p_base_transaction_value/p_primary_quantity))
5631 burdened_cost_rate,
5632
5633 decode(p_cost_element_id,5,
5634 p_bur_syslink_literal, p_wip_syslink_literal)
5635 system_linkage,
5636
5637 'P' transaction_status_code
5638
5639 FROM dual
5640 WHERE p_base_transaction_value <> 0;
5641
5642 BEGIN
5643 -- initialize local variables
5644 l_err_num := 0;
5645 l_err_code := '';
5646 l_err_msg := '';
5647 l_use_hook_acct := FALSE;
5648 l_stmt_num := 1;
5649
5650 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
5651 if (l_debug = 'Y') then
5652 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_process_txn_wt');
5653 end if;
5654
5655 -- Initialize the batch name as CC followed by group_id
5656
5657 l_stmt_num := 10;
5658 -- Modified for Bug#2218654
5659 -- Changed for Bug #2260708. PA import fails when you use a 15 character
5660 -- batch name. Instead I am using the last 8 characters of the group id
5661 -- so the batch name remains less than 10 chars. The likelihood of two
5662 -- batch numbers being the same is very low.
5663
5664 SELECT 'CC'|| substr( replace( lpad(
5665 to_char(p_Group_Id,'9999999999999'),14,'0') ,' ','0'),-8)
5666 INTO l_batch
5667 FROM DUAL;
5668
5669 -- get exp ending date for the current transaction's transaction_date
5670 /* Bug 5308514 - Setting the OU context for the current organization */
5671 l_stmt_num := 16;
5672 select org_information3
5673 into l_operating_unit
5674 from hr_organization_information
5675 where organization_id = p_organization_id
5676 and org_information_context ='Accounting Information';
5677
5678 l_stmt_num :=17;
5679 begin
5680 mo_global.set_policy_context('S',l_operating_unit);
5681 end;
5682
5683 l_stmt_num := 20;
5684 l_exp_end_date := pa_utils.GetWeekEnding(p_transaction_date);
5685
5686 IF l_exp_end_date is NULL THEN
5687 RAISE CST_FAILED_GET_EXPENDDATE;
5688 END IF;
5689
5690 /* Commented for bug 6266553
5691 l_stmt_num := 30;
5692 SELECT schedule_close_date
5693 INTO l_gl_date
5694 FROM org_acct_periods oap
5695 WHERE oap.organization_id = p_organization_id
5696 AND oap.acct_period_id = p_acct_period_id;*/
5697
5698 -- Get Proj/Task Number for Proj/Task Ids.
5699 -- Query from PJM_PROJECTS_V and PJM_TASKS_V
5700 -- Refer to Bug# 571127
5701
5702 ----------------------------------------------------------------------
5703 -- MOAC Changes for R12:
5704 -- References to PJM_PROJECTS_V and PJM_TASKS_V has been removed and
5705 -- their base table pa_projects_all and pa_tasks are used instead.
5706 ----------------------------------------------------------------------
5707
5708 BEGIN
5709 l_stmt_num := 35;
5710 IF p_project_id is NOT NULL then
5711 SELECT segment1 -- project number
5712 INTO l_project_number
5713 FROM pa_projects_all
5714 WHERE project_id = p_project_id;
5715
5716 l_stmt_num := 36;
5717
5718 SELECT task_number
5719 INTO l_task_number
5720 FROM pa_tasks
5721 WHERE project_id = p_project_id
5722 AND task_id = p_task_id;
5723 END IF;
5724 EXCEPTION
5725 WHEN OTHERS THEN
5726 l_err_msg := SUBSTR(SQLERRM,1,200);
5727 RAISE CST_FAILED_PROJTSK_VALID;
5728 END;
5729
5730 -- assign multi_org_id
5731
5732 l_stmt_num := 40;
5733
5734 /* bug 3742735. The org_id passed should be the org_id where the transaction happened and not the OU on the project. */
5735
5736 select to_number(org_information3)
5737 into l_multi_org_id
5738 from hr_organization_information
5739 where organization_id = p_organization_id
5740 and org_information_context ='Accounting Information';
5741
5742
5743 l_stmt_num := 50;
5744
5745 FOR c_rec IN c_sel_wt LOOP
5746
5747 /* The following changes are for the support of blue print enabled organizations */
5748 If (p_wip_txn_source_literal = 'PJM_CSTBP_WIP_ACCOUNTS')
5749 OR (p_wip_txn_source_literal = 'PJM_CSTBP_WIP_NO_ACCOUNTS') then
5750 /* Blue print enabled org, so pass as raw */
5751
5752 l_raw_cost_rate := c_rec.burdened_cost_rate;
5753 l_raw_cost := c_rec.burdened_cost;
5754 l_burdened_cost_rate := NULL;
5755 l_burdened_cost := NULL;
5756
5757 Else /* non BP org */
5758
5759 l_raw_cost_rate := c_rec.raw_cost_rate;
5760 l_raw_cost := c_rec.raw_cost;
5761 l_burdened_cost_rate := c_rec.burdened_cost_rate;
5762 l_burdened_cost := c_rec.burdened_cost;
5763
5764 End If;
5765
5766 l_stmt_num := 56;
5767
5768 /* check for the transaction source to be "WIP with No Accounts". If it is
5769 then dont send the accounts */
5770
5771 If p_wip_txn_source_literal = 'PJM_CSTBP_WIP_NO_ACCOUNTS' then
5772
5773 l_dr_code_combination_id := NULL;
5774 l_cr_code_combination_id := NULL;
5775
5776 l_wip_dr_sub_ledger_id := NULL;
5777 l_wip_cr_sub_ledger_id := NULL;
5778
5779 else
5780
5781 l_dr_code_combination_id := c_rec.dr_code_combination_id;
5782 l_cr_code_combination_id := c_rec.cr_code_combination_id;
5783
5784 l_wip_dr_sub_ledger_id := c_rec.wip_dr_sub_ledger_id;
5785 l_wip_cr_sub_ledger_id := c_rec.wip_cr_sub_ledger_id;
5786
5787 end if;
5788
5789 l_stmt_num := 57;
5790
5791 /* now check if the transaction has an employee on it .If yes then stamp it with "Straight time" source*/
5792
5793
5794 /* Bug #3449856. Use the transaction source of straight time only for
5795 * resource cost element. If there is a resource based overhead, it
5796 * should be passed with a transaction source of WIP. */
5797 If c_rec.employee_number is NOT NULL and p_cost_element_id <> 5 then
5798
5799 fnd_file.put_line(fnd_file.log,'Setting Straight time');
5800 fnd_file.put_line(fnd_file.log,p_wip_straight_time_literal);
5801 l_transaction_source := p_wip_straight_time_literal ;
5802
5803 /* set the sys linkage to the system linkage to which this transaction source maps to
5804 (usually this transaction source should map to the straight time system linkage) */
5805
5806 Select NVL(system_linkage_function,c_rec.system_linkage) into l_syslinkage
5807 from pa_transaction_sources
5808 where transaction_source = l_transaction_source;
5809
5810 else
5811
5812 l_transaction_source := p_wip_txn_source_literal ;
5813 l_syslinkage := c_rec.system_linkage;
5814
5815 End If;
5816
5817 l_stmt_num := 60;
5818
5819 /* bug 3345746 for Blue Print organizations the system linkage should be WIP even for overhead costs(BTC) as the
5820 transaction sources do not allow burdening in MFG (allow_burden_flag = 'N') */
5821
5822 If (l_transaction_source = 'PJM_CSTBP_WIP_ACCOUNTS') OR (l_transaction_source = 'PJM_CSTBP_WIP_NO_ACCOUNTS')
5823 OR (l_transaction_source = 'PJM_CSTBP_ST_ACCOUNTS') OR (l_transaction_source = 'PJM_CSTBP_ST_NO_ACCOUNTS') then
5824
5825 If l_syslinkage = p_bur_syslink_literal then
5826 l_syslinkage := p_wip_syslink_literal ;
5827 end if;
5828
5829 end If;
5830
5831
5832
5833 l_stmt_num := 62;
5834
5835
5836 /* This following insert statement into pa_transaction_interface will be changes to insert into pa_transaction_interface_all */
5837
5838 /* modify the insert statement to insert the wip_resource_id and primary UOM code bug 3298023 */
5839
5840 /* get the primary UOM code directly from the transaction */
5841
5842 select primary_uom into l_uom_code
5843 from wip_transactions
5844 where transaction_id = p_transaction_id ;
5845
5846 If l_debug = 'Y' then
5847 fnd_file.put_line(fnd_file.log,' UOM code for the WIP txn : ' || l_uom_code);
5848 fnd_file.put_line(fnd_file.log,' Quantity : ' || c_rec.quantity);
5849 fnd_file.put_line(fnd_file.log,' Raw Cost Rate : ' || l_raw_cost_rate);
5850 end If;
5851
5852 /* This following insert statement into pa_transaction_interface will be changes to insert into pa_transaction_interface_all */
5853
5854 INSERT INTO pa_transaction_interface_all
5855 ( transaction_source,
5856 batch_name,
5857 expenditure_ending_date,
5858 employee_number,
5859 organization_name,
5860 expenditure_item_date,
5861 project_number,
5862 task_number,
5863 expenditure_type,
5864 quantity,
5865 denom_raw_cost,
5866 acct_raw_cost,
5867 expenditure_comment,
5868 orig_transaction_reference,
5869 raw_cost_rate,
5870 unmatched_negative_txn_flag,
5871 dr_code_combination_id,
5872 cr_code_combination_id,
5873 cdl_system_reference1,
5874 cdl_system_reference2,
5875 cdl_system_reference3,
5876 gl_date,
5877 org_id,
5878 denom_burdened_cost,
5879 acct_burdened_cost,
5880 burdened_cost_rate,
5881 system_linkage,
5882 transaction_status_code,
5883 denom_currency_code,
5884 person_business_group_name,
5885 wip_resource_id,
5886 unit_of_measure,
5887 cdl_system_reference4, --WIP cr. sub Ledger ID
5888 cdl_system_reference5 --WIP Dr. sub LEDGER ID
5889 )
5890 VALUES
5891 ( l_transaction_source,
5892 c_rec.batch_name,
5893 c_rec.expenditure_ending_date,
5894 c_rec.employee_number,
5895 c_rec.organization_name,
5896 c_rec.expenditure_item_date,
5897 c_rec.project_number,
5898 c_rec.task_number,
5899 c_rec.expenditure_type,
5900 c_rec.quantity,
5901 l_raw_cost,
5902 l_raw_cost,
5903 c_rec.expenditure_comment,
5904 c_rec.orig_transaction_reference,
5905 l_raw_cost_rate,
5906 c_rec.unmatched_negative_txn_flag,
5907 l_dr_code_combination_id,
5908 l_cr_code_combination_id,
5909 c_rec.cdl_system_reference1,
5910 c_rec.cdl_system_reference2,
5911 c_rec.cdl_system_reference3,
5912 c_rec.gl_date,
5913 c_rec.org_id,
5914 l_burdened_cost,
5915 l_burdened_cost,
5916 l_burdened_cost_rate,
5917 l_syslinkage,
5918 c_rec.transaction_status_code,
5919 c_rec.denom_currency_code,
5920 p_business_group_name,
5921 p_resource_id,
5922 l_uom_code,
5923 l_wip_cr_sub_ledger_id,
5924 l_wip_dr_sub_ledger_id
5925 );
5926 END LOOP;
5927
5928 EXCEPTION
5929 WHEN CST_FAILED_GET_EXPENDDATE THEN
5930 O_err_num := 20001;
5931
5932 fnd_message.set_name('BOM','CST_FAILED_GET_EXPENDDATE');
5933 l_err_msg := fnd_message.get ;
5934 O_err_msg := substr(l_err_msg,1,240) ;
5935
5936 O_err_code := 'CSTPPCCB.pm_process_txn_wt('
5937 || to_char(l_stmt_num)
5938 || '): ';
5939
5940 WHEN PROCESS_ERROR THEN
5941 O_err_num := l_err_num;
5942 O_err_code := l_err_code;
5943 O_err_msg := l_err_msg;
5944
5945 WHEN CST_FAILED_HOOK_ACCT THEN
5946 O_err_num := 20002;
5947
5948 fnd_message.set_name('BOM','CST_FAILED_HOOK_ACCT');
5949 l_err_msg := fnd_message.get ;
5950 O_err_msg := substr(l_err_msg,1,240) ;
5951
5952 O_err_code := 'CSTPPCCB.pm_process_txn_wt('
5953 || to_char(l_stmt_num)
5954 || '): '
5955 || ' WIP Transaction_Id: '
5956 || to_char(p_transaction_id)
5957 || ' Organization_Id: '
5958 || to_char(p_organization_id);
5959
5960 WHEN CST_FAILED_PROJTSK_VALID THEN
5961 O_err_num := 20003;
5962 /*
5963 fnd_message.set_name('BOM','CST_FAILED_PROJTSK_VALID');
5964 l_err_msg := fnd_message.get ;
5965 O_err_msg := substr(l_err_msg,1,240) ;
5966 */
5967 O_err_msg := 'Proj/Task Invalid for Cost Collection.';
5968 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_wt('
5969 || to_char(l_stmt_num)
5970 || '): '
5971 ||l_err_msg,1,240);
5972
5973
5974 WHEN OTHERS THEN
5975 O_err_num := SQLCODE;
5976 O_err_code := NULL;
5977 O_err_msg := SUBSTR('CSTPPCCB.pm_process_txn_wt('
5978 || to_char(l_stmt_num)
5979 || '): '
5980 || SQLERRM,1,240);
5981 END pm_process_txn_wt;
5982
5983 /*----------------------------------------------------------------------------*
5984 | PRIVATE PROCEDURE |
5985 | pm_check_error_wt |
5986 | |
5987 | DESCRIPTION |
5988 | The procedure validates the transaction to cost collect. The validations|
5989 | it performs are |
5990 | 1. Both the project and task columns for the txn are NOT NULL |
5991 | 2. If the expenditure type for the Transactions Resource Id is not NULL |
5992 | 3. If the employee id is null, pa is informed the pa_expenditure_org_id |
5993 | which needs to be NOT NULL for the department in which the non labor|
5994 | resource was used |
5995 | |
5996 | PARAMETERS |
5997 | p_transaction_id, |
5998 | p_project_id, |
5999 | p_task_id |
6000 | p_expenditure_type |
6001 | p_organization_id |
6002 | p_department_id |
6003 | p_employee_number |
6004 | p_user_id, |
6005 | p_login_id, |
6006 | p_req_id, |
6007 | p_prg_appl_id, |
6008 | p_prg_id, |
6009 | O_err_num, |
6010 | O_err_code, |
6011 | O_err_msg |
6012 | |
6013 | CALLED FROM |
6014 | pm_cc_worker_wt() |
6015 | |
6016 | HISTORY |
6017 | 07-SEP-96 Bhaskar Dasari Created. |
6018 *----------------------------------------------------------------------------*/
6019
6020 PROCEDURE pm_check_error_wt (
6021 p_transaction_id NUMBER,
6022 p_project_id NUMBER,
6023 p_task_id NUMBER,
6024 p_expenditure_type VARCHAR2,
6025 p_organization_id NUMBER,
6026 p_department_id NUMBER,
6027 p_employee_number VARCHAR2,
6028 p_exp_org_name OUT NOCOPY VARCHAR2,
6029 p_process_yn OUT NOCOPY NUMBER,
6030 p_user_id NUMBER,
6031 p_login_id NUMBER,
6032 p_req_id NUMBER,
6033 p_prg_appl_id NUMBER,
6034 p_prg_id NUMBER,
6035 O_err_num OUT NOCOPY NUMBER,
6036 O_err_code OUT NOCOPY VARCHAR2,
6037 O_err_msg OUT NOCOPY VARCHAR2)
6038 IS
6039
6040 l_dummy NUMBER;
6041 l_err_num NUMBER;
6042 l_err_code VARCHAR2(240);
6043 l_err_msg VARCHAR2(240);
6044 l_err_msg_temp VARCHAR2(240);
6045 l_stmt_num NUMBER;
6046 PROCESS_ERROR EXCEPTION;
6047 CST_NO_EXP_ORG_FOR_DEPT EXCEPTION;
6048
6049 --UTF8 changes l_organization_name VARCHAR2(60);
6050 l_organization_name hr_organization_units.name%TYPE;
6051 l_exp_type VARCHAR2(30);
6052 l_error_code VARCHAR2(240);
6053 l_error_explanation VARCHAR2(240);
6054 l_debug VARCHAR2(80);
6055
6056 l_err_in_code VARCHAR2(240);
6057 l_err_in_msg VARCHAR2(240);
6058
6059 BEGIN
6060 -- initialize local variables
6061 l_err_num := 0;
6062 l_err_code := '';
6063 l_err_msg := '';
6064 l_err_msg_temp := '';
6065 l_organization_name := '';
6066
6067 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
6068 if (l_debug = 'Y') then
6069 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_check_error_wt');
6070 end if;
6071
6072 p_process_yn := 1; /* 1 Implies Process the Txn */
6073 --
6074 -- GENERIC CHECKS
6075 --
6076 -- TXNS demanding knowledge of both project and task ie. NOT NULL
6077
6078 l_stmt_num := 10;
6079 IF p_task_id is NULL THEN
6080
6081 fnd_message.set_name('BOM','CST_NO_PROJ_OR_TASK');
6082 l_err_msg := fnd_message.get ;
6083 l_err_code := 'CSTPPCCB.pm_check_error_wt('
6084 || to_char(l_stmt_num)
6085 || '): ';
6086
6087 l_error_explanation := substr(l_err_msg,1,240) ;
6088 l_error_code := l_err_code;
6089
6090 pm_mark_error_wt ( p_transaction_id,
6091 l_error_code,
6092 l_error_explanation,
6093 p_user_id,
6094 p_login_id,
6095 p_req_id,
6096 p_prg_appl_id,
6097 p_prg_id,
6098 l_err_num,
6099 l_err_code,
6100 l_err_msg);
6101
6102 IF (l_err_num <> 0) THEN
6103 -- Error occured
6104 raise PROCESS_ERROR;
6105 ELSE
6106 p_process_yn := 2;
6107 l_err_num := 20003;
6108 l_err_code := l_error_code;
6109 l_err_msg := l_error_explanation;
6110 raise PROCESS_ERROR;
6111 END IF;
6112 END IF;
6113
6114 l_stmt_num := 20;
6115 IF p_expenditure_type is NULL THEN
6116
6117 fnd_message.set_name('BOM','CST_SE_ET_IS_NULL');
6118 l_err_msg := fnd_message.get ;
6119 l_err_code := 'CSTPPCCB.pm_check_error_wt('
6120 || to_char(l_stmt_num)
6121 || '): ';
6122
6123 l_error_explanation := substr(l_err_msg,1,240) ;
6124 l_error_code := l_err_code;
6125
6126 pm_mark_error_wt ( p_transaction_id,
6127 l_error_code,
6128 l_error_explanation,
6129 p_user_id,
6130 p_login_id,
6131 p_req_id,
6132 p_prg_appl_id,
6133 p_prg_id,
6134 l_err_num,
6135 l_err_code,
6136 l_err_msg);
6137
6138 IF (l_err_num <> 0) THEN
6139 -- Error occured
6140 raise PROCESS_ERROR;
6141 ELSE
6142 p_process_yn := 2;
6143 l_err_num := 20006;
6144 l_err_code := l_error_code;
6145 l_err_msg := l_error_explanation;
6146 raise PROCESS_ERROR;
6147 END IF;
6148 END IF;
6149
6150 l_organization_name := NULL;
6151 if p_employee_number is NULL THEN
6152 BEGIN
6153 l_stmt_num := 30;
6154 SELECT hou.name
6155 INTO l_organization_name
6156 FROM bom_departments bd,
6157 hr_organization_units hou
6158 WHERE hou.organization_id =
6159 bd.pa_expenditure_org_id
6160 AND bd.organization_id = p_organization_id
6161 AND bd.department_id = p_department_id;
6162 EXCEPTION
6163 when NO_DATA_FOUND then
6164 l_organization_name := 'NO VALUE';
6165 END;
6166 END IF;
6167
6168 IF l_organization_name = 'NO VALUE' THEN
6169 RAISE CST_NO_EXP_ORG_FOR_DEPT;
6170 ELSE
6171 p_exp_org_name := l_organization_name;
6172 END IF;
6173
6174 EXCEPTION
6175
6176 WHEN CST_NO_EXP_ORG_FOR_DEPT THEN
6177
6178 fnd_message.set_name('BOM','CST_NO_EXP_ORG_FOR_DEPT');
6179 l_err_msg := fnd_message.get ;
6180 l_err_code := 'CSTPPCCB.pm_check_error_wt('
6181 || to_char(l_stmt_num)
6182 || '): ';
6183
6184 l_error_explanation := substr(l_err_msg,1,240) ;
6185 l_error_code := l_err_code;
6186
6187 pm_mark_error_wt ( p_transaction_id,
6188 l_error_code,
6189 l_error_explanation,
6190 p_user_id,
6191 p_login_id,
6192 p_req_id,
6193 p_prg_appl_id,
6194 p_prg_id,
6195 l_err_num,
6196 l_err_code,
6197 l_err_msg);
6198
6199 IF (l_err_num <> 0) THEN
6200 O_err_num := l_err_num;
6201 O_err_code := l_err_code;
6202 O_err_msg := l_err_msg;
6203 ELSE
6204 p_process_yn := 2;
6205 O_err_num := 20008;
6206 O_err_code := l_error_code;
6207 O_err_msg := l_error_explanation;
6208 END IF;
6209
6210 WHEN PROCESS_ERROR THEN
6211
6212 O_err_num := l_err_num;
6213 O_err_code := l_err_code;
6214 O_err_msg := l_err_msg;
6215
6216 WHEN OTHERS THEN
6217 O_err_num := SQLCODE;
6218 O_err_code := NULL;
6219 l_err_msg_temp := 'CSTPPCCB.pm_check_error_wt('
6220 || to_char(l_stmt_num)
6221 || '): '
6222 || substr(SQLERRM,1,150);
6223
6224 l_err_num := 0;
6225
6226 l_err_in_code := l_err_code;
6227 l_err_in_msg := l_err_msg;
6228
6229 pm_mark_error_wt(p_transaction_id,
6230 l_err_in_code,
6231 l_err_in_msg,
6232 p_user_id,
6233 p_login_id,
6234 p_req_id,
6235 p_prg_appl_id,
6236 p_prg_id,
6237 l_err_num,
6238 l_err_code,
6239 l_err_msg);
6240 IF (l_err_num <> 0) THEN
6241 O_err_msg := SUBSTR(l_err_msg_temp
6242 ||' * '
6243 ||l_err_msg
6244 ||' * '
6245 ||l_err_code
6246 ||' * '
6247 ||'TXN NOT MARKED IN WTIE!'
6248 ,1,240);
6249 ELSE
6250 O_err_msg := SUBSTR(l_err_msg_temp
6251 ||' * '
6252 ||'TXN MARKED IN WTIE.'
6253 ,1,240);
6254
6255 END IF;
6256 END pm_check_error_wt;
6257
6258 /*----------------------------------------------------------------------------*
6259 | PRIVATE PROCEDURE |
6260 | pm_mark_error_wt |
6261 | |
6262 | DESCRIPTION |
6263 | |
6264 | |
6265 | PARAMETERS |
6266 | |
6267 | p_transaction_id, |
6268 | p_error_code, |
6269 | p_error_explanation, |
6270 | p_user_id, |
6271 | p_login_id, |
6272 | p_req_id, |
6273 | p_prg_appl_id, |
6274 | p_prg_id, |
6275 | O_err_num, |
6276 | O_err_code, |
6277 | O_err_msg |
6278 | |
6279 | CALLED FROM |
6280 | pm_check_error_wt() |
6281 | |
6282 | HISTORY |
6283 | 07-SEP-96 Bhaskar Dasari Created. |
6284 *----------------------------------------------------------------------------*/
6285
6286 PROCEDURE pm_mark_error_wt (
6287 p_transaction_id NUMBER,
6288 p_error_code VARCHAR2,
6289 p_error_explanation VARCHAR2,
6290 p_user_id NUMBER,
6291 p_login_id NUMBER,
6292 p_req_id NUMBER,
6293 p_prg_appl_id NUMBER,
6294 p_prg_id NUMBER,
6295 O_err_num OUT NOCOPY NUMBER,
6296 O_err_code OUT NOCOPY VARCHAR2,
6297 O_err_msg OUT NOCOPY VARCHAR2)
6298
6299 IS
6300
6301 l_err_num NUMBER;
6302 l_err_code VARCHAR2(240);
6303 l_err_msg VARCHAR2(240);
6304 l_stmt_num NUMBER;
6305 l_debug VARCHAR2(80);
6306
6307 BEGIN
6308 -- initialize local variables
6309 l_err_num := 0;
6310 l_err_code := '';
6311 l_err_msg := '';
6312 l_stmt_num := 1;
6313
6314 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
6315 if (l_debug = 'Y') then
6316 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_mark_error_wt ' );
6317 end if;
6318
6319
6320 l_stmt_num := 10;
6321
6322 UPDATE wip_transactions wt
6323 SET wt.pm_cost_collected = 'E',
6324 wt.last_update_date = sysdate,
6325 wt.last_updated_by = p_user_id,
6326 wt.last_update_login = p_login_id,
6327 wt.request_id = p_req_id,
6328 wt.program_application_id = p_prg_appl_id,
6329 wt.program_id = p_prg_id,
6330 wt.program_update_date = sysdate
6331 WHERE wt.transaction_id = p_transaction_id ;
6332
6333 l_stmt_num := 20;
6334 UPDATE wip_txn_interface_errors wtie
6335 SET wtie.error_message = p_error_explanation,
6336 wtie.last_update_date = sysdate,
6337 wtie.last_updated_by = p_user_id,
6338 wtie.last_update_login = p_login_id,
6339 wtie.request_id = p_req_id,
6340 wtie.program_application_id = p_prg_appl_id,
6341 wtie.program_id = p_prg_id,
6342 wtie.program_update_date = sysdate
6343 WHERE wtie.error_column='PM_COST_COLLECTED'
6344 AND wtie.transaction_id = p_transaction_id;
6345
6346 IF SQL%NOTFOUND THEN
6347
6348 l_stmt_num := 30;
6349 INSERT INTO wip_txn_interface_errors
6350 ( transaction_id,
6351 error_message,
6352 error_column,
6353 last_update_date,
6354 last_updated_by,
6355 creation_date,
6356 created_by,
6357 last_update_login,
6358 request_id,
6359 program_application_id,
6360 program_id,
6361 program_update_date
6362 )
6363 VALUES ( p_transaction_id,
6364 p_error_explanation,
6365 'PM_COST_COLLECTED',
6366 sysdate,
6367 p_user_id,
6368 sysdate,
6369 p_user_id,
6370 p_login_id,
6371 p_req_id,
6372 p_prg_appl_id,
6373 p_prg_id,
6374 sysdate
6375 );
6376 END IF;
6377
6378 EXCEPTION
6379 WHEN OTHERS THEN
6380 O_err_num := SQLCODE;
6381 O_err_code := NULL;
6382 O_err_msg := 'CSTPPCCB.pm_mark_error_wt('
6383 || to_char(l_stmt_num)
6384 || '): '
6385 || substr(SQLERRM,1,200);
6386 END pm_mark_error_wt;
6387
6388 /*----------------------------------------------------------------------------*
6389 | PUBLIC PROCEDURE |
6390 | pm_get_mta_accts() |
6391 | |
6392 | DESCRIPTION |
6393 | This procedure returns the ccid from the manufacturing |
6394 | accounting distribution table (MTA). The parameters |
6395 | passed to this procedure relate to records in mcacd/cicd. |
6396 | Since project interface is only concerned with the dr column,|
6397 | the accounting information is extracted from mta based on |
6398 | the sign of primary transaction quantity. Based on |
6399 | transaction specific distribution, accounting line type is |
6400 | passed to obtain the account that will be populated in the |
6401 | credit column of project interface table. |
6402 | |
6403 | |
6404 | CALLED FROM |
6405 | pm_process_txn_mmt() |
6406 -----------------------------------------------------------------------------*/
6407
6408 PROCEDURE pm_get_mta_accts (
6409 p_transaction_id NUMBER,
6410 p_cost_element_id NUMBER,
6411 p_resource_id NUMBER,
6412 p_source_flag NUMBER,
6413 p_variance_flag NUMBER,
6414 O_dr_code_combination_id IN OUT NOCOPY NUMBER,
6415 O_cr_code_combination_id IN OUT NOCOPY NUMBER,
6416 O_inv_cr_sub_ledger_id OUT NOCOPY NUMBER,
6417 O_inv_dr_sub_ledger_id OUT NOCOPY NUMBER,
6418 O_err_num OUT NOCOPY NUMBER,
6419 O_err_code OUT NOCOPY VARCHAR2,
6420 O_err_msg OUT NOCOPY VARCHAR2)
6421 IS
6422
6423 l_transaction_action_id NUMBER;
6424 l_transaction_source_type_id NUMBER;
6425 l_organization_id NUMBER;
6426 l_mta_organization_id NUMBER;
6427 l_mta_transaction_id NUMBER;
6428 l_source_flag NUMBER;
6429 l_citw_flag NUMBER;
6430 l_xfer_organization_id NUMBER;
6431 l_xfer_transaction_id NUMBER;
6432 l_subinventory_code VARCHAR2(11);
6433 l_transfer_subinventory VARCHAR2(11);
6434 l_inventory_item_id NUMBER;
6435 l_type_class NUMBER;
6436 l_fob_point NUMBER;
6437 l_si_asset_yes_no NUMBER;
6438 l_transfer_si_asset_yes_no NUMBER;
6439 l_exp_flag NUMBER;
6440 l_exp_item NUMBER;
6441 l_xfer_exp_flag NUMBER;
6442 l_accounting_line_type NUMBER;
6443 l_cost_element_id NUMBER;
6444 l_mta_primary_quantity NUMBER;
6445 l_mmt_primary_quantity NUMBER;
6446 l_resource_id NUMBER;
6447 l_cg_id NUMBER;
6448 l_xfer_cg_id NUMBER;
6449 l_stmt_num NUMBER;
6450 l_txn_type_id NUMBER;
6451 l_debug VARCHAR2(80);
6452 l_cost_method NUMBER;
6453 l_xfer_cost_method NUMBER;
6454 l_blue_print_enabled VARCHAR2(1);
6455 l_autoaccounting_flag VARCHAR2(1);
6456 l_wip_txn_source_type NUMBER;
6457
6458 CST_NO_ACCOUNT_FOUND EXCEPTION;
6459
6460 BEGIN
6461
6462 O_dr_code_combination_id := -999999;
6463 O_cr_code_combination_id := -999999;
6464 l_accounting_line_type := -99;
6465 l_cost_element_id := -99;
6466 l_mmt_primary_quantity := 0;
6467 l_stmt_num := 0;
6468 l_xfer_cost_method := 0;
6469 l_wip_txn_source_type := '';
6470
6471 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
6472 if (l_debug = 'Y') then
6473 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#: pm_get_mta_accts');
6474 end if;
6475
6476 BEGIN
6477 /****** Get Transaction Information ******/
6478 l_stmt_num := 5;
6479 SELECT
6480 mmt.transaction_action_id,
6481 mmt.transaction_source_type_id,
6482 mmt.organization_id,
6483 mmt.transfer_organization_id,
6484 mmt.transfer_transaction_id,
6485 mmt.cost_group_id,
6486 mmt.transfer_cost_group_id,
6487 mmt.transfer_subinventory,
6488 mmt.inventory_item_id,
6489 mmt.primary_quantity,
6490 mmt.transaction_type_id,
6491 mtt.type_class
6492 INTO l_transaction_action_id,
6493 l_transaction_source_type_id,
6494 l_organization_id,
6495 l_xfer_organization_id,
6496 l_xfer_transaction_id,
6497 l_cg_id,
6498 l_xfer_cg_id,
6499 l_transfer_subinventory,
6500 l_inventory_item_id,
6501 l_mmt_primary_quantity,
6502 l_txn_type_id,
6503 l_type_class
6504 FROM mtl_material_transactions mmt,
6505 mtl_transaction_types mtt
6506 WHERE mmt.transaction_id = p_transaction_id
6507 AND mtt.transaction_type_id = mmt.transaction_type_id;
6508
6509 IF l_transaction_action_id <> 17 THEN
6510 l_stmt_num := 10;
6511 SELECT mmt.subinventory_code,
6512 msi.asset_inventory
6513 INTO
6514 l_subinventory_code,
6515 l_si_asset_yes_no
6516 FROM MTL_MATERIAL_TRANSACTIONS mmt,
6517 MTL_SECONDARY_INVENTORIES msi
6518 WHERE
6519 mmt.transaction_id = p_transaction_id
6520 AND msi.secondary_inventory_name = mmt.subinventory_code
6521 AND msi.organization_id = mmt.organization_id;
6522
6523 l_stmt_num := 15;
6524 -- Get Item Expense Flag
6525 SELECT decode(inventory_asset_flag, 'Y',0,1)
6526 INTO l_exp_item
6527 FROM mtl_system_items msi
6528 WHERE msi.inventory_item_id = l_inventory_item_id
6529 AND msi.organization_id = l_organization_id;
6530
6531 l_stmt_num := 20;
6532 -- Set Expense Flag
6533 SELECT decode(l_exp_item,1,1,decode(l_si_asset_yes_no,1,0,1))
6534 INTO l_exp_flag
6535 FROM mtl_secondary_inventories msi
6536 WHERE msi.secondary_inventory_name = l_subinventory_code
6537 AND msi.organization_id = l_organization_id;
6538 ELSE
6539 l_subinventory_code := NULL;
6540 l_si_asset_yes_no := 0;
6541 l_exp_item := 1;
6542 l_exp_flag := 1;
6543 END IF;
6544
6545
6546 l_stmt_num := 25;
6547 /****** Set l_xfer_exp_flag ******/
6548 IF (l_transfer_subinventory IS NOT NULL) THEN
6549 SELECT msub.asset_inventory,
6550 decode(mitems.inventory_asset_flag,
6551 'Y', decode(msub.asset_inventory,1,0,1), 1)
6552 INTO l_transfer_si_asset_yes_no,
6553 l_xfer_exp_flag
6554 FROM mtl_secondary_inventories msub,
6555 mtl_system_items mitems
6556 WHERE msub.secondary_inventory_name = l_transfer_subinventory
6557 AND msub.organization_id = l_xfer_organization_id
6558 AND mitems.inventory_item_id = l_inventory_item_id
6559 AND mitems.organization_id = l_xfer_organization_id;
6560 END IF;
6561
6562 -- Modified for fob stamping project
6563 l_stmt_num := 30;
6564 /****** Get FOB POINT ******/
6565 IF (l_xfer_organization_id IS NOT NULL) THEN
6566 IF l_transaction_action_id = 21 THEN /* Intransit Shipment */
6567 SELECT nvl(MMT.fob_point, MSNV.fob_point) INTO l_fob_point
6568 FROM mtl_shipping_network_view MSNV,
6569 mtl_material_transactions MMT
6570 WHERE MSNV.from_organization_id = l_organization_id
6571 AND MSNV.to_organization_id = l_xfer_organization_id
6572 AND MMT.transaction_id = p_transaction_id;
6573 ELSIF l_transaction_action_id = 12 THEN /* Intransit Receipt */
6574 SELECT nvl(MMT.fob_point, MSNV.fob_point)
6575 INTO l_fob_point
6576 FROM mtl_shipping_network_view MSNV,
6577 mtl_material_transactions MMT
6578 WHERE MSNV.from_organization_id = l_xfer_organization_id
6579 AND MSNV.to_organization_id = l_organization_id
6580 AND MMT.transaction_id = p_transaction_id;
6581 END IF;
6582 END IF;
6583
6584 l_stmt_num := 35;
6585 /* Bug #2128760. CITW only applies to average costing orgs */
6586 SELECT primary_cost_method
6587 INTO l_cost_method
6588 FROM mtl_parameters
6589 WHERE organization_id = l_organization_id;
6590
6591 l_stmt_num := 40;
6592 /* Check for standard to standard direct interorg transfers. In this case
6593 the accounting entries are all made against the sending transaction_id. */
6594 IF (l_xfer_organization_id IS NOT NULL) THEN
6595 SELECT primary_cost_method
6596 INTO l_xfer_cost_method
6597 FROM mtl_parameters
6598 WHERE organization_id = l_xfer_organization_id;
6599 END IF;
6600
6601 l_stmt_num := 45;
6602 /****** Set CITW FLAG ******/
6603 IF (l_transaction_action_id = 1 AND l_transaction_source_type_id = 5
6604 AND l_cg_id <> NVL(l_xfer_cg_id,-9)
6605 AND l_xfer_cg_id IS NOT NULL
6606 AND l_cost_method = 2) THEN
6607 l_citw_flag := 1;
6608 ELSE
6609 l_citw_flag := -1;
6610 END IF;
6611
6612 l_stmt_num := 50;
6613 /****** Start Dr Account Processing ******/
6614 l_source_flag := p_source_flag;
6615 l_mta_transaction_id := p_transaction_id;
6616 l_mta_organization_id := l_organization_id;
6617
6618 IF (l_source_flag = 1) THEN
6619 IF l_type_class = 1 THEN
6620 l_accounting_line_type := 2;
6621 l_cost_element_id := -99;
6622 ELSIF (l_citw_flag = 1) THEN
6623 l_accounting_line_type := 1; -- Project CG is Dr
6624 l_wip_txn_source_type := 13; --INV txn SRC
6625 l_cost_element_id := NVL(p_cost_element_id, -99);
6626 ELSIF (l_transaction_action_id = 3) THEN
6627 /* If direct interorg is between standard costing orgs,
6628 no need for this as all mta entries will be against
6629 the sending transaction */
6630 IF ( l_cost_method <> 1 OR
6631 l_xfer_cost_method <> 1 OR
6632 l_mmt_primary_quantity>0) THEN
6633 l_mta_transaction_id := l_xfer_transaction_id;
6634 END IF;
6635 l_mta_organization_id := l_xfer_organization_id;
6636 IF (l_xfer_exp_flag = 0) THEN
6637 l_accounting_line_type := 1;
6638 ELSE
6639 l_accounting_line_type := 2;
6640 END IF;
6641 If ( NVL(p_cost_element_id,-99)= 2 AND
6642 NVL(p_resource_id,-99) <> -99) then
6643 l_cost_element_id :=2 ; /* Mat Abs at receiving */
6644 ELSE
6645 l_cost_element_id := NVL(p_cost_element_id,-99); /* NOT Always MAT at REC ORG */
6646 End If;
6647 ELSIF l_transaction_source_type_id = 5 THEN --WIP/CFM
6648 l_accounting_line_type := 7;
6649 l_cost_element_id := NVL(p_cost_element_id, -99);
6650 /* bug 3150050 include staging Txfrs */
6651 ELSIF l_transaction_action_id in (2,28) THEN --SUB Xfer
6652 IF l_xfer_exp_flag = 0 THEN
6653 l_accounting_line_type := 1;
6654 ELSE
6655 l_accounting_line_type := 2;
6656 END IF;
6657 l_cost_element_id := NVL(p_cost_element_id, -99);
6658 /* Logical Expense Requisition Receipt */
6659 ELSIF (l_transaction_action_id = 17) THEN
6660 L_accounting_line_type := 2; -- Account
6661 END IF;
6662 l_mta_primary_quantity := -1 * l_mmt_primary_quantity;
6663
6664 ELSE /* Not Src_Flag */
6665 IF (l_transaction_action_id = 3 AND
6666 l_cost_method = 1 AND
6667 l_xfer_cost_method = 1 AND
6668 l_mmt_primary_quantity > 0) THEN
6669 l_mta_transaction_id := l_xfer_transaction_id;
6670 END IF;
6671 IF ( l_transaction_action_id = 2 )
6672 AND ( l_cg_id <> l_xfer_cg_id)
6673 AND (l_txn_type_id = 68)
6674 AND (p_variance_flag = 1) THEN
6675 l_accounting_line_type := 13; -- Payback Transaction
6676 -- STD PJM
6677 ELSIF ( p_variance_flag = 1 AND
6678 ( l_transaction_source_type_id = 1
6679 OR l_transaction_action_id IN (12,21,3)
6680 OR (l_transaction_action_id = 6 ))) THEN
6681 /* Consigned ownership transfer transactions */
6682 IF (l_transaction_action_id = 3 AND
6683 l_cost_method <> 1 AND
6684 l_xfer_cost_method = 1 AND
6685 l_mmt_primary_quantity < 0) THEN
6686 l_mta_transaction_id := l_xfer_transaction_id;
6687 l_mta_organization_id := l_xfer_organization_id;
6688 ELSIF (l_transaction_action_id = 3 AND
6689 l_cost_method = 1 AND
6690 l_xfer_cost_method = 1 AND
6691 l_mmt_primary_quantity < 0) THEN
6692 l_mta_organization_id := l_xfer_organization_id;
6693 ELSIF (l_transaction_action_id = 21 AND
6694 l_cost_method = 1 AND
6695 l_xfer_cost_method = 1 AND
6696 l_fob_point = 1 ) THEN
6697 l_mta_organization_id := l_xfer_organization_id;
6698 END IF;
6699 -- PPV
6700 l_accounting_line_type := 6;
6701 /* Internal Sales order Issue to Expense */
6702 ELSIF(l_transaction_action_id = 1 AND l_transaction_source_type_id = 8) THEN
6703 L_accounting_line_type := 10; -- Interorg Receivables
6704 ELSIF (l_transaction_action_id = 17) THEN
6705 L_accounting_line_type := 2; -- Account
6706 ELSE -- the following is neither payback nor PPV
6707 IF l_exp_flag = 0 THEN
6708 l_accounting_line_type := 1;
6709 ELSE
6710 l_accounting_line_type := 2;
6711 END IF;
6712 /* check for common issue to wip,if yes then set the source to be used */
6713 If l_citw_flag = 1 then
6714 l_wip_txn_source_type := 13;
6715 else
6716 l_wip_txn_source_type := '';
6717 end if;
6718 END IF;
6719
6720 l_cost_element_id := NVL(p_cost_element_id, -99);
6721
6722 /* Bug 3978501.Change the l_cost_element_id to -99 for expense item or expense */
6723 /* sub as MTA will have the Dr entry with cost element id of NULL for expense */
6724 /* item receipts */
6725 /* Exclude Internal Order Issues to Expense */
6726 /* I know that's messed up.. But. */
6727 /* bugs 4655264 and 4651130. In consistencies between standard and Average costing orgs. THe cost processor stamps a
6728 cost element ID against the AL of 2 in the case of Average costing orgs and in the case of std costing orgs
6729 there is no CE stamped against the AL 2.Need to handle them separately. */
6730
6731
6732 if ( l_exp_flag = 1 AND l_transaction_action_id <> 17 AND l_cost_method = 1) then
6733 l_cost_element_id := -99;
6734 End If;
6735 l_mta_primary_quantity := l_mmt_primary_quantity;
6736
6737 /* Bug 6461155 */
6738
6739 if (l_transaction_action_id = 29 and l_transaction_source_type_id = 1)
6740 then
6741
6742 l_cost_element_id := -99;
6743 l_mta_primary_quantity := -1 * l_mmt_primary_quantity;
6744 l_accounting_line_type := 5;
6745
6746 fnd_file.put_line(fnd_file.log,'PO delivery Adjustment transaction');
6747
6748 end if;
6749
6750 END IF;
6751
6752 if (l_debug = 'Y') then
6753 FND_FILE.PUT_LINE (FND_FILE.LOG,
6754 'DEBIT DATA. Txn: '||to_char(l_mta_transaction_id)
6755 ||' Exp_Flag: '||to_char(l_exp_flag)
6756 ||' Xfer_Exp_Flag: '
6757 ||to_char(l_xfer_exp_flag)
6758 ||' Org: '||to_char(l_mta_organization_id)
6759 ||' Item: '||to_char(l_inventory_item_id)
6760 ||' CE: '||to_char(l_cost_element_id)
6761 ||' AL: '||to_char(l_accounting_line_type)
6762 ||' Qty: '||to_char(l_mta_primary_quantity)
6763 ||' l_cost_method ' || to_char(l_cost_method)
6764 ||' l_xfer_cost_method '||to_char(l_xfer_cost_method)
6765 ||' Src Flag '||to_char(l_source_flag)
6766 ||' Transfer txn '||to_char(l_xfer_transaction_id)
6767 ||' Transfer org '||to_char(l_xfer_organization_id)
6768 ||' WIP Txn Src Type ' || to_char(l_wip_txn_source_type)
6769 );
6770 END IF;
6771
6772 SELECT NVL(MAX(mta.reference_account), -999999)
6773 INTO O_dr_code_combination_id
6774 FROM mtl_transaction_accounts mta
6775 WHERE
6776 mta.transaction_id = l_mta_transaction_id AND
6777 mta.organization_id = l_mta_organization_id AND
6778 mta.inventory_item_id = l_inventory_item_id AND
6779 nvl(mta.cost_element_id, -99) = l_cost_element_id AND
6780 mta.accounting_line_type = l_accounting_line_type AND
6781 mta.primary_quantity = decode(p_variance_flag, 1, mta.primary_quantity,
6782 decode(l_source_flag, 1,
6783 decode(l_transaction_action_id, 3, mta.primary_quantity,
6784 l_mta_primary_quantity), l_mta_primary_quantity)) AND
6785 (((l_citw_flag = 1) AND
6786 (mta.transaction_source_type_id = l_wip_txn_source_type)) OR(l_citw_flag <> 1));
6787
6788
6789 l_stmt_num := 53;
6790
6791 /* Changes to get the Debit INV sub Ledger ID from MTA for the dr account fecthed above*/
6792
6793 If O_dr_code_combination_id <> -999999 then
6794
6795 SELECT MAX(INV_SUB_LEDGER_ID)
6796 INTO O_inv_dr_sub_ledger_id
6797 FROM mtl_transaction_accounts mta
6798 WHERE
6799 mta.reference_account = O_dr_code_combination_id AND
6800 mta.transaction_id = l_mta_transaction_id AND
6801 mta.organization_id = l_mta_organization_id AND
6802 mta.inventory_item_id = l_inventory_item_id AND
6803 nvl(mta.cost_element_id, -99) = l_cost_element_id AND
6804 mta.accounting_line_type = l_accounting_line_type AND
6805 mta.primary_quantity = decode(p_variance_flag, 1, mta.primary_quantity,
6806 decode(l_source_flag, 1,
6807 decode(l_transaction_action_id, 3, mta.primary_quantity,
6808 l_mta_primary_quantity), l_mta_primary_quantity)) AND
6809 (((l_citw_flag = 1) AND
6810 (mta.transaction_source_type_id = l_wip_txn_source_type)) OR(l_citw_flag <> 1));
6811
6812 End If;
6813
6814
6815 /* The decode stmt incorporated the fix for bug 917729 and 967071 */
6816 /* bug 917729, for borrow payback txn, don't need to */
6817 /* join the primary quantity */
6818 /* Bug#967071. Changed the where clause , if sending and recv orgs have */
6819 /* different UOM then primary qty will be different */
6820
6821
6822 l_stmt_num := 55;
6823 /****** Start Cr Account Processing ******/
6824 IF O_dr_code_combination_id <> -999999 THEN /* Valid Dr A/C */
6825 IF (l_citw_flag = 1) THEN /* MAIN IF */
6826 SELECT
6827 NVL((MAX(mta.reference_account)),-999999)
6828 INTO O_cr_code_combination_id
6829 FROM mtl_transaction_accounts mta
6830 WHERE mta.transaction_id = p_transaction_id
6831 AND mta.organization_id = l_organization_id
6832 AND mta.inventory_item_id = l_inventory_item_id
6833 AND NVL(mta.cost_element_id,-99)= NVL(p_cost_element_id,-99)
6834 AND mta.accounting_line_type = 1
6835 AND mta.primary_quantity = decode(l_source_flag,1,l_mmt_primary_quantity,((-1)*l_mmt_primary_quantity))
6836 AND mta.transaction_source_type_id = 13; --ALWAYS INV
6837
6838 l_stmt_num := 57;
6839
6840 /* changes to get the Credit INV sub ledger ID for the credit side from MTA */
6841
6842 Select MAX(INV_SUB_LEDGER_ID)
6843 into O_inv_cr_sub_ledger_id
6844 from mtl_transaction_accounts mta
6845 where mta.reference_account = O_cr_code_combination_id
6846 AND mta.transaction_id = p_transaction_id
6847 AND mta.organization_id = l_organization_id
6848 AND mta.inventory_item_id = l_inventory_item_id
6849 AND NVL(mta.cost_element_id,-99)= NVL(p_cost_element_id,-99)
6850 AND mta.accounting_line_type = 1
6851 AND mta.primary_quantity = decode(l_source_flag,1,l_mmt_primary_quantity,((-1)*l_mmt_primary_quantity))
6852 AND mta.transaction_source_type_id = 13; --ALWAYS INV
6853
6854 l_stmt_num := 58;
6855
6856 /* Check if Org is Blue print.If yes then use clearing Accts */
6857 BEGIN
6858 Select NVL(pa_posting_flag,'N'),
6859 NVL(pa_autoaccounting_flag,'N')
6860 into l_blue_print_enabled,
6861 l_autoaccounting_flag
6862 from pjm_org_parameters
6863 where organization_id = l_mta_organization_id;
6864 EXCEPTION
6865 WHEN NO_DATA_FOUND then
6866 l_blue_print_enabled := 'N';
6867 l_autoaccounting_flag := 'N';
6868 END;
6869 If l_blue_print_enabled = 'Y' AND l_autoaccounting_flag = 'N' then
6870 SELECT NVL(MAX(pjm_clearing_account),-999999)
6871 INTO O_cr_code_combination_id
6872 FROM pjm_org_parameters
6873 where organization_id = l_mta_organization_id;
6874
6875 O_inv_cr_sub_ledger_id := NULL;
6876
6877 If O_cr_code_combination_id = -999999 then
6878 raise CST_NO_ACCOUNT_FOUND;
6879 end If;
6880 End If;
6881 ELSIF (l_source_flag = 1) THEN /*Source Txn */
6882 IF (l_transaction_action_id = 3) THEN /* Dir IO */
6883 If (NVL(p_cost_element_id,-99) = 2 AND
6884 NVL(p_resource_id,-99) <> -99 ) then
6885 l_cost_element_id := 2;
6886 l_accounting_line_type := 3;
6887 else
6888 l_cost_element_id := -99;
6889 select (decode(sign(l_mmt_primary_quantity),1,10,9))
6890 into l_accounting_line_type
6891 from dual;
6892 End If;
6893 l_mta_primary_quantity:=l_mmt_primary_quantity;
6894 ELSIF ( l_transaction_action_id = 1 AND
6895 l_transaction_source_type_id = 8 ) THEN
6896 L_accounting_line_type := 1;
6897 l_cost_element_id := -99;
6898 l_mta_primary_quantity := l_mmt_primary_quantity;
6899 ELSIF (l_transaction_action_id = 17) THEN
6900 L_accounting_line_type := 9;
6901 l_cost_element_id := -99;
6902 l_mta_primary_quantity := l_mmt_primary_quantity;
6903 ELSE
6904 IF l_exp_flag = 0 THEN
6905 l_accounting_line_type := 1;
6906 ELSE
6907 l_accounting_line_type := 2;
6908 END IF;
6909 l_cost_element_id :=NVL(p_cost_element_id,-99);
6910 l_mta_primary_quantity:=l_mmt_primary_quantity;
6911 END IF;
6912 ELSE /* Neither CITW Nor Source_Flg */
6913 IF NVL(p_resource_id,-99) <> -99 THEN /* Res Not Null*/
6914 l_accounting_line_type := 3; --OHA
6915 l_cost_element_id :=2; --MOH
6916 l_mta_primary_quantity := -1 * l_mmt_primary_quantity;
6917 ELSIF l_transaction_action_id = 3 and p_variance_flag =1 then
6918 /* handle PPV for direct interorgs receiving side */
6919 l_accounting_line_type := 9;
6920 /* the MTA primary Qty is always - against the Rcv */
6921 if l_mmt_primary_quantity < 0 then
6922 l_mta_primary_quantity := l_mmt_primary_quantity;
6923 else
6924 l_mta_primary_quantity := -1 * l_mmt_primary_quantity;
6925 end if;
6926 ELSE
6927 l_mta_primary_quantity := -1 * l_mmt_primary_quantity;
6928 SELECT
6929 decode(l_transaction_action_id, 3, --Direct IO Xfer
6930 decode(sign(l_mmt_primary_quantity), 1,9, --IO Pyble
6931 10), --IO Rcvble
6932 32, 7, --Assy Return
6933 31, 7, --Assy Complete
6934 33, 7, --Neg WIP Issue
6935 34, 7, --Neg WIP Return
6936 2, decode(l_xfer_exp_flag, 0,1, 2), --Sub Xfer
6937 4, 2, --Cycle Count
6938 8, 2, --Phy Inv
6939 12, --Intransit Receipt
6940 decode(nvl(l_fob_point,-99), 1,14, 2,9), 21, --Intransit Shipment
6941 decode(nvl(l_fob_point,-99), 1,10, 2,14), 29, decode(l_transaction_source_type_id, 1,5), --PO Adj
6942 1, decode(l_transaction_source_type_id, 1, 5, --RTV
6943 3, 2, --A/C Issue
6944 5, 7, --WIP/CFM
6945 6, 2, --Ali Issue
6946 13,2), --Misc Issue
6947 27, decode(l_transaction_source_type_id, 1, 5, --PO Receipt
6948 3, 2, --A/C Receipt
6949 5, 7, --WIP/CFM
6950 6, 2, --Ali Receipt
6951 13,2), --Misc Rcpt
6952 6,16, /*consigned ownership transfer */
6953 26,31, /* Logical PO receipt for BP org */
6954 28,1, /* staging Txfrs */
6955 17, 9, /* Logical Expense Requition Receipt */ -99)
6956 INTO l_accounting_line_type
6957 FROM DUAL;
6958
6959 IF l_accounting_line_type IN (7,1,14) THEN
6960 l_cost_element_id := NVL(p_cost_element_id,-99);
6961 ELSIF l_accounting_line_type = 2 AND l_transaction_action_id =2 THEN
6962 l_cost_element_id := NVL(p_cost_element_id,-99);
6963 ELSIF l_accounting_line_type = 9 AND l_transaction_action_id = 17 THEN
6964 l_cost_element_id := NVL(p_cost_element_id,-99);
6965 ELSE
6966 l_cost_element_id := -99;
6967 END IF;
6968
6969 END IF; /* Res Not Null */
6970 END IF; /*MAIN IF */
6971
6972 IF (l_citw_flag <> 1) THEN
6973 IF l_debug = 'Y' THEN
6974 FND_FILE.put_line(fnd_file.log, 'CREDIT DATA: ');
6975 FND_FILE.put_line(fnd_file.log, 'Cost Element: '||to_char(l_cost_element_id) || ' Accounting Line Type: '||to_char(l_accounting_line_type)||' Primary Quantity: '||to_char(l_mta_primary_quantity));
6976 END IF;
6977 -- Bug 936641, for borrow payback variance, should NOT
6978 -- store both Cr and Dr with the same accounting information
6979 -- The line 'O_cr_code_combination_id := O_dr_code_combination_id;'
6980 -- was removed.
6981 -- The credit accounts for project transfer txns will be replaced
6982 -- with clearing accounts for blue print orgs
6983 -- Bug 3662806. Enclose Begin and end for non PJM orgs
6984 l_stmt_num := 60;
6985 BEGIN
6986 Select NVL(pa_posting_flag,'N'),
6987 NVL(pa_autoaccounting_flag,'N')
6988 into l_blue_print_enabled,
6989 l_autoaccounting_flag
6990 from pjm_org_parameters
6991 where organization_id = l_mta_organization_id;
6992 EXCEPTION
6993 WHEN NO_DATA_FOUND then
6994 l_blue_print_enabled := 'N';
6995 l_autoaccounting_flag := 'N';
6996 END;
6997 if ((l_transaction_action_id = 2) OR (l_transaction_action_id = 1
6998 AND l_transaction_source_type_id = 5) OR l_transaction_action_id = 28)
6999 AND l_blue_print_enabled= 'Y'
7000 AND l_autoaccounting_flag = 'N' then
7001 SELECT NVL(MAX(pjm_clearing_account),-999999)
7002 INTO O_cr_code_combination_id
7003 FROM pjm_org_parameters
7004 where organization_id = l_mta_organization_id;
7005
7006 O_inv_cr_sub_ledger_id := NULL;
7007
7008 If O_cr_code_combination_id = -999999 then
7009 raise CST_NO_ACCOUNT_FOUND;
7010 end If;
7011 else
7012 /* Non blue print or non project transfer txns
7013 changed the join condition on the cost element ID to get the correct account */
7014 SELECT NVL(MAX(mta.reference_account), -999999)
7015 INTO O_cr_code_combination_id
7016 FROM mtl_transaction_accounts mta
7017 WHERE
7018 mta.transaction_id =l_mta_transaction_id AND
7019 mta.organization_id =l_mta_organization_id AND
7020 mta.inventory_item_id =l_inventory_item_id AND
7021 nvl(mta.cost_element_id, -99) =decode(l_cost_element_id,-99,nvl(mta.cost_element_id,-99),l_cost_element_id) AND
7022 nvl(mta.resource_id, -99) = nvl(p_resource_id,-99) AND
7023 mta.accounting_line_type = l_accounting_line_type AND
7024 mta.primary_quantity = l_mta_primary_quantity;
7025
7026 /* Changes to get the INV sub ledger ID for the credit account from MTA */
7027
7028 SELECT MAX(INV_SUB_LEDGER_ID)
7029 INTO O_inv_cr_sub_ledger_id
7030 FROM mtl_transaction_accounts mta
7031 WHERE
7032 mta.reference_account = O_cr_code_combination_id AND
7033 mta.transaction_id =l_mta_transaction_id AND
7034 mta.organization_id =l_mta_organization_id AND
7035 mta.inventory_item_id =l_inventory_item_id AND
7036 nvl(mta.cost_element_id, -99) =decode(l_cost_element_id,-99,nvl(mta.cost_element_id,-99),l_cost_element_id) AND
7037 nvl(mta.resource_id, -99) = nvl(p_resource_id,-99) AND
7038 mta.accounting_line_type = l_accounting_line_type AND
7039 mta.primary_quantity = l_mta_primary_quantity;
7040
7041 end if;
7042 END IF; -- l_citw_flag <> 1
7043
7044 IF O_cr_code_combination_id = -999999 THEN
7045 O_cr_code_combination_id := O_dr_code_combination_id;
7046 O_inv_cr_sub_ledger_id := O_inv_dr_sub_ledger_id;
7047
7048 IF l_debug = 'Y' THEN
7049 FND_FILE.put_line(FND_FILE.log, 'Credit Account not found. It will be set the same as Debit account');
7050 END IF;
7051
7052 END IF;
7053
7054 ELSE
7055 RAISE CST_NO_ACCOUNT_FOUND;
7056 END IF; /* Valid Dr A/C */
7057
7058 EXCEPTION
7059 WHEN CST_NO_ACCOUNT_FOUND THEN
7060 O_err_num := -1;
7061 O_err_code := NULL;
7062 O_err_msg := SUBSTR('No Account Retrieved.'
7063 || '('
7064 ||to_char(l_stmt_num)
7065 ||') '
7066 ||' Txn_id: '
7067 ||to_char(p_transaction_id)
7068 ||' CE: '
7069 ||to_char(p_cost_element_id)
7070 ||' Rsrc: '
7071 ||to_char(p_resource_id)
7072 ||' Src_flag: '
7073 ||to_char(p_source_flag)
7074 ||' Borrow payback variance: '
7075 ||to_char(p_variance_flag),1,200);
7076 WHEN OTHERS THEN
7077 IF O_dr_code_combination_id <> -999999 THEN
7078 O_cr_code_combination_id := O_dr_code_combination_id;
7079 O_inv_cr_sub_ledger_id := O_inv_dr_sub_ledger_id;
7080 ELSE
7081 O_dr_code_combination_id := -999999;
7082 O_cr_code_combination_id := -999999;
7083 O_inv_dr_sub_ledger_id := NULL;
7084 O_inv_cr_sub_ledger_id := NULL;
7085 O_err_num := SQLCODE;
7086 O_err_code := NULL;
7087 O_err_msg := SUBSTR('CSTPPCCB.pm_get_mta_accts('
7088 ||to_char(l_stmt_num)
7089 ||'): '
7090 ||SQLERRM,1,240);
7091 END IF;
7092 END;
7093 END pm_get_mta_accts;
7094
7095 /*----------------------------------------------------------------------------*
7096 | PRIVATE FUNCTION |
7097 | get_max_group_size |
7098 | |
7099 | DESCRIPTION |
7100 | |
7101 | This function will return the maximum number of records that a single |
7102 | worker should process. |
7103 | |
7104 | PARAMETERS |
7105 | |
7106 | RETURNS |
7107 | Records with in a Single Group |
7108 | |
7109 | CALLED FROM |
7110 | pm_cc_manager |
7111 | |
7112 | HISTORY |
7113 | 07-SEP-96 Bhaskar Dasari Created. |
7114 *----------------------------------------------------------------------------*/
7115
7116 FUNCTION get_group_size RETURN NUMBER IS
7117
7118 max_group_size_per_worker NUMBER := 3000;
7119 BEGIN
7120
7121 return ( max_group_size_per_worker );
7122
7123 END get_group_size;
7124
7125
7126 /*----------------------------------------------------------------------------*
7127 | PRIVATE PROCEDURE |
7128 | pm_ins_pti_pvt |
7129 | |
7130 | DESCRIPTION |
7131 | |
7132 | This procedure will call accounting hook and cost collector hook andt |
7133 | it will manage the insertion of records in PA_TRANSACTIONS_INTERFACE |
7134 | |
7135 | PARAMETERS |
7136 | |
7137 | |
7138 | CALLED FROM |
7139 | pm_process_txn_mmt |
7140 | |
7141 | HISTORY |
7142 | 23-APR-01 Hemant Gosain Created. |
7143 *----------------------------------------------------------------------------*/
7144
7145 PROCEDURE pm_insert_pti_pvt
7146 (p_transaction_source VARCHAR2,
7147 p_batch_name VARCHAR2,
7148 p_expenditure_ending_date DATE,
7149 p_employee_number VARCHAR2,
7150 p_organization_name VARCHAR2,
7151 p_expenditure_item_date DATE,
7152 p_project_number VARCHAR2,
7153 p_task_number VARCHAR2,
7154 p_expenditure_type VARCHAR2,
7155 p_pa_quantity NUMBER,
7156 p_raw_cost NUMBER,
7157 p_expenditure_comment VARCHAR2,
7158 p_orig_transaction_reference VARCHAR2,
7159 p_raw_cost_rate NUMBER,
7160 p_unmatched_negative_txn_flag VARCHAR2,
7161 p_gl_date DATE,
7162 p_org_id NUMBER,
7163 p_burdened_cost NUMBER,
7164 p_burdened_cost_rate NUMBER,
7165 p_system_linkage VARCHAR2,
7166 p_transaction_status_code VARCHAR2,
7167 p_denom_currency_code VARCHAR2,
7168
7169 p_transaction_id NUMBER,
7170 p_transaction_action_id NUMBER,
7171 p_transaction_source_type_id NUMBER,
7172 p_organization_id NUMBER,
7173 p_inventory_item_id NUMBER,
7174 p_cost_element_id NUMBER,
7175 p_resource_id NUMBER,
7176 p_source_flag NUMBER,
7177 p_variance_flag NUMBER,
7178 p_primary_quantity NUMBER,
7179 p_transfer_organization_id NUMBER,
7180 p_fob_point NUMBER,
7181 p_wip_entity_id NUMBER,
7182 p_basis_resource NUMBER,
7183
7184 p_type_class NUMBER,
7185 p_project_id NUMBER,
7186 p_task_id NUMBER,
7187 p_transaction_date DATE,
7188 p_cost_group_id NUMBER,
7189 p_transfer_cost_group_id NUMBER,
7190 p_transaction_source_id NUMBER,
7191 p_to_project_id NUMBER,
7192 p_to_task_id NUMBER,
7193 p_source_project_id NUMBER,
7194 p_source_task_id NUMBER,
7195 p_transfer_transaction_id NUMBER,
7196 p_primary_cost_method NUMBER,
7197 p_acct_period_id NUMBER,
7198 p_exp_org_id NUMBER,
7199 p_distribution_account_id NUMBER,
7200 p_proj_job_ind NUMBER,
7201 p_first_matl_se_exp_type VARCHAR2,
7202 p_inv_txn_source_literal VARCHAR2,
7203 p_cap_txn_source_literal VARCHAR2,
7204 p_inv_syslink_literal VARCHAR2,
7205 p_bur_syslink_literal VARCHAR2,
7206 p_wip_syslink_literal VARCHAR2,
7207 p_user_def_exp_type VARCHAR2,
7208 p_flow_schedule VARCHAR2,
7209 p_si_asset_yes_no NUMBER,
7210 p_transfer_si_asset_yes_no NUMBER,
7211
7212 O_err_num OUT NOCOPY NUMBER,
7213 O_err_code OUT NOCOPY VARCHAR2,
7214 O_err_msg OUT NOCOPY VARCHAR2
7215 )
7216
7217 IS
7218
7219 l_err_num NUMBER := 0;
7220 l_err_code VARCHAR2(240) ;
7221 l_err_msg VARCHAR2(240) ;
7222 l_stmt_num NUMBER;
7223 l_hook_used NUMBER;
7224 l_cse_hook_used NUMBER;
7225 l_cse_err_code NUMBER := 0;
7226 l_cse_err_msg NUMBER := 0;
7227 l_dr_code_combination_id NUMBER;
7228 l_cr_code_combination_id NUMBER;
7229 l_sql_stmt VARCHAR2(8000);
7230 l_cse_installed BOOLEAN;
7231 l_status VARCHAR2(1);
7232 l_industry VARCHAR2(1);
7233 l_schema VARCHAR2(30);
7234 l_nl_trackable VARCHAR2(1);
7235 l_asset_creation_code VARCHAR2(30);
7236
7237 l_raw_cost_rate NUMBER := 0;
7238 l_raw_cost NUMBER := 0;
7239 l_burdened_cost_rate NUMBER := 0;
7240 l_burdened_cost NUMBER := 0;
7241 l_systemlinkage VARCHAR2(30);
7242
7243 l_uom_code VARCHAR2(30) ;
7244 l_inv_cr_sub_ledger_id NUMBER;
7245 l_inv_dr_sub_ledger_id NUMBER;
7246
7247 CST_FAILED_GET_ACCOUNT EXCEPTION;
7248 CST_FAILED_HOOK_ACCT EXCEPTION;
7249 CST_FAILED_CST_CC_HOOK EXCEPTION;
7250 CST_FAILED_CSE_CALL EXCEPTION;
7251 CST_NL_NOT_INSTALLED EXCEPTION;
7252
7253 l_debug VARCHAR2(80);
7254 l_op_unit NUMBER;
7255
7256 BEGIN
7257
7258 l_stmt_num := 1;
7259 l_hook_used := 0;
7260 l_cse_hook_used := 0;
7261
7262 l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
7263 if (l_debug = 'Y') then
7264 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Reached#:pm_insert_pti_pvt');
7265 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Transaction_id :'||to_char(p_transaction_id));
7266 end if;
7267
7268 l_stmt_num := 10;
7269
7270 pm_get_mta_accts(
7271 p_transaction_id => p_transaction_id,
7272 p_cost_element_id => p_cost_element_id,
7273 p_resource_id => p_resource_id,
7274 p_source_flag => p_source_flag,
7275 p_variance_flag => p_variance_flag,
7276 O_dr_code_combination_id => l_dr_code_combination_id,
7277 O_cr_code_combination_id => l_cr_code_combination_id,
7278 O_inv_cr_sub_ledger_id => l_inv_cr_sub_ledger_id,
7279 O_inv_dr_sub_ledger_id => l_inv_dr_sub_ledger_id,
7280 O_err_num => l_err_num,
7281 O_err_code => l_err_code,
7282 O_err_msg => l_err_msg);
7283
7284 IF (l_err_num <> 0) THEN
7285
7286 RAISE CST_FAILED_GET_ACCOUNT;
7287
7288 END IF;
7289
7290
7291 l_stmt_num := 20;
7292
7293 IF (NVL(l_dr_code_combination_id,-9) < 0) OR
7294 (NVL(l_cr_code_combination_id,-9) < 0)
7295 THEN
7296
7297 RAISE CST_FAILED_HOOK_ACCT;
7298
7299 END IF;
7300
7301
7302
7303 l_stmt_num := 15;
7304
7305 /* changes to support the PJM Blue Print organization stuff */
7306
7307 If (p_transaction_source = 'PJM_CSTBP_INV_ACCOUNTS')
7308 OR (p_transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS') then
7309
7310 /* Blue print sources so pass everything as row cost */
7311
7312 l_raw_cost_rate := p_burdened_cost_rate;
7313 l_raw_cost := p_burdened_cost;
7314 l_burdened_cost_rate := NULL;
7315 l_burdened_cost := NULL;
7316
7317 Else /* non BP org */
7318
7319 l_raw_cost_rate := p_raw_cost_rate;
7320 l_raw_cost := p_raw_cost;
7321 l_burdened_cost_rate := p_burdened_cost_rate;
7322 l_burdened_cost := p_burdened_cost;
7323
7324 End If;
7325
7326
7327 l_stmt_num := 17;
7328
7329 /* check if the transaction source is "Inventory with no accounts".If it is, then do not send any accounts to PA.They will use auto accounting */
7330
7331 If p_transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS' then
7332
7333 l_dr_code_combination_id := NULL;
7334 l_cr_code_combination_id := NULL;
7335
7336 l_inv_cr_sub_ledger_id := NULL;
7337 l_inv_dr_sub_ledger_id := NULL;
7338
7339 end if;
7340
7341 -------------------------------------------------------------------------
7342 -- Network Logistics Support
7343 -------------------------------------------------------------------------
7344
7345 /* Added Block - Network Logistics Changes */
7346
7347 -------------------------------------------------------------------------
7348 -- Check Installation Status of Network Logistics (CSE)
7349 -------------------------------------------------------------------------
7350
7351 l_stmt_num := 30;
7352
7353 /* Bug 3742735. Pass the org_id of the organization on the txn always.This will enable cross project charging to also work. */
7354
7355 select to_number(org_information3)
7356 into l_op_unit
7357 from hr_organization_information hoi,
7358 mtl_material_transactions mmt
7359 where hoi.organization_id = mmt.organization_id
7360 and mmt.transaction_id = to_number(p_orig_transaction_reference)
7361 and org_information_context ='Accounting Information';
7362
7363 l_cse_installed := FND_INSTALLATION.GET_APP_INFO ( 'CSE',
7364 l_status,
7365 l_industry,
7366 l_schema);
7367
7368 /* Check if item is NL trackable */
7369 SELECT nvl(comms_nl_trackable_flag, 'N'), asset_creation_code
7370 INTO l_nl_trackable, l_asset_creation_code
7371 FROM mtl_system_items
7372 WHERE inventory_item_id = p_inventory_item_id
7373 AND organization_id = p_organization_id;
7374
7375 /* Bug 2907681 The code that checks for the item to be NL trackable and the NL module to be installed has been removed as it is not true always.We should not error out if the item is NL trackable but the NL module is not installed */
7376
7377
7378 IF (l_nl_trackable = 'Y' and l_status = 'I') THEN
7379
7380 l_stmt_num := 35;
7381 l_cse_hook_used := 0;
7382
7383 CSE_COST_COLLECTOR.eib_cost_collector_stub (
7384 p_transaction_id => p_transaction_id,
7385 p_organization_id => p_organization_id,
7386 p_transaction_action_id => p_transaction_action_id,
7387 p_transaction_source_type_id => p_transaction_source_type_id,
7388 p_type_class => p_type_class,
7389 p_project_id => p_project_id,
7390 p_task_id => p_task_id,
7391 p_transaction_date => p_transaction_date,
7392 p_primary_quantity => p_primary_quantity,
7393 p_cost_group_id => p_cost_group_id,
7394 p_transfer_cost_group_id => p_transfer_cost_group_id,
7395 p_inventory_item_id => p_inventory_item_id,
7396 p_transaction_source_id => p_transaction_source_id,
7397 p_to_project_id => p_to_project_id,
7398 p_to_task_id => p_to_task_id,
7399 p_source_project_id => p_source_project_id,
7400 p_source_task_id => p_source_task_id,
7401 p_transfer_transaction_id => p_transfer_transaction_id,
7402 p_primary_cost_method => p_primary_cost_method,
7403 p_acct_period_id => p_acct_period_id,
7404 p_exp_org_id => p_exp_org_id,
7405 p_distribution_account_id => p_distribution_account_id,
7406 p_proj_job_ind => p_proj_job_ind,
7407 p_first_matl_se_exp_type => p_first_matl_se_exp_type,
7408 p_inv_txn_source_literal => p_inv_txn_source_literal,
7409 p_cap_txn_source_literal => p_cap_txn_source_literal,
7410 p_inv_syslink_literal => p_inv_syslink_literal,
7411 p_bur_syslink_literal => p_bur_syslink_literal,
7412 p_wip_syslink_literal => p_wip_syslink_literal,
7413 p_user_def_exp_type => p_user_def_exp_type,
7414 p_transfer_organization_id => p_transfer_organization_id,
7415 p_flow_schedule => p_flow_schedule,
7416 p_si_asset_yes_no => p_si_asset_yes_no,
7417 p_transfer_si_asset_yes_no => p_transfer_si_asset_yes_no,
7418 p_denom_currency_code => p_denom_currency_code,
7419 p_exp_type => p_expenditure_type,
7420 p_dr_code_combination_id => l_dr_code_combination_id,
7421 p_cr_code_combination_id => l_cr_code_combination_id,
7422 p_raw_cost => l_raw_cost,
7423 p_burden_cost => l_burdened_cost,
7424 p_cr_sub_ledger_id => l_inv_cr_sub_ledger_id,
7425 p_dr_sub_ledger_id => l_inv_dr_sub_ledger_id,
7426 p_cost_element_id => p_cost_element_id,
7427 O_hook_used => l_cse_hook_used,
7428 O_err_num => l_err_num,
7429 O_err_code => l_cse_err_code,
7430 O_err_msg => l_cse_err_msg);
7431
7432 l_stmt_num := 40;
7433
7434 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: CSE hook usage flag :'||to_char(l_cse_hook_used));
7435 IF (l_err_num <> 0) THEN
7436
7437 RAISE CST_FAILED_CSE_CALL;
7438
7439 END IF;
7440
7441 END IF;
7442
7443 /* End: Added Block - Network Logistics Changes */
7444 l_stmt_num := 45;
7445
7446 l_hook_used := 0;
7447
7448 CST_COST_COLLECTOR_HOOK.pm_invtxn_hook(
7449 p_transaction_id ,
7450 p_organization_id ,
7451 p_transaction_action_id ,
7452 p_transaction_source_type_id ,
7453 p_type_class ,
7454 p_project_id ,
7455 p_task_id ,
7456 p_transaction_date ,
7457 p_primary_quantity ,
7458 p_cost_group_id ,
7459 p_transfer_cost_group_id ,
7460 p_inventory_item_id ,
7461 p_transaction_source_id ,
7462 p_to_project_id ,
7463 p_to_task_id ,
7464 p_source_project_id ,
7465 p_source_task_id ,
7466 p_transfer_transaction_id ,
7467 p_primary_cost_method ,
7468 p_acct_period_id ,
7469 p_exp_org_id ,
7470 p_distribution_account_id ,
7471 p_proj_job_ind ,
7472 p_first_matl_se_exp_type ,
7473 p_inv_txn_source_literal ,
7474 p_cap_txn_source_literal ,
7475 p_inv_syslink_literal ,
7476 p_bur_syslink_literal ,
7477 p_wip_syslink_literal ,
7478 p_user_def_exp_type ,
7479 p_transfer_organization_id ,
7480 p_flow_schedule ,
7481 p_si_asset_yes_no ,
7482 p_transfer_si_asset_yes_no ,
7483 p_denom_currency_code ,
7484 p_expenditure_type ,
7485 l_dr_code_combination_id ,
7486 l_cr_code_combination_id ,
7487 l_raw_cost ,
7488 l_burdened_cost,
7489 p_transaction_source ,
7490 p_batch_name ,
7491 p_expenditure_ending_date ,
7492 p_employee_number ,
7493 p_organization_name ,
7494 p_expenditure_item_date ,
7495 p_project_number ,
7496 p_task_number ,
7497 p_pa_quantity ,
7498 p_expenditure_comment ,
7499 p_orig_transaction_reference ,
7500 p_raw_cost_rate ,
7501 p_unmatched_negative_txn_flag ,
7502 p_gl_date ,
7503 l_op_unit ,
7504 p_burdened_cost_rate ,
7505 p_system_linkage ,
7506 p_transaction_status_code ,
7507 l_hook_used ,
7508 l_err_num ,
7509 l_err_code ,
7510 l_err_msg);
7511 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: INV hook usage flag :'||to_char(l_hook_used));
7512
7513 IF (l_err_num <> 0) THEN
7514
7515 RAISE CST_FAILED_CST_CC_HOOK;
7516
7517 END IF;
7518
7519
7520
7521
7522 /* Added Block - Network Logistics Changes */
7523
7524 IF(l_hook_used = 1 OR l_cse_hook_used = 1) THEN
7525 return;
7526 END IF;
7527
7528 /* End: Added Block - Network Logistics Changes */
7529
7530 l_stmt_num := 50;
7531
7532 /* bug 3345746 .For Blue print orgs,the system linkage that should be pased in is INV for burden as the
7533 transaction sources do not allow burdening in MFG ( allow_burden_flag = 'N') */
7534
7535 l_systemlinkage := p_system_linkage;
7536
7537 If (p_transaction_source = 'PJM_CSTBP_INV_ACCOUNTS') OR (p_transaction_source = 'PJM_CSTBP_INV_NO_ACCOUNTS') then
7538
7539 If l_systemlinkage = p_bur_syslink_literal then
7540 l_systemlinkage := p_inv_syslink_literal;
7541 end If;
7542
7543 End If;
7544
7545 l_stmt_num := 52;
7546
7547
7548 IF (l_hook_used = 0 ) THEN
7549
7550 if (l_debug = 'Y') then
7551 FND_FILE.PUT_LINE(FND_FILE.LOG,'DEBUG: Inserting transaction into PTI ');
7552 end if;
7553
7554
7555 /* The following insert statement into pa_transaction_interface will be changed to insert into pa_transaction_interface_all */
7556
7557
7558 /* The following insert statement into pa_transaction_interface will be changed to insert into pa_transaction_interface_all */
7559
7560 /* Modified the insert to insert the Inventory_item_id and basic UOM code bug 3298023 */
7561
7562 /*Get the primary UOM code of the item from mtl_system_items */
7563
7564 select primary_uom_code into l_uom_code
7565 from mtl_system_items msi
7566 where msi.inventory_item_id = p_inventory_item_id
7567 AND msi.organization_id = p_organization_id;
7568
7569 If l_debug = 'Y' then
7570 fnd_file.put_line(fnd_file.log,'UOM code for the INV txn : ' || l_uom_code);
7571 end If;
7572
7573
7574
7575 INSERT INTO pa_transaction_interface_all
7576 ( transaction_source,
7577 batch_name,
7578 expenditure_ending_date,
7579 employee_number,
7580 organization_name,
7581 expenditure_item_date,
7582 project_number,
7583 task_number,
7584 expenditure_type,
7585 quantity,
7586 denom_raw_cost,
7587 acct_raw_cost,
7588 expenditure_comment,
7589 orig_transaction_reference,
7590 raw_cost_rate,
7591 unmatched_negative_txn_flag,
7592 dr_code_combination_id,
7593 cr_code_combination_id,
7594 cdl_system_reference1,
7595 cdl_system_reference2,
7596 cdl_system_reference3,
7597 gl_date,
7598 org_id,
7599 denom_burdened_cost,
7600 acct_burdened_cost,
7601 burdened_cost_rate,
7602 system_linkage,
7603 transaction_status_code,
7604 denom_currency_code,
7605 Inventory_item_id,
7606 unit_of_measure,
7607 cdl_system_reference4, --Credit INV Sub ledger ID
7608 cdl_system_reference5 --Debit INV Subledger ID
7609 )
7610 VALUES
7611 (
7612 p_transaction_source,
7613 p_batch_name,
7614 p_expenditure_ending_date,
7615 p_employee_number,
7616 p_organization_name,
7617 p_expenditure_item_date,
7618 p_project_number,
7619 p_task_number,
7620 p_expenditure_type,
7621 p_pa_quantity,
7622 l_raw_cost,
7623 l_raw_cost,
7624 p_expenditure_comment,
7625 p_orig_transaction_reference,
7626 l_raw_cost_rate,
7627 p_unmatched_negative_txn_flag,
7628 l_dr_code_combination_id,
7629 l_cr_code_combination_id,
7630 NULL,
7631 NULL,
7632 NULL,
7633 p_gl_date,
7634 l_op_unit,
7635 l_burdened_cost,
7636 l_burdened_cost,
7637 l_burdened_cost_rate,
7638 l_systemlinkage,
7639 p_transaction_status_code,
7640 p_denom_currency_code,
7641 p_inventory_item_id,
7642 l_uom_code,
7643 l_inv_cr_sub_ledger_id,
7644 l_inv_dr_sub_ledger_id
7645 );
7646 END IF; --l_hook_used
7647
7648 EXCEPTION
7649
7650 WHEN CST_FAILED_CSE_CALL THEN
7651
7652 O_err_num := 20005;
7653 O_err_code := SUBSTR('CSTPPCCB.pm_insert_pti_pvt('
7654 || to_char(l_stmt_num)
7655 || '): '
7656 || 'FAILED CSE Package Call. '
7657 || l_cse_err_code,1,240);
7658 O_err_msg := substr(l_err_msg,1,240) ;
7659
7660 WHEN CST_NL_NOT_INSTALLED THEN
7661 O_err_num := 20004;
7662 O_err_code := SUBSTR('CSTPPCCB.pm_process_txn_mmt('
7663 || to_char(l_stmt_num)
7664 || '): '
7665 || 'NL trackable/depreciable item will not be cost collected if Network Logistics is not installed',1,240);
7666 O_err_msg := substr(l_err_msg,1,240) ;
7667
7668
7669 WHEN CST_FAILED_GET_ACCOUNT THEN
7670
7671 O_err_num := 20001;
7672 O_err_code := SUBSTR('CSTPPCCB.pm_insert_pti_pvt('
7673 || to_char(l_stmt_num)
7674 || '): '
7675 || 'FAILED TO GET ACCT. '
7676 || l_err_msg,1,240);
7677 fnd_message.set_name('BOM','CST_FAILED_GET_ACCOUNT');
7678 l_err_msg := fnd_message.get ;
7679 O_err_msg := substr(l_err_msg,1,240) ;
7680
7681 WHEN CST_FAILED_HOOK_ACCT THEN
7682
7683 O_err_num := 20002;
7684
7685 fnd_message.set_name('BOM','CST_FAILED_HOOK_ACCT');
7686 l_err_msg := fnd_message.get ;
7687 O_err_msg := substr(l_err_msg,1,240) ;
7688
7689 O_err_code := 'CSTPPCCB.pm_insert_pti_pvt('
7690 || to_char(l_stmt_num)
7691 || '): ';
7692
7693 WHEN CST_FAILED_CST_CC_HOOK THEN
7694
7695 O_err_num := 20003;
7696 O_err_code := l_err_code;
7697 O_err_msg := SUBSTR('CSTPPCCB.pm_insert_pti_pvt('
7698 ||to_char(l_stmt_num)
7699 ||'), '
7700 ||'CSTCCHKB.pm_invtxn_hook: '
7701 ||'error at CSTCCHKB, line: '
7702 ||to_char(l_err_num)
7703 ||' CSTCCHKB.err_msg:'
7704 ||l_err_msg,1,240);
7705
7706
7707 WHEN OTHERS THEN
7708
7709 O_err_num := SQLCODE;
7710 O_err_code := NULL;
7711 O_err_msg := SUBSTR('CSTPPCCB.pm_insert_pti_pvt('
7712 || to_char(l_stmt_num)
7713 || '): '
7714 ||SQLERRM,1,240);
7715
7716
7717 END pm_insert_pti_pvt;
7718
7719 /*----------------------------------------------------------------------------*
7720 | PACKAGE CONSTRUCTOR |
7721 | |
7722 | DESCRIPTION |
7723 | |
7724 | HISTORY |
7725 | 07-SEP-96 Bhaskar Dasari |
7726 | |
7727 *----------------------------------------------------------------------------*/
7728 --
7729 -- Constructor Code
7730 --
7731 BEGIN
7732 NULL;
7733 END CST_PRJMFG_COST_COLLECTOR ;