9: PRODUCT
10: Oracle*Payroll
11: --
12: NAME
13: PAY_TRGL_PKG - Procedure to transfer pay costs to General Ledger.
14: --
15: --
16: DESCRIPTION
17: The procedure sums are costs for each cost centre for all payroll runs
51: date if TGL_DATE_USED set to 'EVE'.
52: Bug 4709735.
53: 115.34 alogue 07-OCT-2005 Support of Sub Ledger Accouting (SLA).
54: 115.33 alogue 22-AUG-2005 Support of Payment Costs.
55: 115.32 alogue 15-NOV-2004 Use of transfer_to_gl_flag in pay_costs.
56: Bug 4013881.
57: 115.31 alogue 03-NOV-2004 Always get transfer_to_gl_flag from
58: distributed element for distributed
59: costs. Bug 3972448.
72: 115.26 alogue 02-JUN-2003 Support of TGL_REVB_ACC_DATE action
73: parameter. Population of reference24
74: in gl_interface. Bug 2987235.
75: 115.25 alogue 24-APR-2003 Hints in gl_interface insert statement
76: in trans_pay_costs_mt. Bug 2919000.
77: 115.24 alogue 10-FEB-2003 Support of Estimate Cost Process.
78: Bug 2794030.
79: 115.23 alogue 21-NOV-2002 Support of grandchild (and further)
80: Run child actions.
232: g_date_used VARCHAR2(80) := null;
233:
234: /* SINGLE-THREADED SOLUTION */
235: --
236: PROCEDURE trans_pay_costs
237: (i_payroll_action_id NUMBER)
238: IS
239: --
240: --
322: l_group_id VARCHAR2(80);
323: --
324: BEGIN
325: --
326: hr_utility.set_location('pytrgl.trans_pay_costs',10);
327: --
328: sql_curs :=dbms_sql.open_cursor;
329: --
330: OPEN transfer_payrolls (i_payroll_action_id);
328: sql_curs :=dbms_sql.open_cursor;
329: --
330: OPEN transfer_payrolls (i_payroll_action_id);
331: --
332: hr_utility.set_location('pytrgl.trans_pay_costs',20);
333: --
334: -- Bug 1066820 avoid passing in hard coded strings.
335: --
336: select user_je_source_name
337: into l_source_name
338: from gl_je_sources_vl
339: where je_source_name = 'Payroll';
340: --
341: hr_utility.set_location('pytrgl.trans_pay_costs',25);
342: --
343: select user_je_category_name
344: into l_category_name
345: from gl_je_categories_vl
344: into l_category_name
345: from gl_je_categories_vl
346: where je_category_name = 'Payroll';
347: --
348: hr_utility.set_location('pytrgl.trans_pay_costs',27);
349: --
350: -- Find if use an accouting date of date_earned
351: -- (default is effective_date)
352: --
359: when others then
360: l_date_used := 'P';
361: end;
362: --
363: hr_utility.set_location('pytrgl.trans_pay_costs',28);
364: --
365: -- Find if use an accouting date of date_earned
366: -- (default is effective_date)
367: --
374: when others then
375: l_rvb_acc_date := 'P';
376: end;
377: --
378: hr_utility.set_location('pytrgl.trans_pay_costs',29);
379: --
380: -- Find if should populate gl_interface.group_id
381: -- (default is to leave this column blank)
382: -- If so we populate it with the TGL payroll_action_id
390: when others then
391: l_group_id := 'N';
392: end;
393: --
394: hr_utility.set_location('pytrgl.trans_pay_costs',30);
395: --
396: -- Process each run action in turn. Each run action may be for
397: -- several payrolls. Each payroll will be processed separately.
398: LOOP
402: c_cost_action_id, -- cost action
403: c_payroll_id,
404: c_set_of_books_id;
405: --
406: hr_utility.set_location('pytrgl.trans_pay_costs',31);
407: --
408: EXIT WHEN transfer_payrolls%NOTFOUND;
409: --
410: hr_utility.set_location('pytrgl.trans_pay_costs',32);
406: hr_utility.set_location('pytrgl.trans_pay_costs',31);
407: --
408: EXIT WHEN transfer_payrolls%NOTFOUND;
409: --
410: hr_utility.set_location('pytrgl.trans_pay_costs',32);
411: --
412: select decode(ppa1.action_type, 'S', ppa1.effective_date,
413: decode(ppa2.action_type, 'B', decode(l_rvb_acc_date, 'C', ppa1.effective_date,
414: ppa2.effective_date),
427: pay_payroll_actions ppa2 -- Payroll run action
428: where ppa1.payroll_action_id = c_cost_action_id
429: and ppa2.payroll_action_id = c_run_action_id;
430: --
431: hr_utility.set_location('pytrgl.trans_pay_costs',35);
432: --
433: -- Get payrolls currency conversion rate type
434: -- handle fact that it may be null
435: --
440: c_conversion_date := c_accounting_date;
441:
442: exception
443: when no_data_found then
444: hr_utility.set_location('pytrgl.trans_pay_costs',37);
445: l_currency_type := null;
446: c_conversion_date := null;
447: end;
448: --
455: --
456: pay_segment_list := NULL;
457: gl_segment_list := NULL;
458: --
459: hr_utility.set_location('pytrgl.trans_pay_costs',40);
460: --
461: -- Dynamically build up the segment lists for the payroll.
462: FOR flex_segs IN flex_segments ( c_payroll_id, c_set_of_books_id )
463: LOOP
461: -- Dynamically build up the segment lists for the payroll.
462: FOR flex_segs IN flex_segments ( c_payroll_id, c_set_of_books_id )
463: LOOP
464: --
465: hr_utility.set_location('pytrgl.trans_pay_costs',50);
466: --
467: gl_segment_list := gl_segment_list ||
468: flex_segs.gl_account_segment ||',';
469: --
466: --
467: gl_segment_list := gl_segment_list ||
468: flex_segs.gl_account_segment ||',';
469: --
470: hr_utility.set_location('pytrgl.trans_pay_costs',60);
471: --
472: -- Payroll segment list needs to MIN() function as not grouped
473: -- by each segment.
474: --
481: --
482: prev_payroll_id := c_payroll_id;
483: prev_sob_id := c_set_of_books_id;
484: --
485: hr_utility.set_location('pytrgl.trans_pay_costs',70);
486: --
487: -- Put the statement into the cursor and parse. Don't know how long
488: -- the segment list is so we cannot bind to variables.
489: --
543: pay_assignment_actions pa1, -- Cost assignment action
544: pay_action_interlocks pi2, -- interlock to run
545: pay_assignment_actions pa3, -- run master assignment action
546: pay_assignment_actions pa2, -- run assignment action
547: pay_costs cst,
548: pay_cost_allocation_keyflex caf,
549: pay_run_results rr,
550: pay_input_values_f IV,
551: pay_element_types_f et
747: pay_assignment_actions pa1, -- Cost assignment action
748: pay_action_interlocks pi2, -- interlock to run
749: pay_assignment_actions pa3, -- run master assignment action
750: pay_assignment_actions pa2, -- run assignment action
751: pay_costs cst,
752: pay_cost_allocation_keyflex caf,
753: pay_run_results rr,
754: pay_input_values_f IV,
755: pay_element_types_f et
899: decode (IV.uom, ''M'', et.output_currency_code, ''STAT'')',
900: dbms_sql.v7);
901: end if;
902: --
903: hr_utility.set_location('pytrgl.trans_pay_costs',80);
904: --
905: -- Bind the variable values to the cursor values.
906: --
907: dbms_sql.bind_variable(sql_curs,'c_run_action_id',
932: -- Execute the insert statment.
933: --
934: rows_processed := dbms_sql.execute(sql_curs);
935: --
936: hr_utility.set_location('pytrgl.trans_pay_costs',90);
937: --
938: -- Update the assignment actions. Mark as processed.
939: --
940: UPDATE pay_assignment_actions pa
961: AND ppa2.effective_date
962: BETWEEN per.effective_start_date
963: AND per.effective_end_date);
964: --
965: hr_utility.set_location('pytrgl.trans_pay_costs', 100);
966: --
967: COMMIT;
968: --
969: END LOOP;
967: COMMIT;
968: --
969: END LOOP;
970: --
971: hr_utility.set_location('pytrgl.trans_pay_costs',110);
972: --
973: CLOSE transfer_payrolls;
974: --
975: dbms_sql.close_cursor(sql_curs);
973: CLOSE transfer_payrolls;
974: --
975: dbms_sql.close_cursor(sql_curs);
976: --
977: hr_utility.set_location('pytrgl.trans_pay_costs',120);
978: --
979: END trans_pay_costs;
980:
981: --
975: dbms_sql.close_cursor(sql_curs);
976: --
977: hr_utility.set_location('pytrgl.trans_pay_costs',120);
978: --
979: END trans_pay_costs;
980:
981: --
982: /* MULTI-THREADED SOLUTION */
983: --
980:
981: --
982: /* MULTI-THREADED SOLUTION */
983: --
984: PROCEDURE trans_pay_costs_mt
985: (i_payroll_action_id NUMBER)
986: IS
987: --
988: --
1110: l_asg_join VARCHAR2(500);
1111: --
1112: BEGIN
1113: --
1114: hr_utility.set_location('pytrgl.trans_pay_costs_mt',10);
1115: --
1116: sql_curs := dbms_sql.open_cursor;
1117: --
1118: OPEN transfer_payrolls (i_payroll_action_id);
1116: sql_curs := dbms_sql.open_cursor;
1117: --
1118: OPEN transfer_payrolls (i_payroll_action_id);
1119: --
1120: hr_utility.set_location('pytrgl.trans_pay_costs_mt',20);
1121: --
1122: -- Bug 1066820 avoid passing in hard coded strings.
1123: --
1124: select user_je_source_name
1125: into l_source_name
1126: from gl_je_sources_vl
1127: where je_source_name = 'Payroll';
1128: --
1129: hr_utility.set_location('pytrgl.trans_pay_costs_mt',25);
1130: --
1131: select user_je_category_name
1132: into l_category_name
1133: from gl_je_categories_vl
1132: into l_category_name
1133: from gl_je_categories_vl
1134: where je_category_name = 'Payroll';
1135: --
1136: hr_utility.set_location('pytrgl.trans_pay_costs_mt',27);
1137: --
1138: select bus.currency_code, bus.business_group_id
1139: into l_bus_currency_code, l_bus_grp_id
1140: from per_business_groups_perf bus,
1141: pay_payroll_actions ppa
1142: where ppa.payroll_action_id = i_payroll_action_id
1143: and bus.business_group_id = ppa.business_group_id;
1144: --
1145: hr_utility.set_location('pytrgl.trans_pay_costs',28);
1146: --
1147: -- Find if use an accouting date of date_earned
1148: -- (default is effective_date)
1149: --
1169: when others then
1170: l_rvb_acc_date := 'P';
1171: end;
1172: --
1173: hr_utility.set_location('pytrgl.trans_pay_costs',29);
1174: --
1175: -- Find if should populate gl_interface.group_id
1176: -- (default is to leave this column blank)
1177: -- If so we populate it with the TGL payroll_action_id
1197: c_payroll_id,
1198: c_set_of_books_id,
1199: c_pay_id;
1200: --
1201: hr_utility.set_location('pytrgl.trans_pay_costs_mt',30);
1202: --
1203: EXIT WHEN transfer_payrolls%NOTFOUND;
1204: --
1205: hr_utility.set_location('pytrgl.trans_pay_costs_mt',32);
1201: hr_utility.set_location('pytrgl.trans_pay_costs_mt',30);
1202: --
1203: EXIT WHEN transfer_payrolls%NOTFOUND;
1204: --
1205: hr_utility.set_location('pytrgl.trans_pay_costs_mt',32);
1206: --
1207: if (c_action_type in ('C', 'S')) then
1208:
1209: select decode(ppa1.action_type, 'S', ppa1.effective_date,
1238: -- required payroll. Use string concatenation method to avoid performance hit
1239: -- ie only join to per_all_assignments_f if have to.
1240: if ((c_action_type = 'EC' or c_action_type = 'CP') and
1241: c_pay_id is null) then
1242: hr_utility.set_location('pytrgl.trans_pay_costs_mt',33);
1243: l_asg_tab := 'per_all_assignments_f paf,';
1244: l_asg_join :=
1245: 'AND paf.assignment_id = '||'p'||'a.assignment_id
1246: AND :c_run_date between paf.effective_start_date
1246: AND :c_run_date between paf.effective_start_date
1247: and paf.effective_end_date
1248: AND paf.payroll_id = :c_payroll_id';
1249: else
1250: hr_utility.set_location('pytrgl.trans_pay_costs_mt',34);
1251: l_asg_tab := '';
1252: l_asg_join := '';
1253: end if;
1254:
1252: l_asg_join := '';
1253: end if;
1254:
1255: --
1256: hr_utility.set_location('pytrgl.trans_pay_costs_mt',35);
1257: --
1258: -- Get payrolls currency conversion rate type
1259: -- handle fact that it may be null
1260: --
1265: c_conversion_date := c_accounting_date;
1266:
1267: exception
1268: when no_data_found then
1269: hr_utility.set_location('pytrgl.trans_pay_costs',37);
1270: l_currency_type := null;
1271: c_conversion_date := null;
1272: end;
1273: --
1280: --
1281: pay_segment_list := NULL;
1282: gl_segment_list := NULL;
1283: --
1284: hr_utility.set_location('pytrgl.trans_pay_costs_mt',40);
1285: --
1286: -- Dynamically build up the segment lists for the payroll.
1287: FOR flex_segs IN flex_segments ( c_payroll_id, c_set_of_books_id )
1288: LOOP
1286: -- Dynamically build up the segment lists for the payroll.
1287: FOR flex_segs IN flex_segments ( c_payroll_id, c_set_of_books_id )
1288: LOOP
1289: --
1290: hr_utility.set_location('pytrgl.trans_pay_costs_mt',50);
1291: --
1292: gl_segment_list := gl_segment_list ||
1293: flex_segs.gl_account_segment ||',';
1294: --
1291: --
1292: gl_segment_list := gl_segment_list ||
1293: flex_segs.gl_account_segment ||',';
1294: --
1295: hr_utility.set_location('pytrgl.trans_pay_costs_mt',60);
1296: --
1297: -- Payroll segment list needs to MIN() function as not grouped
1298: -- by each segment.
1299: --
1306: --
1307: prev_payroll_id := c_payroll_id;
1308: prev_sob_id := c_set_of_books_id;
1309: --
1310: hr_utility.set_location('pytrgl.trans_pay_costs_mt',65);
1311: --
1312: -- For Payment Costs should not populate segment columns
1313: -- in gl_interface : bug 6169000
1314: --
1319: l_pay_segment_list := pay_segment_list;
1320: l_gl_segment_list := gl_segment_list;
1321: end if;
1322: --
1323: hr_utility.set_location('pytrgl.trans_pay_costs_mt',70);
1324: --
1325: -- Put the statement into the cursor and parse. Don't know how long
1326: -- the segment list is so we cannot bind to variables.
1327: --
1467: pgl.currency_code',
1468: dbms_sql.v7);
1469: end if;
1470: --
1471: hr_utility.set_location('pytrgl.trans_pay_costs_mt',80);
1472: --
1473: -- Bind the variable values to the cursor values.
1474: --
1475: dbms_sql.bind_variable(sql_curs,'c_run_action_id',
1511: -- Execute the insert statment.
1512: --
1513: rows_processed := dbms_sql.execute(sql_curs);
1514: --
1515: hr_utility.set_location('pytrgl.trans_pay_costs_mt',90);
1516: --
1517: END LOOP;
1518: --
1519: hr_utility.set_location('pytrgl.trans_pay_costs_mt',100);
1515: hr_utility.set_location('pytrgl.trans_pay_costs_mt',90);
1516: --
1517: END LOOP;
1518: --
1519: hr_utility.set_location('pytrgl.trans_pay_costs_mt',100);
1520: --
1521: CLOSE transfer_payrolls;
1522: --
1523: dbms_sql.close_cursor(sql_curs);
1521: CLOSE transfer_payrolls;
1522: --
1523: dbms_sql.close_cursor(sql_curs);
1524: --
1525: hr_utility.set_location('pytrgl.trans_pay_costs_mt',110);
1526: --
1527: COMMIT;
1528: --
1529: hr_utility.set_location('pytrgl.trans_pay_costs_mt',120);
1525: hr_utility.set_location('pytrgl.trans_pay_costs_mt',110);
1526: --
1527: COMMIT;
1528: --
1529: hr_utility.set_location('pytrgl.trans_pay_costs_mt',120);
1530: --
1531: END trans_pay_costs_mt;
1532: --
1533: PROCEDURE trans_ass_costs
1527: COMMIT;
1528: --
1529: hr_utility.set_location('pytrgl.trans_pay_costs_mt',120);
1530: --
1531: END trans_pay_costs_mt;
1532: --
1533: PROCEDURE trans_ass_costs
1534: (i_assignment_action_id NUMBER,
1535: sla_mode NUMBER)
1583: --
1584: if (c_action_type IN ('C', 'S')) then
1585: --
1586: -- Costing or Retrocostong hence know run result populated
1587: -- in pay_costs.
1588: --
1589: hr_utility.set_location('pytrgl.trans_ass_costs',20);
1590: --
1591: SELECT pa2.assignment_action_id,
1623: SUM(DECODE(cst.debit_or_credit,'D',cst.costed_value,0)),
1624: SUM(DECODE(cst.debit_or_credit,'C',cst.costed_value,0))
1625: FROM pay_payroll_actions ppa, -- run payroll action
1626: pay_assignment_actions raa,
1627: pay_costs cst,
1628: pay_run_results rr,
1629: pay_element_types_f et,
1630: pay_input_values_f IV
1631: WHERE cst.assignment_action_id = c_assignment_action_id
1770: --
1771: elsif (c_action_type = 'EC') then
1772: --
1773: -- Estimate Costing hence run result not populated
1774: -- in pay_costs.
1775: --
1776: hr_utility.set_location('pytrgl.trans_ass_costs',50);
1777: --
1778: --
1791: end;
1792: end if;
1793: l_date_used := g_date_used;
1794: --
1795: hr_utility.set_location('pytrgl.trans_pay_costs',29);
1796: --
1797: -- get accounting_date according to TGL_DATE_USED
1798: -- for use with the reversal costs
1799: --
1835: SUM(DECODE(cst.debit_or_credit,'D',cst.costed_value,0)),
1836: SUM(DECODE(cst.debit_or_credit,'C',cst.costed_value,0)),
1837: decode (CST.source_id, null, null, l_accounting_date)
1838: FROM pay_payroll_actions ppa, -- TGL payroll action
1839: pay_costs cst,
1840: pay_input_values_f IV,
1841: pay_element_types_f et
1842: WHERE ppa.payroll_action_id = t_payroll_action_id
1843: AND cst.assignment_action_id = c_assignment_action_id