1 PACKAGE ARP_ALLOCATION_PKG AUTHID CURRENT_USER AS
2 /* $Header: ARALLOCS.pls 120.10 2005/07/26 15:19:25 naneja ship $ */
3
4 /*=======================================================================+
5 | Public Variables and Record Types
6 +=======================================================================*/
7 SUBTYPE ae_doc_rec_type IS ARP_ACCT_MAIN.ae_doc_rec_type;
8 SUBTYPE ae_event_rec_type IS ARP_ACCT_MAIN.ae_event_rec_type;
9 SUBTYPE ae_sys_rec_type IS ARP_ACCT_MAIN.ae_sys_rec_type;
10 SUBTYPE ae_line_rec_type IS ARP_ACCT_MAIN.ae_line_rec_type;
11 SUBTYPE ae_line_tbl_type IS ARP_ACCT_MAIN.ae_line_tbl_type;
12 SUBTYPE ae_curr_rec_type IS ARP_ACCT_MAIN.ae_curr_rec_type;
13 SUBTYPE ae_rule_rec_type IS ARP_ACCT_MAIN.ae_app_rule_rec_type;
14
15 adj_code_combination_id ar_adjustments.code_combination_id%TYPE;
16
17 --Cache counter to store substituted ccid in a global table
18 cache_ctr BINARY_INTEGER := 0;
19
20 --Record type definition Stores key and accounts derived using flexbuilder
21 TYPE flex_parms_rec_type IS RECORD
22 (
23 coa_id gl_sets_of_books.chart_of_accounts_id%TYPE ,
24 orig_ccid ar_system_parameters_all.code_combination_id_round%TYPE ,
25 subs_ccid ar_system_parameters_all.code_combination_id_round%TYPE ,
26 actual_ccid ar_system_parameters_all.code_combination_id_round%TYPE
27 );
28
29 --Table type declaration which stores key for accounts derived using flexbuilder
30
31 TYPE flex_parms_tbl_type IS TABLE OF flex_parms_rec_type
32 INDEX BY BINARY_INTEGER;
33
34 --Actual global table which stores gain, loss, net expense or revenue tax accounts
35 --with balancing segment matching receivable of Invoice
36
37 flex_parms_tbl flex_parms_tbl_type;
38
39 --Exception handler which raises an error if unable to derive a valid substituted ccid
40 --for gain, loss, round or override net expense or tax accounts from location or tax codes
41
42 flex_subs_ccid_error EXCEPTION;
43 invalid_ccid_error EXCEPTION;
44 rounding_error EXCEPTION;
45 invalid_allocation_base EXCEPTION;
46 ram_api_error EXCEPTION;
47
48 /*------------------------------------------------------------+
49 | Allocation Control Record Type |
50 +------------------------------------------------------------*/
51 TYPE ae_alloc_rec_type IS RECORD (
52 ae_account_class ra_cust_trx_line_gl_dist.account_class%TYPE ,
53 ae_customer_trx_id ra_customer_trx_lines.customer_trx_id%TYPE ,
54 ae_customer_trx_line_id ra_customer_trx_lines.customer_trx_line_id%TYPE ,
55 ae_link_to_cust_trx_line_id ra_customer_trx_lines.link_to_cust_trx_line_id%TYPE,
56 ae_tax_type VARCHAR2(3) ,
57 ae_code_combination_id ra_cust_trx_line_gl_dist.code_combination_id%TYPE ,
58 ae_collected_tax_ccid ra_cust_trx_line_gl_dist.collected_tax_ccid%TYPE ,
59 ae_line_amount NUMBER ,
60 ae_amount NUMBER ,
61 ae_acctd_amount NUMBER ,
62 ae_tax_group_code_id NUMBER ,
63 ae_tax_id NUMBER ,
64 ae_taxable_amount NUMBER ,
65 ae_taxable_acctd_amount NUMBER ,
66 ae_adj_ccid ar_vat_tax.adj_ccid%TYPE ,
67 ae_edisc_ccid ar_vat_tax.edisc_ccid%TYPE ,
68 ae_unedisc_ccid ar_vat_tax.unedisc_ccid%TYPE ,
69 ae_finchrg_ccid ar_vat_tax.finchrg_ccid%TYPE ,
70 ae_adj_non_rec_tax_ccid ar_vat_tax.adj_non_rec_tax_ccid%TYPE ,
71 ae_edisc_non_rec_tax_ccid ar_vat_tax.edisc_non_rec_tax_ccid%TYPE ,
72 ae_unedisc_non_rec_tax_ccid ar_vat_tax.unedisc_non_rec_tax_ccid%TYPE ,
73 ae_finchrg_non_rec_tax_ccid ar_vat_tax.finchrg_non_rec_tax_ccid%TYPE ,
74 ae_override_ccid1 ra_cust_trx_line_gl_dist.code_combination_id%TYPE , --edisc, adj
75 ae_override_ccid2 ra_cust_trx_line_gl_dist.code_combination_id%TYPE , --unedisc
76 ae_tax_link_id ar_distributions.tax_link_id%TYPE ,
77 ae_tax_link_id_act ar_distributions.tax_link_id%TYPE ,
78 ae_pro_amt NUMBER ,
79 ae_pro_acctd_amt NUMBER ,
80 ae_pro_frt_chrg_amt NUMBER ,
81 ae_pro_frt_chrg_acctd_amt NUMBER ,
82 ae_pro_taxable_amt NUMBER ,
83 ae_pro_taxable_acctd_amt NUMBER ,
84 ae_pro_def_tax_amt NUMBER ,
85 ae_pro_def_tax_acctd_amt NUMBER ,
86 ae_summarize_flag VARCHAR2(1) ,
87 ae_counted_flag VARCHAR2(1) ,
88 ae_autotax ra_customer_trx_lines.autotax%TYPE
89 );
90 /*----------------------------------------------------------------------+
91 | Table which stores details for Invoice Revenue and Tax distributions |
92 | and their tax code details. |
93 +----------------------------------------------------------------------*/
94 TYPE ae_alloc_tbl_type IS TABLE of ae_alloc_rec_type
95 INDEX BY BINARY_INTEGER;
96
97 /*--------------------------------------------------------------------+
98 | Invoice Lines Revenue amounts and revenue accounted amount totals |
99 +--------------------------------------------------------------------*/
100 TYPE ae_rev_total_rec IS RECORD (
101 ae_inv_line ra_customer_trx_lines.customer_trx_line_id%TYPE,
102 ae_sum_rev_amt NUMBER,
103 ae_sum_rev_acctd_amt NUMBER,
104 ae_count NUMBER
105 );
106
107 /*---------------------------------------------------------------------+
108 | Table which stores the Invoice lines revenue amounts and accounted |
109 | amounts sum totals |
110 +---------------------------------------------------------------------*/
111 TYPE ae_rev_total_type IS TABLE of ae_rev_total_rec
112 INDEX BY BINARY_INTEGER;
113
114 /*--------------------------------------------------------------------------+
115 | Table which stores link id and revenue allocated totals for line amounts|
116 +--------------------------------------------------------------------------*/
117 TYPE ae_link_rec IS RECORD (
118 ae_tax_link_id NUMBER,
119 ae_inv_line ra_customer_trx_lines.customer_trx_line_id%TYPE,
120 ae_sum_alloc_amt NUMBER,
121 ae_sum_alloc_acctd_amt NUMBER,
122 ae_run_amt_tot NUMBER,
123 ae_run_acctd_amt_tot NUMBER,
124 ae_run_pro_amt_tot NUMBER,
125 ae_run_pro_acctd_amt_tot NUMBER,
126 ae_def_flg BOOLEAN,
127 ae_tax_id NUMBER,
128 ae_tax_type VARCHAR2(3)
129 );
130
131 /*---------------------------------------------------------------------+
132 | Table which stores the link id and revenu allocated totals |
133 +---------------------------------------------------------------------*/
134 TYPE ae_link_tbl_type IS TABLE of ae_link_rec
135 INDEX BY BINARY_INTEGER;
136
137 /* ==========================================================================================
138 | PROCEDURE Allocate_Tax
139 |
140 | DESCRIPTION
141 | This procedure is the cover routine which will tax account for
142 | discounts, adjustments and finance charges. The rule details
143 | and document, event details are passed to this procedure which will
144 | help determine the manner in which discounts and adjustments are
145 | allocated over specific accounts based on Activity Rule.
146 |
147 | PARAMETERS
148 | p_ae_doc_rec IN Document record
149 | p_ae_event_rec IN Event record
150 | p_app_rec IN Application record for discounts
151 | p_adj_rec IN Adjustment record for adjustments
152 | p_rule_rec IN Rule record
153 | p_ae_line_tbl OUT Table with accounting for discounts or adjustments
154 * ==========================================================================================*/
155 PROCEDURE Allocate_Tax ( p_ae_doc_rec IN ae_doc_rec_type ,
156 p_ae_event_rec IN ae_event_rec_type ,
157 p_ae_rule_rec IN ae_rule_rec_type ,
158 p_app_rec IN ar_receivable_applications%ROWTYPE ,
159 p_cust_inv_rec IN ra_customer_trx%ROWTYPE ,
160 p_adj_rec IN ar_adjustments%ROWTYPE ,
161 p_ae_ctr IN OUT NOCOPY BINARY_INTEGER ,
162 p_ae_line_tbl IN OUT NOCOPY ae_line_tbl_type ,
163 p_br_cust_trx_line_id IN ra_customer_trx_lines.customer_trx_line_id%TYPE default NULL,
164 p_simul_app IN VARCHAR2 default NULL ,
165 --{HYUDETUPT
166 p_from_llca_call IN VARCHAR2 DEFAULT 'N',
167 p_gt_id IN NUMBER DEFAULT NULL,
168 -- this flag is introduced to indicate if the application need conversion
169 p_inv_cm IN VARCHAR2 DEFAULT 'I'
170 ) ;
171
172 FUNCTION Retain_Neg_Ind(p_rowid IN ROWID) RETURN NUMBER;
173
174 FUNCTION Get_Tax_Count(p_invoice_line_id IN NUMBER) RETURN NUMBER;
175
176 FUNCTION Set_Adj_CCID(p_action IN VARCHAR2) RETURN NUMBER;
177
178 PROCEDURE Substitute_Ccid(p_coa_id IN gl_sets_of_books.chart_of_accounts_id%TYPE ,
179 p_original_ccid IN ar_system_parameters.code_combination_id_gain%TYPE,
180 p_subs_ccid IN ar_system_parameters.code_combination_id_gain%TYPE,
181 p_actual_ccid OUT NOCOPY ar_system_parameters.code_combination_id_gain%TYPE);
182 END ARP_ALLOCATION_PKG;