DBA Data[Home] [Help]

PACKAGE BODY: APPS.POS_ENTERPRISE_UTIL_PKG

Source


1 PACKAGE BODY POS_ENTERPRISE_UTIL_PKG as
2 --$Header: POSENTRB.pls 120.2 2005/07/21 01:44:08 bitang noship $
3 
4 PROCEDURE get_enterprise_information
5   (x_party_id      OUT NOCOPY NUMBER,
6    x_party_name    OUT NOCOPY VARCHAR2,
7    x_exception_msg OUT NOCOPY VARCHAR2,
8    x_status        OUT NOCOPY VARCHAR2
9    )
10 IS
11    CURSOR l_cur IS
12       SELECT hp.party_id, hp.party_name
13 	FROM hz_parties hp, hz_code_assignments hca
14     	WHERE hca.owner_table_id = hp.party_id
15     	  AND hca.owner_table_name = 'HZ_PARTIES'
16     	  AND hca.class_category = 'POS_PARTICIPANT_TYPE'
17     	  AND hca.class_code = 'ENTERPRISE'
18     	  AND hca.status= 'A'
19     	  AND hp.status= 'A'
20     	  AND ( hca.end_date_active > sysdate or hca.end_date_active is null );
21 
22    l_rec1 l_cur%ROWTYPE;
23    l_rec2 l_cur%ROWTYPE;
24 BEGIN
25    OPEN l_cur;
26    FETCH l_cur INTO l_rec1;
27    IF l_cur%notfound THEN
28       CLOSE l_cur;
29       x_status := 'E';
30       x_exception_msg := 'enterprise party not found';
31       RETURN;
32    END IF;
33 
34    FETCH l_cur INTO l_rec2;
35    IF l_cur%found THEN
36       CLOSE l_cur;
37       x_status := 'E';
38       x_exception_msg := 'found more than 1 enterprise party';
39       RETURN;
40    END IF;
41 
42    CLOSE l_cur;
43 
44    x_party_id      := l_rec1.party_id;
45    x_party_name    := l_rec1.party_name;
46    x_status        := 'S';
47    x_exception_msg := NULL;
48 
49 END get_enterprise_information;
50 
51 PROCEDURE get_enterprise_party_name
52   ( x_party_name    OUT NOCOPY VARCHAR2,
53     x_exception_msg OUT NOCOPY VARCHAR2,
54     x_status        OUT NOCOPY VARCHAR2
55     )
56 IS
57    l_party_id NUMBER;
58 BEGIN
59    get_enterprise_information(l_party_id, x_party_name, x_exception_msg, x_status);
60 END get_enterprise_party_name;
61 
62 PROCEDURE get_enterprise_partyid
63   (x_party_id      OUT NOCOPY NUMBER,
64    x_exception_msg OUT NOCOPY VARCHAR2,
65    x_status        OUT NOCOPY VARCHAR2
66    )
67   IS
68      l_party_name hz_parties.party_name%TYPE;
69 BEGIN
70    get_enterprise_information(x_party_id, l_party_name, x_exception_msg, x_status);
71 END get_enterprise_partyid;
72 
73 PROCEDURE create_enterprise_party
74   (  x_status        OUT NOCOPY VARCHAR2
75    , x_exception_msg OUT NOCOPY VARCHAR2
76      )
77 IS
78    CURSOR l_cur IS
79       SELECT hp.party_id, hp.party_name
80 	FROM hz_parties hp, hz_code_assignments hca
81     	WHERE hca.owner_table_id = hp.party_id
82     	  AND hca.owner_table_name = 'HZ_PARTIES'
83     	  AND hca.class_category = 'POS_PARTICIPANT_TYPE'
84     	  AND hca.class_code = 'ENTERPRISE'
85     	  AND hca.status= 'A'
86     	  AND hp.status= 'A'
87 	  AND ( hca.end_date_active > sysdate or hca.end_date_active is null );
88 
89    l_party_id      NUMBER;
90    l_party_name    hz_parties.party_name%TYPE;
91    l_party_number  hz_parties.party_number%TYPE;
92    l_profile_id    NUMBER;
93 BEGIN
94    OPEN l_cur;
95    FETCH l_cur INTO l_party_id, l_party_name;
96    IF l_cur%found THEN
97       CLOSE l_cur;
98       x_status := 'E';
99       x_exception_msg := 'enterprise party already exists';
100       raise_application_error(-20001,x_exception_msg,TRUE);
101    END IF;
102    CLOSE l_cur;
103 
104    pos_party_management_pkg.classify_party
105      (l_party_id,
106       'POS_CLASSIFICATION',
107       'PROCUREMENT_ORGANIZATION',
108       x_status,
109       x_exception_msg
110       );
111 
112     IF (x_status <> 'S') THEN
113        x_exception_msg	:= 'Error when classifying enterprise party as PROCUREMENT_ORGANIZATION '
114 	 || l_party_id ||' '|| x_exception_msg;
115        raise_application_error(-20002,x_exception_msg,TRUE);
116     END IF;
117 
118     pos_party_management_pkg.classify_party
119       (l_party_id,
120        'POS_PARTICIPANT_TYPE',
121        'ENTERPRISE',
122        x_status,
123        x_exception_msg
124        );
125 
126     IF (x_status <> 'S') THEN
127        x_exception_msg	:= 'Error when classifying enterprise party as ENTERPRISE '
128 	 || l_party_id ||' '|| x_exception_msg;
129        raise_application_error(-20002,x_exception_msg,TRUE);
130     END IF;
131 
132 END create_enterprise_party;
133 
134 PROCEDURE pos_create_enterprise_user
135   (p_username        IN  VARCHAR2, -- must
136    p_firstname       IN  VARCHAR2, -- must
137    p_lastname        IN  VARCHAR2, -- must
138    p_emailaddress    IN  VARCHAR2 DEFAULT NULL,
139    x_party_id        OUT NOCOPY NUMBER, -- party id of the user
140    x_relationship_id OUT NOCOPY NUMBER, -- relationship_id of the user with the company
141    x_exception_msg   OUT NOCOPY VARCHAR2,
142    x_status          OUT NOCOPY VARCHAR2
143    )
144 IS
145     l_org_partyId       NUMBER;
146     l_party_name        hz_parties.party_name%TYPE;
147     l_emp_records       NUMBER;
148     l_user_id           NUMBER;
149 BEGIN
150 
151     select user_id
152     into l_user_id
153     from fnd_user
154     where user_name = p_username;
155 
156     l_emp_records := pos_party_management_pkg.get_emp_or_ctgt_wrkr_pty_id(l_user_id);
157     if ( l_emp_records <= 0 ) then
158         x_status := 'E';
159         x_exception_msg := 'User: '||p_username ||' does not have employee id set.';
160         raise_application_error(-20001, x_exception_msg, true);
161     end if;
162 
163     -- Get the Enterprise party_id
164     get_enterprise_information
165       (l_org_partyId,
166        l_party_name,
167        x_exception_msg,
168        x_status
169        );
170 
171     IF (x_status <> 'S') THEN
172         raise_application_error(-20001, x_exception_msg, true);
173     END IF;
174 
175     pos_party_management_pkg.pos_create_user
176       (p_username,
177        p_firstname,
178        p_lastname,
179        p_emailaddress,
180        x_party_id,
181        x_exception_msg,
182        x_status
183        );
184 
185     IF (x_status <> 'S') THEN
186         raise_application_error(-20001, x_exception_msg, true);
187     END IF;
188 
189     pos_party_management_pkg.classify_party
190       (x_party_id,
191        'POS_PARTICIPANT_TYPE',
192        'ENTERPRISE_USER',
193        x_status,
194        x_exception_msg
195        );
196 
197     IF (x_status <> 'S') THEN
198         raise_application_error(-20001, x_exception_msg, true);
199     END IF;
200 
201     pos_hz_relationships_pkg.pos_create_relationship
202       (x_party_id,
203        l_org_partyId,
204        'POS_EMPLOYMENT',
205        'EMPLOYEE_OF',
206        x_relationship_id,
207        x_status,
208        x_exception_msg
209        );
210 
211     IF (x_status <> 'S') THEN
212         raise_application_error(-20001, x_exception_msg, true);
213     END IF;
214 
215 END pos_create_enterprise_user;
216 
217 END POS_ENTERPRISE_UTIL_PKG;