DBA Data[Home] [Help]

PACKAGE BODY: APPS.IBY_TIME_OF_PURCHASE_PKG

Source


1 package body iby_time_of_purchase_pkg as
2 /*$Header: ibytopb.pls 115.7 2002/11/20 00:19:29 jleybovi ship $*/
3 
4 
5     procedure eval_factor( i_payeeid in varchar2,
6                           i_hours in integer,
7                           i_minutes in integer,
8                           o_score out nocopy integer)
9     is
10 
11     l_not_found boolean;
12     l_hours integer;
13     l_score varchar2(10);
14     l_cnt integer;
15     l_payeeid varchar2(80);
16     l_lower_range integer;
17     l_upper_range integer;
18 
19     cursor c_get_factor_config(ci_payeeid in varchar2) is
20 
21     select duration_from, duration_to, score
22     from iby_irf_timeof_purchase
23     where ( ( payeeid is null and ci_payeeid is null ) or
24           payeeid = ci_payeeid)
25     order by seq;
26 
27     begin
28 
29 
30         /*
31         ** check whether this payeeid has any entry in
32         ** for time of purchase configuration.
33         ** if not the set payeeid to null.
34         */
35 
36         select count(1) into l_cnt
37         from iby_irf_timeof_purchase
38         where payeeid = i_payeeid;
39 
40         if ( l_cnt = 0 ) then
41             l_payeeid := null;
42         else
43             l_payeeid := i_payeeid;
44         end if;
45 
46         l_not_found := true;
47 
48         -- round the hours value to nearest hour based on the
49         -- time value passed.
50 
51         -- if minutes value is greater than 0 then
52         -- add 1 to hours value. After adding 1 if hours value bcome
53         -- more than or equal to 24 then assign hours value 0.
54         -- if minutes is 0 then hours will remain same.
55         if ( i_minutes > 0 ) then
56             if ( i_hours + 1 = 24 ) then
57                 l_hours := 0;
58             else
59                 l_hours := i_hours + 1;
60             end if;
61         else
62             l_hours := i_hours;
63         end if;
64 
65         if ( c_get_factor_config%isopen ) then
66             close c_get_factor_config;
67         end if;
68 
69         <<l_ranges_loop>>
70         for i in c_get_factor_config(l_payeeid) loop
71             l_lower_range := i.duration_from;
72             l_upper_range := i.duration_to;
73 
74             -- if lower range and upper range are in sameday, i.e
75             -- upper is greater than lower.
76             if ( l_upper_range >= l_lower_range ) then
77                   if ( ( l_lower_range < l_hours ) and
78                      ( l_upper_range >= l_hours ) ) then
79                      l_not_found := false;
80                      l_score := i.score;
81                      exit l_ranges_loop;
82                   end if;
83             -- if range falls in two different days.
84             -- i.e lower is greater than upper.
85             else
86                 if ( ( ( l_hours <= 24 )  and ( l_hours > l_lower_range ) ) or
87                      ( ( l_hours >= 0 ) and ( l_hours <= l_upper_range ) ) ) then
88                     l_not_found := false;
89                     l_score := i.score;
90                     exit l_ranges_loop;
91                 end if;
92             end if;
93         end loop l_ranges_loop;
94 
95         if ( l_not_found ) then
96             raisE_application_error(-20000, 'IBY_204232#');
97         end if;
98 
99         o_score := iby_risk_scores_pkg.getScore(i_payeeid, l_score);
100 
101     end eval_factor;
102 
103 end iby_time_of_purchase_pkg;
104