DBA Data[Home] [Help]

PACKAGE BODY: APPS.AR_INVOICE_DEFAULT_PVT

Source


1 PACKAGE BODY AR_INVOICE_DEFAULT_PVT AS
2 /* $Header: ARXVINDB.pls 120.11 2011/05/25 09:38:51 naneja ship $ */
3 
4 pg_debug                VARCHAR2(1) := nvl(fnd_profile.value('AFLOG_ENABLED'),'N');
5 
6 PROCEDURE Get_system_parameters (
7     p_trx_system_parameters_rec     OUT NOCOPY trx_system_parameters_rec_type,
8     x_errmsg			            OUT NOCOPY VARCHAR2,
9     x_return_status		            OUT NOCOPY VARCHAR2) IS
10 
11 BEGIN
12     IF pg_debug = 'Y'
13     THEN
14         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Get_system_parameters(+)' );
15     END IF;
16    x_return_status := FND_API.G_RET_STS_SUCCESS;
17 
18     /* 5921925 - copy info from arp_global.sysparam rather than selecting
19        from the db (again) */
20     arp_global.init_global;
21 
22     trx_system_parameters_rec.set_of_books_id := arp_global.sysparam.set_of_books_id;
23     trx_system_parameters_rec.accounting_method := arp_global.sysparam.accounting_method;
24     trx_system_parameters_rec.accrue_interest :=  arp_global.sysparam.accrue_interest;
28     trx_system_parameters_rec.default_cb_due_date := arp_global.sysparam.default_cb_due_date;
25     trx_system_parameters_rec.unearned_discount := arp_global.sysparam.unearned_discount;
26     trx_system_parameters_rec.partial_discount_flag := arp_global.sysparam.partial_discount_flag;
27     trx_system_parameters_rec.print_remit_to := arp_global.sysparam.print_remit_to;
29     trx_system_parameters_rec.auto_site_numbering := arp_global.sysparam.auto_site_numbering;
30     trx_system_parameters_rec.cash_basis_set_of_books_id := arp_global.sysparam.cash_basis_set_of_books_id;
31     trx_system_parameters_rec.code_combination_id_gain := arp_global.sysparam.code_combination_id_gain;
32     trx_system_parameters_rec.autocash_hierarchy_id := arp_global.sysparam.autocash_hierarchy_id;
33     trx_system_parameters_rec.run_gl_journal_import_flag := arp_global.sysparam.run_gl_journal_import_flag;
34     trx_system_parameters_rec.cer_split_amount := arp_global.sysparam.cer_split_amount;
35     trx_system_parameters_rec.cer_dso_days := arp_global.sysparam.cer_dso_days;
36     trx_system_parameters_rec.posting_days_per_cycle := arp_global.sysparam.posting_days_per_cycle;
37     trx_system_parameters_rec.address_validation := arp_global.sysparam.address_validation;
38     trx_system_parameters_rec.calc_discount_on_lines_flag := arp_global.sysparam.calc_discount_on_lines_flag;
39     trx_system_parameters_rec.change_printed_invoice_flag := arp_global.sysparam.change_printed_invoice_flag;
40     trx_system_parameters_rec.code_combination_id_loss := arp_global.sysparam.code_combination_id_loss;
41     trx_system_parameters_rec.create_reciprocal_flag := arp_global.sysparam.create_reciprocal_flag;
42     trx_system_parameters_rec.default_country := arp_global.sysparam.default_country;
43     trx_system_parameters_rec.default_territory := arp_global.sysparam.default_territory;
44     trx_system_parameters_rec.generate_customer_number := arp_global.sysparam.generate_customer_number;
45     trx_system_parameters_rec.invoice_deletion_flag := arp_global.sysparam.invoice_deletion_flag;
46     trx_system_parameters_rec.location_structure_id := arp_global.sysparam.location_structure_id;
47     trx_system_parameters_rec.site_required_flag := arp_global.sysparam.site_required_flag;
48     trx_system_parameters_rec.tax_allow_compound_flag := arp_global.sysparam.tax_allow_compound_flag;
49 	trx_system_parameters_rec.tax_header_level_flag := arp_global.sysparam.tax_header_level_flag;
50 	trx_system_parameters_rec.tax_rounding_allow_override := arp_global.sysparam.tax_rounding_allow_override;
51     trx_system_parameters_rec.tax_invoice_print := arp_global.sysparam.tax_invoice_print;
52     trx_system_parameters_rec.tax_method := arp_global.sysparam.tax_method;
53     trx_system_parameters_rec.tax_use_customer_exempt_flag := arp_global.sysparam.tax_use_customer_exempt_flag;
54     trx_system_parameters_rec.tax_use_cust_exc_rate_flag := arp_global.sysparam.tax_use_cust_exc_rate_flag;
55     trx_system_parameters_rec.tax_use_loc_exc_rate_flag := arp_global.sysparam.tax_use_loc_exc_rate_flag;
56     trx_system_parameters_rec.tax_use_product_exempt_flag := arp_global.sysparam.tax_use_product_exempt_flag;
57     trx_system_parameters_rec.tax_use_prod_exc_rate_flag := arp_global.sysparam.tax_use_prod_exc_rate_flag;
58     trx_system_parameters_rec.tax_use_site_exc_rate_flag := arp_global.sysparam.tax_use_site_exc_rate_flag;
59     trx_system_parameters_rec.ai_log_file_message_level := arp_global.sysparam.ai_log_file_message_level;
60     trx_system_parameters_rec.ai_max_memory_in_bytes := arp_global.sysparam.ai_max_memory_in_bytes;
61     trx_system_parameters_rec.ai_acct_flex_key_left_prompt := arp_global.sysparam.ai_acct_flex_key_left_prompt;
62     trx_system_parameters_rec.ai_mtl_items_key_left_prompt := arp_global.sysparam.ai_mtl_items_key_left_prompt;
63     trx_system_parameters_rec.ai_territory_key_left_prompt := arp_global.sysparam.ai_territory_key_left_prompt;
64     trx_system_parameters_rec.ai_purge_int_tables_flag := arp_global.sysparam.ai_purge_interface_tables_flag;
65     trx_system_parameters_rec.ai_activate_sql_trace_flag := arp_global.sysparam.ai_activate_sql_trace_flag;
66     trx_system_parameters_rec.default_grouping_rule_id := arp_global.sysparam.default_grouping_rule_id;
67     trx_system_parameters_rec.salesrep_required_flag := arp_global.sysparam.salesrep_required_flag;
68     trx_system_parameters_rec.auto_rec_invoices_per_commit := arp_global.sysparam.auto_rec_invoices_per_commit;
69     trx_system_parameters_rec.auto_rec_receipts_per_commit := arp_global.sysparam.auto_rec_receipts_per_commit;
70     trx_system_parameters_rec.pay_unrelated_invoices_flag := arp_global.sysparam.pay_unrelated_invoices_flag;
71     trx_system_parameters_rec.print_home_country_flag := arp_global.sysparam.print_home_country_flag;
72     trx_system_parameters_rec.location_tax_account := arp_global.sysparam.location_tax_account;
73     trx_system_parameters_rec.from_postal_code := arp_global.sysparam.from_postal_code;
74     trx_system_parameters_rec.to_postal_code := arp_global.sysparam.to_postal_code;
75     trx_system_parameters_rec.tax_registration_number := arp_global.sysparam.tax_registration_number;
76     trx_system_parameters_rec.populate_gl_segments_flag := arp_global.sysparam.populate_gl_segments_flag;
77     trx_system_parameters_rec.unallocated_revenue_ccid := arp_global.sysparam.unallocated_revenue_ccid;
78     trx_system_parameters_rec.org_id := arp_global.sysparam.org_id;
79     trx_system_parameters_rec.base_currency_code := arp_global.functional_currency;
80     trx_system_parameters_rec.chart_of_accounts_id := arp_global.chart_of_accounts_id;
81     trx_system_parameters_rec.period_set_name := arp_global.period_set_name;
82 --    trx_system_parameters_rec.short_name := arp_global.sysparam.short_name;
83     trx_system_parameters_rec.precision := arp_global.base_precision;
84 --    trx_system_parameters_rec.EXTENDED_PRECISION := arp_global.sysparam.extended_precision;
85     trx_system_parameters_rec.MINIMUM_ACCOUNTABLE_UNIT := arp_global.base_min_acc_unit;
86 --    trx_system_parameters_rec.yes_meaning := l_yes_meaning;
87 --    trx_system_parameters_rec.no_meaning := l_no_meaning;
91     trx_system_parameters_rec.br_enabled_flag := arp_global.sysparam.bills_receivable_enabled_flag;
88     trx_system_parameters_rec.inclusive_tax_used := arp_global.sysparam.inclusive_tax_used;
89     trx_system_parameters_rec.tax_enforce_account_flag := arp_global.sysparam.tax_enforce_account_flag;
90     trx_system_parameters_rec.ta_installed_flag := arp_global.sysparam.ta_installed_flag;
92     trx_system_parameters_rec.DOCUMENT_SEQ_GEN_LEVEL := arp_global.sysparam.DOCUMENT_SEQ_GEN_LEVEL;
93     trx_system_parameters_rec.trx_header_level_rounding := arp_global.sysparam.trx_header_level_rounding;
94     trx_system_parameters_rec.default_rct_mthd_for_lc_inv := arp_global.sysparam.default_rct_mthd_for_lc_inv;
95 
96     p_trx_system_parameters_rec := trx_system_parameters_rec;
97     IF pg_debug = 'Y'
98     THEN
99         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Get_system_parameters(-)' );
100     END IF;
101 
102     EXCEPTION
103             WHEN OTHERS THEN
104                 x_errmsg := 'Error in AR_INVOICE_DEFAULT_PVT.Get_system_parameters '||sqlerrm;
105                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
106                 return;
107 
108 END;
109 PROCEDURE Get_profile_values(
110         p_trx_profile_rec           OUT NOCOPY trx_profile_rec_type,
111         x_errmsg                    OUT NOCOPY  VARCHAR2,
112         x_return_status             OUT NOCOPY  VARCHAR2)  IS
113     l_profile_value                 varchar2(240);
114     l_result                        boolean;
115     l_dummy                         varchar2(240);
116     l_user_conversion_type	        VARCHAR2(30);
117     l_user_profile_option_name      VARCHAR2(240);
118 
119 BEGIN
120        --- Get profile options
121     IF pg_debug = 'Y'
122     THEN
123         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Get_profile_values(+)' );
124     END IF;
125 
126     x_return_status := FND_API.G_RET_STS_SUCCESS;
127 
128        trx_profile_rec.ar_unique_seq_numbers :=  fnd_profile.value('UNIQUE:SEQ_NUMBERS');
129 
130        /* 4743228 - swap AR to ZX profiles for etax */
131        trx_profile_rec.ar_allow_manual_tax_lines := fnd_profile.value('ZX_ALLOW_MANUAL_TAX_LINES');
132        trx_profile_rec.ar_allow_tax_code_override := fnd_profile.value('ZX_ALLOW_TAX_CLASSIF_OVERRIDE');
133        trx_profile_rec.ar_allow_trx_line_exemptions := fnd_profile.value('ZX_ALLOW_TRX_LINE_EXEMPTIONS');
134        /* 4743228 - end */
135 
136        trx_profile_rec.ar_batch_source := fnd_profile.value('AR_BATCH_SOURCE');
137        trx_profile_rec.ar_ra_batch_source := fnd_profile.value('AR_RA_BATCH_SOURCE');
138        trx_profile_rec.ar_update_due_date := fnd_profile.value('AR_UPDATE_DUE_DATE');
139        trx_profile_rec.ussgl_option := NVL(fnd_profile.value('USSGL_OPTION'),'N');
140        trx_profile_rec.ar_allow_salescredit_update := fnd_profile.value('AR_ALLOW_SALESCREDIT_UPDATE');
141        trx_profile_rec.so_organization_id := oe_profile.value('SO_ORGANIZATION_ID');
142        trx_profile_rec.so_source_code :=  oe_profile.value('SO_SOURCE_CODE');
143        trx_profile_rec.so_id_flex_code := oe_profile.value('SO_ID_FLEX_CODE');
144        trx_profile_rec.ar_jg_create_bank_charges := NVL(fnd_profile.value('AR_JG_CREATE_BANK_CHARGES'),'N');
145 
146 
147        fnd_profile.get('AR_DEFAULT_EXCHANGE_RATE_TYPE', l_profile_value);
148        IF (l_profile_value IS NOT NULL) THEN
149         BEGIN
150            SELECT user_conversion_type
151            INTO l_user_conversion_type
152 	       FROM GL_DAILY_CONVERSION_TYPES
153 	       WHERE conversion_type = l_profile_value;
154 
155 	       SELECT user_profile_option_name
156 	       INTO l_user_profile_option_name
157            FROM FND_PROFILE_OPTIONS_VL
158            WHERE application_id = 222
159            AND profile_option_name = 'AR_DEFAULT_EXCHANGE_RATE_TYPE';
160 
161 
162         EXCEPTION
163              WHEN NO_DATA_FOUND THEN
164 	           l_profile_value := NULL;
165 	           l_user_conversion_type := NULL;
166 	           l_user_profile_option_name := NULL;
167          END;
168        END IF;
169 
170        trx_profile_rec.default_exchange_rate_type := l_profile_value;
171        trx_profile_rec.default_exchange_rate_type_dsp := l_user_conversion_type;
172        trx_profile_rec.def_exchange_rate_type_profile :=  l_user_profile_option_name;
173 
174        l_result := fnd_installation.get_app_info('OE',
175                                                  l_profile_value,
176                                                  l_dummy,
177                                                  l_dummy);
178 
179        trx_profile_rec.so_installed_flag := l_profile_value;
180 
181 
182       -- IF (p_mode <> 'RECEIPTS')
183       -- THEN
184             IF    ( arp_auto_accounting.query_autoacc_def('REV', 'RA_SALESREPS') = TRUE )
185             THEN
186                 trx_profile_rec.rev_based_on_srep_flag := 'Y';
187             ELSE
188                 trx_profile_rec.rev_based_on_srep_flag := 'N';
189             END IF;
190 
191             IF    ( arp_auto_accounting.query_autoacc_def('ALL', 'RA_SALESREPS') = TRUE )
192             THEN
193                 trx_profile_rec.autoacc_based_on_srep_flag := 'Y';
194             ELSE
195                 trx_profile_rec.autoacc_based_on_srep_flag := 'N';
196             END IF;
197 
198             IF    (
199                       arp_auto_accounting.query_autoacc_def('FREIGHT', 'RA_SALESREPS') = TRUE
200                    OR arp_auto_accounting.query_autoacc_def('REC', 'RA_SALESREPS') = TRUE
201                   )
202             THEN
203                 trx_profile_rec.autoacc_based_on_primary_srep := 'Y';
204             ELSE
205                 trx_profile_rec.autoacc_based_on_primary_srep := 'N';
206             END IF;
207 
208             IF    ( arp_auto_accounting.query_autoacc_def('REV', 'AGREEMENT/CATEGORY') = TRUE )
209             THEN
210                 trx_profile_rec.autoacc_based_on_agree_cat := 'Y';
211             ELSE
212                 trx_profile_rec.autoacc_based_on_agree_cat := 'N';
213             END IF;
214 
215 
216             IF    ( arp_auto_accounting.query_autoacc_def('ALL', 'RA_CUST_TRX_TYPES') = TRUE )
217             THEN
218                 trx_profile_rec.autoacc_based_on_type_flag := 'Y';
219             ELSE
220                 trx_profile_rec.autoacc_based_on_type_flag := 'N';
221             END IF;
222 
223             IF    ( arp_auto_accounting.query_autoacc_def('ALL', 'RA_STD_TRX_LINES') = TRUE )
224             THEN
225                 trx_profile_rec.autoacc_based_on_item_flag := 'Y';
226             ELSE
227                 trx_profile_rec.autoacc_based_on_item_flag := 'N';
228             END IF;
229 
230             IF    ( arp_auto_accounting.query_autoacc_def('TAX', 'RA_TAXES') = TRUE )
231             THEN
232                 trx_profile_rec.autoacc_based_on_tax_code := 'Y';
233             ELSE
234                 trx_profile_rec.autoacc_based_on_tax_code := 'N';
235             END IF;
236 
237 	        IF  ( arp_auto_accounting.query_autoacc_def('ALL', 'RA_SITE_USES') = TRUE )
238             THEN
239                 trx_profile_rec.autoacc_based_on_site_flag := 'Y';
240             ELSE
241                 trx_profile_rec.autoacc_based_on_site_flag := 'N';
242             END IF;
243 
244 
245 
246           p_trx_profile_rec := trx_profile_rec;
247     IF pg_debug = 'Y'
248     THEN
249         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Get_profile_values(-)' );
250     END IF;
251    EXCEPTION
252 	WHEN OTHERS
253 	THEN
254                 x_errmsg := 'Error in AR_INVOICE_DEFAULT_PVT.Get_profile_values '||sqlerrm;
255                 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
256 		        return;
257 
258 END;
259 
260 
261 
262 procedure ar_common_init( p_code_combination_id_gain in number ) is
263 l_ar_receipt_multi_curr_flag    varchar2(1);
264 begin
265        IF (p_code_combination_id_gain IS NULL) THEN
266          trx_system_parameters_rec.ar_multi_currency_flag := 'N';
267          trx_system_parameters_rec.ar_receipt_multi_currency_flag := 'N';
268        ELSE
269          trx_system_parameters_rec.ar_multi_currency_flag := 'Y';
270          trx_system_parameters_rec.ar_receipt_multi_currency_flag := 'Y';
271        END IF;
272 end ar_common_init;
273 
274 
275 
276 
277 
278 PROCEDURE Default_gl_date IS
279 
280 l_error_message        VARCHAR2(128);
281 l_defaulting_rule_used VARCHAR2(50);
282 l_default_gl_date      DATE;
283 
284 /* 5921925 - Added post_to_gl logic so headers are skipped
285     if they are not supposed to post to gl */
286 CURSOR ar_invoice_gt_c IS
287     SELECT nvl(hdr.trx_date, sysdate) trx_date, hdr.set_of_books_id,
288            hdr.trx_header_id
289     FROM ar_trx_header_gt  hdr,
290          ra_cust_trx_types tt
291     WHERE gl_date IS NULL
292     AND   hdr.cust_trx_type_id = tt.cust_trx_type_id
293     AND   NVL(tt.post_to_gl,'N') = 'Y';
294 
295 BEGIN
296   IF pg_debug = 'Y'
297   THEN
298         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Default_gl_date(+)' );
299   END IF;
300   FOR ar_invoice_gt_rec IN ar_invoice_gt_c
301   LOOP
302      IF (arp_util.validate_and_default_gl_date(
303                 ar_invoice_gt_rec.trx_date,
304                 NULL,
305                 NULL,
306                 NULL,
307                 NULL,
308                 ar_invoice_gt_rec.trx_date,
309                 NULL,
310                 NULL,
311                 'N',
312                 NULL,
313                 ar_invoice_gt_rec.set_of_books_id,
314                 222,
315                 l_default_gl_date,
316                 l_defaulting_rule_used,
317                 l_error_message) = TRUE)
318      THEN
319       IF pg_debug = 'Y'
320       THEN
321         ar_invoice_utils.debug ('Default GL Date ' || l_default_gl_date);
322       END IF;
323 
324       UPDATE ar_trx_header_gt
325         SET  gl_date = l_default_gl_date
326       WHERE trx_header_id = ar_invoice_gt_rec.trx_header_id;
327 
328       UPDATE ar_trx_dist_gt
329         SET gl_date = l_default_gl_date
330       WHERE trx_header_id = ar_invoice_gt_rec.trx_header_id
331         AND  gl_date is null;
332 
333      END IF;
334   END LOOP;
335   IF pg_debug = 'Y'
336   THEN
337         ar_invoice_utils.debug ('AR_INVOICE_DEFAULT_PVT.Default_gl_date(-)' );
338   END IF;
339 END default_gl_date;
340 
341 END;