894: -- bulk collect the resources who passed the mandatory competence
895: -- check and their availability into plsql tables.
896:
897: -- need to know the number of assignment days because the
898: -- pa_forecast_items table does not store unassigned time
899: -- resource records with 0 hours.
900: -- This will be used in the following sql statement...
901: --
902: -- hr_utility.trace('SEARCH MODE IS' || p_search_mode);
904:
905: IF p_search_mode = 'RESOURCE' THEN
906:
907: SELECT count(*) INTO l_assignment_days
908: FROM pa_forecast_items
909: WHERE assignment_id = p_search_criteria.assignment_id
910: AND delete_flag = 'N'
911: AND error_flag IN ('Y','N')
912: AND item_date >= trunc(SYSDATE)
935: INSERT INTO PA_FI_ASSIG_TEMP
936: (
937: SELECT asgmt.item_date ,
938: asgmt.item_quantity
939: FROM pa_forecast_items asgmt
940: WHERE asgmt.assignment_id = p_search_criteria.assignment_id
941: AND asgmt.delete_flag = 'N'
942: AND asgmt.error_flag IN ('Y','N')
943: AND asgmt.item_date >= trunc(SYSDATE)
949: l_availability_tbl(k) := 0;
950: l_pot_availability_tbl(k) := 0;
951: END LOOP;
952: END IF;
953: -- Bug Ref # 7457064, Removed multiple joins of PA_FORECAST_ITEMS
954: -- Using the temp table instead.
955: --Bug 6911907: Changed the index to PA_FORECAST_ITEMS_N5 from PA_FORECAST_ITEMS_N3
956: --Bug 6911907: Changed the index back to PA_FORECAST_ITEMS_N3
957: -- Added filter condition
951: END LOOP;
952: END IF;
953: -- Bug Ref # 7457064, Removed multiple joins of PA_FORECAST_ITEMS
954: -- Using the temp table instead.
955: --Bug 6911907: Changed the index to PA_FORECAST_ITEMS_N5 from PA_FORECAST_ITEMS_N3
956: --Bug 6911907: Changed the index back to PA_FORECAST_ITEMS_N3
957: -- Added filter condition
958: stmt_select := 'SELECT /*+ INDEX (res, PA_FORECAST_ITEMS_N3) */ ' ||
959: ' res.person_id, ' ||
952: END IF;
953: -- Bug Ref # 7457064, Removed multiple joins of PA_FORECAST_ITEMS
954: -- Using the temp table instead.
955: --Bug 6911907: Changed the index to PA_FORECAST_ITEMS_N5 from PA_FORECAST_ITEMS_N3
956: --Bug 6911907: Changed the index back to PA_FORECAST_ITEMS_N3
957: -- Added filter condition
958: stmt_select := 'SELECT /*+ INDEX (res, PA_FORECAST_ITEMS_N3) */ ' ||
959: ' res.person_id, ' ||
960: ' TRUNC(SUM(DECODE(SIGN( ' ||
954: -- Using the temp table instead.
955: --Bug 6911907: Changed the index to PA_FORECAST_ITEMS_N5 from PA_FORECAST_ITEMS_N3
956: --Bug 6911907: Changed the index back to PA_FORECAST_ITEMS_N3
957: -- Added filter condition
958: stmt_select := 'SELECT /*+ INDEX (res, PA_FORECAST_ITEMS_N3) */ ' ||
959: ' res.person_id, ' ||
960: ' TRUNC(SUM(DECODE(SIGN( ' ||
961: ' (nvl(res.capacity_quantity, 0) - nvl(res.confirmed_qty, 0) - ' ||
962: ' nvl(res.provisional_qty,0)) / asgmt.item_quantity-1),1, 1, ' ||
968: ' greatest((nvl(res.capacity_quantity, 0) - ' ||
969: ' nvl(res.confirmed_qty, 0)), 0)/ asgmt.item_quantity))/ :1 ' || '* 100) ';
970:
971: stmt_from := ' FROM ' ||
972: ' PA_FORECAST_ITEMS res, ' ||
973: ' PA_FI_ASSIG_TEMP asgmt ';
974:
975: stmt_where := ' WHERE ' ||
976: ' res.forecast_item_type = ''U'' ' ||
1028: -- hr_utility.trace('end_date is ' || to_char(p_search_criteria.end_date, 'DD-MON-YYYY'));
1029: --
1030: -- Caculation from forecast items until new table solution
1031: --
1032: SELECT /*+ ORDERED USE_NL(srt res) INDEX (res, PA_FORECAST_ITEMS_N3)*/srt.person_id, count(res.resource_id)
1033: BULK COLLECT INTO l_person_id_tbl, l_days_in_period_tbl
1034: FROM PA_SEARCH_RESULTS_TEMP srt,
1035: PA_FORECAST_ITEMS res
1036: WHERE srt.resource_id = res.resource_id
1031: --
1032: SELECT /*+ ORDERED USE_NL(srt res) INDEX (res, PA_FORECAST_ITEMS_N3)*/srt.person_id, count(res.resource_id)
1033: BULK COLLECT INTO l_person_id_tbl, l_days_in_period_tbl
1034: FROM PA_SEARCH_RESULTS_TEMP srt,
1035: PA_FORECAST_ITEMS res
1036: WHERE srt.resource_id = res.resource_id
1037: AND res.forecast_item_type = 'U'
1038: AND res.delete_flag = 'N'
1039: AND res.error_flag IN ('Y','N')
1061: l_days_in_period_tbl(i) * 100)
1062: INTO l_pot_availability_tbl(i),
1063: l_availability_tbl(i)
1064: FROM PA_SEARCH_RESULTS_TEMP srt,
1065: PA_FORECAST_ITEMS res
1066: WHERE srt.person_id = l_person_id_tbl(i)
1067: AND srt.resource_id = res.resource_id
1068: AND res.forecast_item_type = 'U'
1069: AND res.delete_flag = 'N'
1176: -- that some people in the denorm table meet the criteria but
1177: -- were not updated in the above update statement because they
1178: -- were not in l_person_id_tbl(k) because they were not available
1179: -- on ANY of the requirement days. Resource records with 0 hours
1180: -- do not exist in the pa_forecast_items table.
1181: -- In that case we need to update the availability to 0 and update
1182: -- the resource org name and candidate score.
1183: -- NOTE that the update only happens if
1184: -- p_search_criteria.min_availability = 0 AND