37: ,parent_invoice_dist_id
38: ,book_type_code
39: ,line_status
40: ,line_type_lookup_code
41: FROM fa_mass_additions_gt
42: ORDER BY 2,1;
43:
44: BEGIN
45: IF NOT G_DUMP_GT_RECS THEN
93: l_debug_info VARCHAR2(240);
94: l_calling_fn VARCHAR2(200);
95:
96: BEGIN
97: l_calling_fn := 'FA_MASS_ADDITIONS_PKG.Get_Account_Segment';
98:
99: if (g_log_level_rec.statement_level) then
100: fa_debug_pkg.add(l_calling_fn, 'Calling FND_FLEX_EXT.Get_segments',p_coa_id
101: ,p_log_level_rec => g_log_level_rec);
255: where gt3.clearing_acct = gt1.clearing_acct);
256:
257: l_count := SQL%ROWCOUNT;
258: DebugLog( 'No of Records Deleted ', to_char(l_count));
259: DebugLog( 'Updating parent lines in ', 'fa_mass_additions_gt' );
260:
261:
262: savepoint FAMADC_preprocess3;
263:
262: savepoint FAMADC_preprocess3;
263:
264: -- now update the parents
265: l_sql := '
266: update /*+ index(gt FA_MASS_ADDITIONS_GT_N2) */ fa_mass_additions_gt gt
267: set (asset_type, line_status, book_type_code) =
268: (select /*+ index(fca FA_CATEGORY_ACCOUNTS_GT_N2 */
269: decode(gt.asset_type,
270: null, decode(glcc.account_type,
308: ,p_book_type_code;
309:
310: l_count := SQL%ROWCOUNT;
311: DebugLog( 'No of Records Updated ', to_char(l_count));
312: DebugLog( 'Updating first set of child lines lines in ', 'fa_mass_additions_gt' );
313:
314: -- update the child lines which have their parent in the gt
315: -- book may be null on the parent too
316:
316:
317:
318: savepoint FAMADC_preprocess4;
319:
320: update /*+ index(gt1 FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt1
321: set (asset_type, line_status , book_type_code) =
322: (select /*+ index(gt2 FA_MASS_ADDITIONS_GT_N3) */
323: gt2.asset_type,
324: decode(gt2.line_status,
318: savepoint FAMADC_preprocess4;
319:
320: update /*+ index(gt1 FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt1
321: set (asset_type, line_status , book_type_code) =
322: (select /*+ index(gt2 FA_MASS_ADDITIONS_GT_N3) */
323: gt2.asset_type,
324: decode(gt2.line_status,
325: 'VALID', 'VALID_CHILD1',
326: gt2.line_status), -- OTHER BOOK / REJECTED
325: 'VALID', 'VALID_CHILD1',
326: gt2.line_status), -- OTHER BOOK / REJECTED
327: nvl(gt1.book_type_code,
328: gt2.book_type_code)
329: from fa_mass_additions_gt gt2
330: where gt2.invoice_distribution_id = gt1.parent_invoice_dist_id)
331: where gt1.line_type_lookup_code not in ('ITEM', 'ACCRUAL')
332: and gt1.ledger_category_code = 'P'
333: and gt1.line_status = 'NEW'
331: where gt1.line_type_lookup_code not in ('ITEM', 'ACCRUAL')
332: and gt1.ledger_category_code = 'P'
333: and gt1.line_status = 'NEW'
334: and exists
335: (select /*+ index(gt3 FA_MASS_ADDITIONS_GT_N3) */ 1
336: from fa_mass_additions_gt gt3
337: where gt3.invoice_distribution_id = gt1.parent_invoice_dist_id);
338:
339:
332: and gt1.ledger_category_code = 'P'
333: and gt1.line_status = 'NEW'
334: and exists
335: (select /*+ index(gt3 FA_MASS_ADDITIONS_GT_N3) */ 1
336: from fa_mass_additions_gt gt3
337: where gt3.invoice_distribution_id = gt1.parent_invoice_dist_id);
338:
339:
340: l_count := SQL%ROWCOUNT;
338:
339:
340: l_count := SQL%ROWCOUNT;
341: DebugLog( 'No of Records Updated ', to_char(l_count));
342: DebugLog( 'Updating second set of child lines lines in ', 'fa_mass_additions_gt' );
343:
344:
345: savepoint FAMADC_preprocess5;
346:
348: -- these are lines whose parents were brought over in
349: -- previous runs. Per AP dependancy, the book is always
350: -- populated on such lines ***
351:
352: update /*+ index(gt1 FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt1
353: set (asset_type, line_status) =
354: (select distinct mad.asset_type,
355: decode(mad.posting_status,
356: 'POSTED', 'VALID_ORPHAN1',
355: decode(mad.posting_status,
356: 'POSTED', 'VALID_ORPHAN1',
357: 'DELETED', 'VALID_ORPHAN2',
358: 'VALID_CHILD2')
359: from fa_mass_additions mad
360: where mad.book_type_code(+) = p_book_type_code
361: and mad.invoice_distribution_id(+) = gt1.parent_invoice_dist_id
362: and mad.invoice_id(+) = gt1.invoice_id
363: and mad.parent_mass_addition_id(+) is null
367: and gt1.ledger_category_code = 'P'
368: and gt1.line_status = 'NEW'
369: and exists
370: (select 1
371: from fa_mass_additions mad
372: where mad.book_type_code(+) = p_book_type_code
373: and mad.invoice_distribution_id(+) = gt1.parent_invoice_dist_id
374: and mad.invoice_id(+) = gt1.invoice_id
375: and mad.parent_mass_addition_id(+) is null);
376:
377:
378: l_count := SQL%ROWCOUNT;
379: DebugLog( 'No of Records Updated ', to_char(l_count));
380: DebugLog( 'Updating third set of child lines lines in ', 'fa_mass_additions_gt' );
381:
382: savepoint FAMADC_preprocess6;
383:
384:
385: -- for remaining orphan lines fire the clearing account validation
386: -- if successful they will end up in the interface with
387: -- asset type derived from parent and no merge status
388:
389: update /*+ index(gt FA_MASS_ADDITIONS_GT_N2) */ fa_mass_additions_gt gt
390: set parent_payables_ccid =
391: (select min(payables_code_combination_id)
392: from fa_asset_invoices ai
393: where invoice_distribution_id = gt.parent_invoice_dist_id)
397:
398: savepoint FAMADC_preprocess7;
399:
400: l_sql := '
401: update /*+ index(gt FA_MASS_ADDITIONS_GT_N2) */ fa_mass_additions_gt gt
402: set (asset_type, line_status, book_type_code) =
403: (select /*+ index(fca FA_CATEGORY_ACCOUNTS_GT_N2 */
404: decode(asset_type,
405: null, decode(glcc.account_type,
443: ,p_book_type_code;
444:
445: l_count := SQL%ROWCOUNT;
446: DebugLog( 'No of Records Updated ', to_char(l_count));
447: DebugLog( 'Updating depreciate_flag in ', 'fa_mass_additions_gt' );
448:
449:
450: savepoint FAMADC_preprocess8;
451:
449:
450: savepoint FAMADC_preprocess8;
451:
452: -- update the depreciate_flag and inventorial on valid lines
453: update /*+ index(gt FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt
454: set depreciate_flag =
455: (select decode(gt.asset_type
456: ,'EXPENSED','NO'
457: ,nvl(CBD.depreciate_flag, 'YES'))
498: ,x_msg_data OUT NOCOPY VARCHAR2
499: ) IS
500:
501:
502: l_calling_fn varchar2(40) := 'FA_MASS_ADDITIONS_PKG.create_lines';
503:
504: l_count INTEGER;
505:
506: l_date_ineffective FA_BOOK_CONTROLS.DATE_INEFFECTIVE%TYPE;
626: raise fa_ineffective_book;
627: end if;
628:
629: DumpGTRecords ( 'MAIN (FAAPI)');
630: DebugLog('Insert FA_MASS_ADDITIONS with ITEM/ACCRUAL lines for primary ledger ',p_book_type_code );
631:
632: savepoint FAMADC_create2;
633:
634: insert into fa_mass_additions(
630: DebugLog('Insert FA_MASS_ADDITIONS with ITEM/ACCRUAL lines for primary ledger ',p_book_type_code );
631:
632: savepoint FAMADC_create2;
633:
634: insert into fa_mass_additions(
635: mass_addition_id ,
636: asset_number ,
637: tag_number ,
638: description ,
732: invoice_distribution_id ,
733: invoice_line_number ,
734: invoice_payment_id ,
735: warranty_number)
736: select /*+ index(gt FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_s.nextval,
737: gt.asset_number ,
738: gt.tag_number ,
739: gt.description ,
740: gt.asset_category_id ,
841: gt.invoice_distribution_id ,
842: gt.invoice_line_number ,
843: gt.invoice_payment_id ,
844: gt.warranty_number
845: from fa_mass_additions_gt gt
846: where gt.book_type_code = p_book_type_code
847: and gt.line_type_lookup_code in ('ITEM', 'ACCRUAL')
848: and gt.line_status = 'VALID';
849:
850: l_count := SQL%ROWCOUNT;
851: DebugLog( 'No of Records Inserted ', to_char(l_count) );
852:
853:
854: DebugLog( 'Updating FA_MASS_ADDITIONS_GT for child lines', p_book_type_code );
855:
856:
857: savepoint FAMADC_create3;
858:
855:
856:
857: savepoint FAMADC_create3;
858:
859: update /*+ leading(gt) index(gt FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt1
860: set (posting_status
861: ,parent_mass_addition_id
862: ,split_merged_code
863: ,merged_code
884: decode(mad.posting_status,
885: 'POSTED', null,
886: 'DELETE', null,
887: mad.mass_addition_id)
888: from fa_mass_additions mad,
889: fa_mass_additions_gt gt
890: where gt.rowid = gt1.rowid
891: and mad.invoice_distribution_id(+) = gt.parent_invoice_dist_id
892: and mad.book_type_code(+) = p_book_type_code
885: 'POSTED', null,
886: 'DELETE', null,
887: mad.mass_addition_id)
888: from fa_mass_additions mad,
889: fa_mass_additions_gt gt
890: where gt.rowid = gt1.rowid
891: and mad.invoice_distribution_id(+) = gt.parent_invoice_dist_id
892: and mad.book_type_code(+) = p_book_type_code
893: and mad.invoice_distribution_id(+) is not null
896: where gt1.book_type_code = p_book_type_code
897: and gt1.line_status in ('VALID_CHILD1', 'VALID_CHILD2');
898:
899:
900: DebugLog( 'Inserting FA_MASS_ADDITIONS with non-ITEM/ACCRUAL lines for primary', p_book_type_code );
901:
902: savepoint FAMADC_create4;
903:
904: insert into fa_mass_additions(
900: DebugLog( 'Inserting FA_MASS_ADDITIONS with non-ITEM/ACCRUAL lines for primary', p_book_type_code );
901:
902: savepoint FAMADC_create4;
903:
904: insert into fa_mass_additions(
905: mass_addition_id ,
906: asset_number ,
907: tag_number ,
908: description ,
1002: invoice_distribution_id ,
1003: invoice_line_number ,
1004: invoice_payment_id ,
1005: warranty_number)
1006: select /*+ index(gt FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_s.nextval ,
1007: gt.asset_number ,
1008: gt.tag_number ,
1009: gt.description ,
1010: gt.asset_category_id ,
1108: gt.invoice_distribution_id ,
1109: gt.invoice_line_number ,
1110: gt.invoice_payment_id ,
1111: gt.warranty_number
1112: from fa_mass_additions_gt gt
1113: where gt.book_type_code = p_book_type_code
1114: and gt.line_status in ('VALID_CHILD1', 'VALID_CHILD2',
1115: 'VALID_ORPHAN1', 'VALID_ORPHAN2', 'VALID_ORPHAN3');
1116:
1122: savepoint FAMADC_create5;
1123:
1124: -- Mark the parent line of DISCOUNT lines as Merged Parent, if not already done by prior(AP) non-item lines
1125: -- Performance bugfix 4945306 - Added invoice_id clause to the sub-select
1126: update fa_mass_additions ma
1127: set ma.split_merged_code = 'MP',
1128: ma.merged_code = 'MP',
1129: ma.sum_units = 'NO'
1130: where ma.posting_status not in ('POSTED', 'DELETE')
1134: and ma.split_merged_code is null
1135: and ma.invoice_payment_id is null
1136: and exists
1137: (select 1
1138: from fa_mass_additions mac,
1139: fa_mass_additions_gt gt
1140: where mac.posting_status = 'MERGED'
1141: and mac.book_type_code = p_book_type_code
1142: and mac.merged_code = 'MC'
1135: and ma.invoice_payment_id is null
1136: and exists
1137: (select 1
1138: from fa_mass_additions mac,
1139: fa_mass_additions_gt gt
1140: where mac.posting_status = 'MERGED'
1141: and mac.book_type_code = p_book_type_code
1142: and mac.merged_code = 'MC'
1143: and mac.merge_parent_mass_additions_id = ma.mass_addition_id
1160: gt.ledger_id,
1161: mad.mass_addition_id,
1162: gt.fixed_assets_cost,
1163: 0
1164: from fa_mass_additions mad,
1165: fa_mass_additions_gt gt
1166: where mad.book_type_code = p_book_type_code
1167: and mad.invoice_distribution_id = gt.invoice_distribution_id
1168: and gt.book_type_code = p_book_type_code
1161: mad.mass_addition_id,
1162: gt.fixed_assets_cost,
1163: 0
1164: from fa_mass_additions mad,
1165: fa_mass_additions_gt gt
1166: where mad.book_type_code = p_book_type_code
1167: and mad.invoice_distribution_id = gt.invoice_distribution_id
1168: and gt.book_type_code = p_book_type_code
1169: and gt.ledger_category_code <> 'P';
1172: DebugLog( 'No of Records Inserted ', to_char(l_count));
1173:
1174: -- update for rejected is already handled in the preprocessing logic
1175:
1176: DebugLog( 'Updating successful/processed rows in ', 'fa_mass_additions_gt' );
1177:
1178: savepoint FAMADC_create7;
1179:
1180:
1177:
1178: savepoint FAMADC_create7;
1179:
1180:
1181: update /*+ index(gt FA_MASS_ADDITIONS_GT_N1) */ fa_mass_additions_gt gt
1182: set gt.line_status = 'PROCESSED'
1183: where book_type_code = p_book_type_code
1184: and line_status like 'VALID%'
1185: and gt.invoice_distribution_id IN
1183: where book_type_code = p_book_type_code
1184: and line_status like 'VALID%'
1185: and gt.invoice_distribution_id IN
1186: ( select mad.invoice_distribution_id
1187: from fa_mass_additions mad
1188: where mad.invoice_distribution_id = gt.invoice_distribution_id
1189: and mad.book_type_code = p_book_type_code
1190: and mad.create_batch_id = gt.create_batch_id
1191: );