21: /* This part populates the Organization_id if it has not been provided by
22: the user.There will be a check done to see if the user has not entered both of t
23: hem */
24:
25: fnd_file.put_line(fnd_file.log, '---------start of the concurrent program for validating CICDI-------------');
26:
27: l_stmt_no := 10;
28:
29: Update CST_ITEM_CST_DTLS_INTERFACE ct
51: );
52:
53: l_stmt_no := 30;
54:
55: fnd_file.put_line(fnd_file.log, 'after checking for organization_id validity');
56:
57: /* Select the corresponding organization_id from mtl_parameters given the
58: organization code.*/
59:
106:
107: commit;
108:
109: l_stmt_no := 60;
110: fnd_file.put_line(fnd_file.log,'after assigning the transaction_id');
111:
112: /* check for the organization to be a costing organization */
113:
114: UPDATE CST_ITEM_CST_DTLS_INTERFACE ct
121: WHERE mp.cost_organization_id <> mp.organization_id
122: AND mp.organization_id = ct.organization_id );
123:
124: l_stmt_no := 61;
125: fnd_file.put_line(fnd_file.log,'done checking for the org to be costing org');
126:
127: /* check to see if the user has input a valid inventory_item_id */
128: Update CST_ITEM_CST_DTLS_INTERFACE ct set
129: error_flag = 'E',
134: AND inventory_item_id is null;
135:
136: l_stmt_no := 62;
137:
138: fnd_file.put_line(fnd_file.log,'done checking for null item_id');
139:
140: /* check to see if the user has input a valid inventory_item_id */
141: Update CST_ITEM_CST_DTLS_INTERFACE ct set
142: error_flag = 'E',
147: AND NOT EXISTS (select 1 from mtl_system_items msi
148: where ct.organization_id = msi.organization_id
149: AND ct.inventory_item_id = msi.inventory_item_id
150: );
151: fnd_file.put_line(fnd_file.log,'done checking for invalid inventory_item_id');
152: l_stmt_no := 63;
153:
154: /* Now call the function to set the defaults for the CIC flags */
155:
169: AND ct.group_id = SEQ_NEXTVAL
170: AND ct.inventory_asset_flag <> 1 ;
171:
172: l_stmt_no := 66;
173: fnd_file.put_line(fnd_file.log,'done checking for the inventory_asset flag');
174:
175:
176: l_stmt_no := 70;
177:
187: AND error_flag is null;
188:
189: l_stmt_no := 90;
190:
191: fnd_file.put_line(fnd_file.log,'after checking for cost element for null');
192:
193:
194: /* Check to see if a valid cost_element has been provided.If only the cost_element_name is provided then, fill up the id */
195:
213: AND ct.error_flag is null;
214:
215: l_stmt_no := 150;
216:
217: fnd_file.put_line(fnd_file.log,'done checking for cost elements validity and picking up the cost element id if it has not been defined');
218:
219:
220: /*----------Checking for sub elements validity--------------------------*/
221: /* There is a special case when checking for the resource id validation.*/
253:
254:
255: l_stmt_no := 170;
256:
257: fnd_file.put_line(fnd_file.log,'done checking for validity of resource_id and picking it up if it has not been supplied');
258:
259: /* Checking for the validity of Activity ID and Activity name if provided */
260:
261: Update CST_ITEM_CST_DTLS_INTERFACE ct set
280: AND ct.activity is not null
281: AND ct.error_flag is null
282: AND ct.group_id = SEQ_NEXTVAL;
283:
284: fnd_file.put_line(fnd_file.log,'done checking for activity ID and assigning it');
285:
286: l_stmt_no := 180;
287:
288:
296: AND (ct.resource_id is null AND ct.resource_code is null);
297:
298: l_stmt_no := 190;
299:
300: fnd_file.put_line(fnd_file.log,'done assigning default sub elements');
301:
302: /* if the resource_id is still null,then that means the user has not provided
303: a default sub element that is necessary */
304:
325: AND bm.cost_element_id = ct.cost_element_id
326: AND bm.resource_id = ct.resource_id
327: AND ((sysdate >= NVL(bm.disable_date,sysdate+1)) OR (bm.allow_costs_flag = 2)));
328:
329: fnd_file.put_line(fnd_file.log,'done checking for the disable_date and allow_costs_flag for the resource');
330: l_stmt_no := 205;
331:
332: /* at this point we have validated org_id,cost_type,cost element,resource
333: ,inventory_item.We will now have to check if the functional currency flag =1
348: );
349:
350: l_stmt_no := 210;
351:
352: fnd_file.put_line(fnd_file.log,'done checking for functional currency flag');
353:
354:
355: /* set The process_flag to 2 */
356:
361: AND process_flag = 2;
362:
363: l_stmt_no := 230;
364:
365: fnd_file.put_line(fnd_file.log,'done with validations for first phase of CICDI');
366:
367: COMMIT;
368:
369: EXCEPTION
370:
371: when others then
372: rollback;
373: CONC_REQUEST := fnd_concurrent.set_completion_status('ERROR',(fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')));
374: fnd_file.put_line(fnd_file.log,'CICDI validate_phase1(' || to_char(l_stmt_no) || '),' || to_char(SQLCODE) || ',' || substr(SQLERRM,1,180));
375: Error_number := 1;
376:
377: END validate_phase1;
378:
385: BEGIN
386:
387: Error_number := 0;
388:
389: fnd_file.put_line(fnd_file.log,'------------Start of the second phase for CICDI-----------');
390:
391:
392: SEQ_NEXTVAL := i_group_id;
393: /* This statement will check for the rollup_source_type flag to be 1 */
412: where level_type <> 1
413: AND ct.error_flag is null
414: AND ct.group_id = SEQ_NEXTVAL;
415:
416: fnd_file.put_line(fnd_file.log,'done checking for level_type flag to be 1 ');
417:
418: l_stmt_no := 11;
419:
420: /* checking for the Usage rate or amount to be not null */
425: where error_flag is null
426: AND Usage_rate_or_amount is null
427: AND group_id = SEQ_NEXTVAL;
428:
429: fnd_file.put_line(fnd_file.log,'done checking for null usage rate');
430:
431: /*This statement checks for the validity of basis types.
432: FOr any other basis type other than material overhead, the only basis types allowed are item and lot.
433: But for material Overhead all 6 basis types allowed.This is inkeeping with the way the form works today.
442: where ((ct.cost_element_id IN (1,3,4,5,6) AND ct.basis_type NOT IN (1,2)) OR (ct.cost_element_id = 2 AND (ct.basis_type <= 0 OR ct.basis_type > 6)))
443: AND ct.error_flag is null
444: AND ct.group_id = SEQ_NEXTVAL;
445:
446: fnd_file.put_line(fnd_file.log,'done checking for basis types');
447:
448: /* If the basis type is activity, then check if the item_units and activity_units are provided */
449:
450: l_stmt_no := 13;
457: AND (ct.activity_units is null OR ct.item_units is null OR ct.item_units = 0)
458: AND ct.error_flag is null
459: AND ct.group_id = SEQ_NEXTVAL;
460:
461: fnd_file.put_line(fnd_file.log,'done checking for item units and activity units');
462:
463: l_stmt_no := 14;
464: /*this statement checks for the shrinkage rate value to be between 0 and 1 */
465:
470: where (ct.shrinkage_rate < 0 OR ct.shrinkage_rate >= 1)
471: AND ct.error_flag is null
472: AND ct.group_id = SEQ_NEXTVAL;
473:
474: fnd_file.put_line(fnd_file.log,'done checking for shrinkage rate to be between 0 and 1');
475: l_stmt_no := 15;
476:
477: /* check for the lot_size to be > 0 */
478: Update CST_ITEM_CST_DTLS_INTERFACE ct set
492: AND ct.error_flag is null
493: AND ct.group_id = SEQ_NEXTVAL;
494:
495: l_stmt_no := 16;
496: fnd_file.put_line(fnd_file.log,'done checking for based on rollup flag');
497:
498: /* this checks for the inventory asset flag to be 1 or 2 */
499: Update CST_ITEM_CST_DTLS_INTERFACE ct set
500: error_flag = 'E',
504: AND ct.error_flag is null
505: AND ct.group_id = SEQ_NEXTVAL;
506:
507: l_stmt_no := 18;
508: fnd_file.put_line(fnd_file.log,'done checking for inv asset flag to be 1 or 2');
509:
510: UPDATE CST_ITEM_CST_DTLS_INTERFACE set
511: error_flag = 'E',
512: error_code = 'CST_INVALID_RESRATE',
514: where error_flag is null
515: AND group_id = SEQ_NEXTVAL
516: AND ((resource_rate <> 1) AND (resource_rate is not null));
517:
518: fnd_file.put_line(fnd_file.log, 'done checking for resource rate to be 1 or null');
519:
520: /* this statement checks for the based_on_rollup flag to be set if there is a shrinkage rate mentioned*/
521:
522: Update CST_ITEM_CST_DTLS_INTERFACE ct set
527: AND ct.shrinkage_rate <> 0
528: AND ct.error_flag is null
529: AND ct.group_id = SEQ_NEXTVAL;
530:
531: fnd_file.put_line(fnd_file.log,'done checking for the based on rollup flag and shrinkage rate');
532:
533: l_stmt_no := 20;
534: /* this statement checks for the same "based_on_rollup_flag, shrinkage_rate,inventory_asset_flag" to be populated for all the rows of the same item,org,cost type combo */
535:
552: AND ct1.error_flag is null;
553:
554: l_stmt_no := 30;
555:
556: fnd_file.put_line(fnd_file.log,'done checking for the 4 flags to match for all the rows of the same item,org,cost type combo');
557:
558: /* Error out all those rows for that particular item,org,cost type combination
559: that already have rows that are errored out */
560:
571: AND ct2.group_id = SEQ_NEXTVAL)
572: AND ct1.error_flag is null
573: AND ct1.group_id = SEQ_NEXTVAL;
574:
575: fnd_file.put_line(fnd_file.log,'done erroring out rows for the same item,org,cost type combo if even one of them has errored out');
576:
577: l_stmt_no := 40;
578:
579: Update CST_ITEM_CST_DTLS_INTERFACE set
587: EXCEPTION
588:
589: when others then
590: rollback;
591: fnd_file.put_line(fnd_file.log,'CICDI table validate_phase2(' || to_char(l_stmt_no) || '),' || to_char(SQLCODE) || ',' || substr(SQLERRM,1,180));
592:
593: CONC_REQUEST := fnd_concurrent.set_completion_status('ERROR',(fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')));
594: Error_number := 1;
595:
612: l_stmt_no := 10;
613:
614: Error_number := 0;
615:
616: fnd_file.put_line(fnd_file.log,'-------------at the start of insert_csttype_and_def procedure-----------');
617:
618: Select default_cost_type_id into l_def_cost_type_id from cst_cost_types
619: where cost_type = i_new_csttype;
620:
631: ct.cost_type = i_new_csttype
632: where error_flag is null
633: and group_id = SEQ_NEXTVAL;
634:
635: fnd_file.put_line(fnd_file.log,'done updating the interface table with the new cost type');
636: l_stmt_no := 30;
637:
638: /*check for the default cost type to be valid for all the or/item combo */
639: Update CST_ITEM_CST_DTLS_INTERFACE ct set
648: and cic.cost_type_id = l_def_cost_type_id
649: and ct.inventory_item_id = cic.inventory_item_id)
650: AND (ct.lot_size is null OR ct.based_on_rollup_flag is null OR shrinkage_rate is null OR inventory_asset_flag is null) ;
651:
652: fnd_file.put_line(fnd_file.log,'done checking for the default cost type to be valid');
653: l_stmt_no := 40;
654:
655: /* now set the defaults for rollup_src_type,basis_type,resource_rate and level_type */
656:
662: where error_flag is null
663: and group_id= SEQ_NEXTVAL
664: and (rollup_source_type is null OR basis_type is null OR resource_rate is null OR level_type is null);
665:
666: fnd_file.put_line(fnd_file.log,'done setting the defaults for the first level ');
667: l_stmt_no := 50;
668:
669: /* now set the defaults from cic for the CIC columns */
670:
681: WHERE ct.error_flag is null
682: AND ct.group_id = SEQ_NEXTVAL
683: AND (ct.lot_size is null OR ct.based_on_rollup_flag is null OR ct.inventory_asset_flag is null OR ct.shrinkage_rate is null);
684:
685: fnd_file.put_line(fnd_file.log,'done setting the defaults for the CIC columns');
686:
687: EXCEPTION
688: when others then
689: rollback;
686:
687: EXCEPTION
688: when others then
689: rollback;
690: fnd_file.put_line(fnd_file.log,'CICDI insert_csttype_and_def('|| to_char(l_stmt_no) || '),' || to_char(SQLCODE) || ',' || substr(SQLERRM,1,180));
691:
692: CONC_REQUEST := fnd_concurrent.set_completion_status('ERROR',(fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')));
693: Error_number := 1;
694:
711: Error_number := 0;
712:
713: /*first get the net_yield and basis_factor and update the interface tables */
714:
715: fnd_file.put_line(fnd_file.log,'---------------entered the insert_cic_cicd procedure-----------------');
716:
717: /* The following statement sets the basis factor and net_yield_or_shrinkage_factor.
718: The basis factor will be set to values like the form does today in the applications */
719:
724: and basis_type IN (1,2,6);
725:
726: l_stmt_no := 11;
727:
728: fnd_file.put_line(fnd_file.log,'done setting the basis factor for basis type 1,2 and 6');
729:
730: /* Updating the basis factor for mat overhead cost element, sub element "resource unit"*/
731:
732: Update CST_ITEM_CST_DTLS_INTERFACE cicdi1 set
748: AND cicdi1.cost_element_id=2;
749:
750: l_stmt_no := 12;
751:
752: fnd_file.put_line(fnd_file.log,'done setting the basis factor for basis type of 3 (resource unit)');
753:
754:
755: Update CST_ITEM_CST_DTLS_INTERFACE CICDI set
756: net_yield_or_shrinkage_factor = Decode(basis_type,1,(1/(1-shrinkage_rate)),2,(1/(1-shrinkage_rate)),3,(1/(1-shrinkage_rate)),1)
756: net_yield_or_shrinkage_factor = Decode(basis_type,1,(1/(1-shrinkage_rate)),2,(1/(1-shrinkage_rate)),3,(1/(1-shrinkage_rate)),1)
757: where error_flag is null
758: and group_id = SEQ_NEXTVAL;
759:
760: fnd_file.put_line(fnd_file.log,'done setting shrinkage factor');
761: l_stmt_no :=20;
762:
763: /* now calculate the item cost for each row for basis */
764:
769: and group_id = SEQ_NEXTVAL;
770:
771: l_stmt_no := 22;
772:
773: fnd_file.put_line(fnd_file.log,'done setting the item cost for basis types 1,2,3 and 6');
774:
775: /*Now calculate the basis factor and item cost for resource value */
776:
777: Update CST_ITEM_CST_DTLS_INTERFACE cicdi1
793: AND cicdi1.basis_type = 4
794: AND cicdi1.cost_element_id = 2;
795:
796: l_stmt_no := 23;
797: fnd_file.put_line(fnd_file.log,'done setting the basis factor and item cost for basis type resource value ');
798:
799: /* Now calculate the basis factor and item cost for total value based */
800:
801: Update CST_ITEM_CST_DTLS_INTERFACE cicdi1
813: AND cicdi1.basis_type = 5
814: AND cicdi1.cost_element_id = 2;
815:
816:
817: fnd_file.put_line(fnd_file.log,'done calculating the item cost and basis factor for total value basis type');
818: l_stmt_no := 30;
819: /* Now insert first into cst_item_costs */
820:
821: /* here we check for the run option.If it is insert only mode, we error out those rows for which rows already exist in CIC for the same item,org,cost type combo.For rem and replace mode, we just delete off all the existing rows and proceed */
849: AND ct.cost_type_id = cic.cost_type_id
850: AND ct.inventory_item_id = cic.inventory_item_id);
851: END IF;
852:
853: fnd_file.put_line(fnd_file.log,'done checking for the run option and deleting or erroring out rows accordingly');
854:
855: l_stmt_no := 35;
856:
857: Insert into CST_ITEM_COSTS (Inventory_item_id,
930: WHERE error_flag is null
931: AND group_id = SEQ_NEXTVAL
932: group by organization_id,inventory_item_id,cost_type_id,based_on_rollup_flag,shrinkage_rate,lot_size,inventory_asset_flag;
933:
934: fnd_file.put_line(fnd_file.log,'after the insert into CIC. Rows -> ' || sql%rowcount);
935: fnd_file.put_line(fnd_file.log,'sucessfully completed inserting ' || to_char(SQL%ROWCOUNT)|| ' rows into cic');
936:
937:
938: update CST_ITEM_COSTS cic set (attribute_category,
931: AND group_id = SEQ_NEXTVAL
932: group by organization_id,inventory_item_id,cost_type_id,based_on_rollup_flag,shrinkage_rate,lot_size,inventory_asset_flag;
933:
934: fnd_file.put_line(fnd_file.log,'after the insert into CIC. Rows -> ' || sql%rowcount);
935: fnd_file.put_line(fnd_file.log,'sucessfully completed inserting ' || to_char(SQL%ROWCOUNT)|| ' rows into cic');
936:
937:
938: update CST_ITEM_COSTS cic set (attribute_category,
939: attribute1,
979: cici2.cost_type_id
980: FROM cst_item_costs_interface cici2
981: where group_id = SEQ_NEXTVAL);
982:
983: fnd_file.put_line(fnd_file.log,'Updated attribute info..... Rows -> ' || sql%rowcount);
984:
985: l_stmt_no := 40;
986:
987: /* Now insert into CICD */
1071: FROM CST_ITEM_CST_DTLS_INTERFACE ct
1072: WHERE ct.error_flag is null
1073: and ct.group_id = SEQ_NEXTVAL;
1074:
1075: fnd_file.put_line(fnd_file.log,'sucessfully completed inserting ' || to_char(SQL%ROWCOUNT)|| ' rows into cicd');
1076:
1077: l_stmt_no := 50;
1078:
1079: Update CST_ITEM_CST_DTLS_INTERFACE ct set
1081: WHERE error_flag is null
1082: AND group_id = SEQ_NEXTVAL
1083: AND process_flag = 4;
1084:
1085: fnd_file.put_line(fnd_file.log,'after updating the process flag to 5');
1086:
1087:
1088: IF i_del_option = 1 then
1089: delete from CST_ITEM_CST_DTLS_INTERFACE
1089: delete from CST_ITEM_CST_DTLS_INTERFACE
1090: WHERE error_flag is null
1091: AND process_flag = 5
1092: AND group_id = SEQ_NEXTVAL;
1093: fnd_file.put_line(fnd_file.log,'done deleting ' || to_char(SQL%ROWCOUNT) || ' processed rows');
1094: END IF;
1095:
1096: commit;
1097:
1097:
1098: EXCEPTION
1099: when others then
1100: rollback;
1101: fnd_file.put_line(fnd_file.log,'CICD/CICDI table insert_cic_cicd(' || to_char(l_stmt_no) || '),' || to_char(SQLCODE) || ',' || substr(SQLERRM,1,180));
1102:
1103: CONC_REQUEST := fnd_concurrent.set_completion_status('ERROR',(fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')));
1104: Error_number := 1;
1105:
1143: AND cicdi.process_flag = 1
1144: AND rownum = 1;
1145:
1146: If l_cicdi_count = 0 then
1147: fnd_file.put_line(fnd_file.log,'no rows to process in CST_ITEM_CST_DTLS_INTERFACE,quitting....');
1148: return;
1149: end If;
1150:
1151: validate_phase1(Err,i_cost_type,i_grp_id);
1170: where group_id = i_grp_id
1171: and error_flag = 'E';
1172:
1173: If (i_count > 0) then
1174: fnd_file.put_line(fnd_file.log,(fnd_message.get_string('BOM','CST_MSG_CICDI')));
1175: CONC_REQUEST := fnd_concurrent.set_completion_status('WARNING',substrb((fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')),1,240));
1176: END IF;
1177:
1178: fnd_file.put_line(fnd_file.log,'done with item costs import, quitting');
1174: fnd_file.put_line(fnd_file.log,(fnd_message.get_string('BOM','CST_MSG_CICDI')));
1175: CONC_REQUEST := fnd_concurrent.set_completion_status('WARNING',substrb((fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')),1,240));
1176: END IF;
1177:
1178: fnd_file.put_line(fnd_file.log,'done with item costs import, quitting');
1179: EXCEPTION
1180: when others then
1181: rollback;
1182: fnd_file.put_line(fnd_file.log,'Start_item_cost_import_process(), Invalid Exception Occured');
1178: fnd_file.put_line(fnd_file.log,'done with item costs import, quitting');
1179: EXCEPTION
1180: when others then
1181: rollback;
1182: fnd_file.put_line(fnd_file.log,'Start_item_cost_import_process(), Invalid Exception Occured');
1183:
1184: CONC_REQUEST := fnd_concurrent.set_completion_status('ERROR',substrb((fnd_message.get_string('BOM','CST_EXCEPTION_OCCURED')),1,240));
1185: Error_number := 1;
1186: END Start_item_cost_import_process;