1 PACKAGE AP_INVOICE_LINES_PKG AS
2 /* $Header: apinlins.pls 120.15 2008/06/30 14:24:22 imandal ship $ */
3
4 TYPE r_dist_info IS RECORD
5 (
6 dist_line_num AP_INVOICE_DISTRIBUTIONS.distribution_line_number%TYPE
7 ,accounting_date AP_INVOICE_DISTRIBUTIONS.accounting_date%TYPE
8 ,period_name AP_INVOICE_DISTRIBUTIONS.period_name%TYPE
9 ,description AP_INVOICE_DISTRIBUTIONS.description%TYPE
10 ,dist_ccid AP_INVOICE_DISTRIBUTIONS.dist_code_combination_id%TYPE
11 ,charge_applicable_to_dist
12 AP_INVOICE_DISTRIBUTIONS.charge_applicable_to_dist_id%TYPE
13 ,project_id AP_INVOICE_DISTRIBUTIONS.project_id%TYPE
14 ,task_id AP_INVOICE_DISTRIBUTIONS.task_id%TYPE
15 ,expenditure_type AP_INVOICE_DISTRIBUTIONS.expenditure_type%TYPE
16 ,expenditure_organization_id
17 AP_INVOICE_DISTRIBUTIONS.expenditure_organization_id%TYPE
18 ,expenditure_item_date AP_INVOICE_DISTRIBUTIONS.expenditure_item_date%TYPE
19 ,project_accounting_context AP_INVOICE_DISTRIBUTIONS.project_accounting_context%TYPE
20 ,pa_quantity AP_INVOICE_DISTRIBUTIONS.pa_quantity%TYPE
21 ,pa_addition_flag AP_INVOICE_DISTRIBUTIONS.pa_addition_flag%TYPE
22 ,award_id AP_INVOICE_DISTRIBUTIONS.award_id%TYPE
23 ,attribute_category AP_INVOICE_DISTRIBUTIONS.attribute_category%TYPE
24 ,attribute1 AP_INVOICE_DISTRIBUTIONS.attribute1%TYPE
25 ,attribute2 AP_INVOICE_DISTRIBUTIONS.attribute2%TYPE
26 ,attribute3 AP_INVOICE_DISTRIBUTIONS.attribute3%TYPE
27 ,attribute4 AP_INVOICE_DISTRIBUTIONS.attribute4%TYPE
28 ,attribute5 AP_INVOICE_DISTRIBUTIONS.attribute5%TYPE
29 ,attribute6 AP_INVOICE_DISTRIBUTIONS.attribute6%TYPE
30 ,attribute7 AP_INVOICE_DISTRIBUTIONS.attribute7%TYPE
31 ,attribute8 AP_INVOICE_DISTRIBUTIONS.attribute8%TYPE
32 ,attribute9 AP_INVOICE_DISTRIBUTIONS.attribute9%TYPE
33 ,attribute10 AP_INVOICE_DISTRIBUTIONS.attribute10%TYPE
34 ,attribute11 AP_INVOICE_DISTRIBUTIONS.attribute11%TYPE
35 ,attribute12 AP_INVOICE_DISTRIBUTIONS.attribute12%TYPE
36 ,attribute13 AP_INVOICE_DISTRIBUTIONS.attribute13%TYPE
37 ,attribute14 AP_INVOICE_DISTRIBUTIONS.attribute14%TYPE
38 ,attribute15 AP_INVOICE_DISTRIBUTIONS.attribute15%TYPE
39 ,amount AP_INVOICE_DISTRIBUTIONS.amount%TYPE
40 ,base_amount AP_INVOICE_DISTRIBUTIONS.base_amount%TYPE
41 ,rounding_amt AP_INVOICE_DISTRIBUTIONS.rounding_amt%TYPE
42 ,type_1099 AP_INVOICE_DISTRIBUTIONS.type_1099%TYPE
43 ,income_tax_region AP_INVOICE_DISTRIBUTIONS.income_tax_region%TYPE
44 ,assets_tracking_flag AP_INVOICE_DISTRIBUTIONS.assets_tracking_flag%TYPE
45 ,asset_book_type_code AP_INVOICE_DISTRIBUTIONS.asset_book_type_code%TYPE
46 ,asset_category_id AP_INVOICE_DISTRIBUTIONS.asset_category_id%TYPE
47 ,awt_group_id AP_INVOICE_DISTRIBUTIONS.awt_group_id%TYPE
48 ,org_id AP_INVOICE_DISTRIBUTIONS.org_id%TYPE
49 ,set_of_books_id AP_INVOICE_DISTRIBUTIONS.set_of_books_id%TYPE
50 --ETAX: Invwkb
51 ,intended_use AP_INVOICE_DISTRIBUTIONS.intended_use%TYPE
52 --bugfix:4674194
53 ,global_attribute3 AP_INVOICE_DISTRIBUTIONS.global_attribute3%TYPE
54 ---7022001
55 ,pay_awt_group_id AP_INVOICE_DISTRIBUTIONS.pay_awt_group_id%TYPE
56 );
57
58
59 TYPE r_alloc_line IS RECORD
60 (
61 invoice_line_number AP_ALLOCATION_RULE_LINES.to_invoice_line_number%TYPE
62 ,percentage AP_ALLOCATION_RULE_LINES.percentage%TYPE
63 ,amount AP_ALLOCATION_RULE_LINES.amount%TYPE
64 ,sum_amount_dists AP_ALLOCATION_RULE_LINES.amount%TYPE);
65
66 TYPE dist_tab_type IS TABLE OF r_dist_info
67 INDEX BY BINARY_INTEGER;
68
69 TYPE alloc_line_tab_type IS TABLE of r_alloc_line
70 INDEX BY BINARY_INTEGER;
71
72
73 /*==========================================================================*/
74 /* */
75 /* This FUNCTION may be called from the insert_from_dist_set function of */
76 /* invoice lines, or from the import process. This FUNCTION takes a series */
77 /* of mandatory parameters. */
78 /* The mandatory parameters are: */
79 /* 1) X_vendor_id */
80 /* 2) X_invoice_date */
81 /* 3) X_invoice_lines_rec -- Lines record as defined in AP_INVOICES_PKG */
82 /* 4) X_dist_tab -- Variable to contain the plsql table of dists */
83 /* 5) X_dist_set_total_percent - 100 = Full Dist set, <> 100 = Skeleton */
84 /* 6) X_exchange_rate */
85 /* 7) X_exchange_rate_type */
86 /* 8) X_exchange_date */
87 /* 9) X_invoice_currency */
88 /* 10)X_base_currency */
89 /* 11)X_chart_of_accounts_id */
90 /* 12)X_Error_Code -- Variable RETURNing error code IF one is found */
91 /* Possible Codes are: */
92 /* 'INVALID ACCOUNT EXISTS' - Invalid account found */
93 /* 'CANNOT OVERLAY' - Cannot overlay with overlay info. */
94 /* 13)X_Debug_Info -- Variable RETURNing debug info for fatal error */
95 /* 14)X_Debug_Context -- Variable RETURNing context for fatal error */
96 /* 15)X_msg_application -- Variable to RETURN info from errors in PA Val */
97 /* 16)X_msg_data -- Variable to RETURN data from errors in PA Val */
98 /* 17)X_calling_sequence -- Calling sequence */
99 /* An optional parameter is: */
100 /* 1) X_line_source -- Should only be populated with the value 'IMPORT' */
101 /* -- IF calling from the Open Interface Import Program */
102 /* -- Should be null otherwise. */
103 /* */
104 /*==========================================================================*/
105 FUNCTION Generate_Dist_Tab_For_Dist_Set(
106 X_vendor_id IN AP_INVOICES.VENDOR_ID%TYPE,
107 X_invoice_date IN AP_INVOICES.INVOICE_DATE%TYPE,
108 X_invoice_lines_rec IN AP_INVOICES_PKG.r_invoice_line_rec,
109 X_line_source IN VARCHAR2,
110 X_dist_tab IN OUT NOCOPY AP_INVOICE_LINES_PKG.dist_tab_type,
111 X_dist_set_total_percent IN NUMBER,
112 X_exchange_rate IN AP_INVOICES.EXCHANGE_RATE%TYPE,
113 X_exchange_rate_type IN AP_INVOICES.EXCHANGE_RATE_TYPE%TYPE,
114 X_exchange_date IN AP_INVOICES.EXCHANGE_DATE%TYPE,
115 X_invoice_currency IN AP_INVOICES.INVOICE_CURRENCY_CODE%TYPE,
116 X_base_currency IN AP_INVOICES.INVOICE_CURRENCY_CODE%TYPE,
117 X_chart_of_accounts_id IN GL_SETS_OF_BOOKS.CHART_OF_ACCOUNTS_ID%TYPE,
118 X_Error_Code OUT NOCOPY VARCHAR2,
119 X_Debug_Info OUT NOCOPY VARCHAR2,
120 X_Debug_Context OUT NOCOPY VARCHAR2,
121 X_msg_application OUT NOCOPY VARCHAR2,
122 X_msg_data OUT NOCOPY VARCHAR2,
123 X_calling_sequence IN VARCHAR2)
124 RETURN BOOLEAN;
125
126 /*==========================================================================*/
127 /* */
128 /* This FUNCTION may be called by any process requiring generation of */
129 /* an invoice line/distributions from a distribution set. */
130 /* It takes the following parameters: */
131 /* 1) X_invoice_id - ID of invoice requesting generation of line/dists */
132 /* 2) X_line_number - Line NUMBER IF line already exists, NULL otherwise */
133 /* - This process will error IF a line NUMBER is provided */
134 /* - and the line does not exist. */
135 /* 3) X_GL_Date - Accounting Date to use in insert of lines/dists. It is */
136 /* - assumed to have been validated to be in an open period. */
137 /* - You should pass this date IF generating distributions */
138 /* - for a line with a date in a closed period. This will */
139 /* - ensure the distributions are created in an open period. */
140 /* 4) X_period_name - Period corresponding to GL_Date parameter. */
141 /* 5) X_Skeleton_Allowed - Indicates whether a check must be performed to */
142 /* - ensure no skeleton dist set in use. */
143 /* 6) X_Generate_Dists - Indicates whether to Generate distributions as part*/
144 /* - of this function. */
145 /* 7) X_Generate_Permanent - Indicates whether to create distributions in */
146 /* - permanent or candidate mode. */
147 /* 8) X_Line_Source - 'HEADER DSET' IF called from the Invoice Workbench */
148 /* 'AUTO INVOICE CREATION' IF called from the */
149 /* AP_Recurring_Invoices_pkg.Ap_create_Recurring_Invoices*/
150 /* 9) X_Item_Description| Copied from the Recurring Invoices Template IF */
151 /* X_Manufacturer | the Invoice Lines/Dists are created via Recurring*/
152 /* X_Model_Number | Invoices */
153 /* 10) Out parameters to be used as stated below to handle errors. */
154 /* This FUNCTION will: */
155 /* 1) validate that IF Skeleton_Allowed is 'N', the given distribution set */
156 /* is not a skeleton distribution set. If skeleton, set error code to */
157 /* 'SKELETON_NOT_ALLOWED' and RETURN FALSE. */
158 /* 2) validate that distribution set is active. If inactive, set error code */
159 /* to 'DIST_SET_INACTIVE' and RETURN FALSE. */
160 /* 3) validate that all accounts in the distribution set are valid and/or if*/
161 /* overlay information provided, the overlayed */
162 /* accounts are valid. If an invalid account is found prior to overlay, */
163 /* set error code to 'INVALID_ACCOUNT_EXISTS' and RETURN FALSE. */
164 /* If overlay RETURNs an error set error code to 'CANNOT_OVERLAY' and */
165 /* RETURN FALSE. */
166 /* 4) IF no line already exists, create the line with the given parameters */
167 /* and information from the dist set. */
168 /* 5) call to create distributions */
169 /* 6) IF at any given time an error is encountered not covered in the error */
170 /* codes, populate debug_info with specific error and RETURN the debug */
171 /* info and the calling sequence as debug context with a FUNCTION output */
172 /* of FALSE. */
173 /* */
174 /*==========================================================================*/
175 FUNCTION Insert_From_Dist_Set(
176 X_invoice_id IN NUMBER,
177 X_line_number IN NUMBER DEFAULT NULL,
178 X_GL_Date IN DATE,
179 X_Period_Name IN VARCHAR2,
180 X_Skeleton_Allowed IN VARCHAR2 DEFAULT 'N',
181 X_Generate_Dists IN VARCHAR2 DEFAULT 'Y',
182 X_Generate_Permanent IN VARCHAR2 DEFAULT 'N',
183 X_Error_Code OUT NOCOPY VARCHAR2,
184 X_Debug_Info OUT NOCOPY VARCHAR2,
185 X_Debug_Context OUT NOCOPY VARCHAR2,
186 X_Msg_Application OUT NOCOPY VARCHAR2,
187 X_Msg_Data OUT NOCOPY VARCHAR2,
188 X_calling_sequence IN VARCHAR2) RETURN BOOLEAN;
189
190 /*==========================================================================*/
191 /* */
192 /* This FUNCTION RETURNs the maximum distribution line NUMBER for a given */
193 /* invoice and invoice line. If the line contains no distributions, this */
194 /* FUNCTION RETURNs 0. */
195 /* */
196 /*==========================================================================*/
197 FUNCTION Get_Max_Dist_Line_Num(
198 X_invoice_id IN NUMBER,
199 X_line_number IN NUMBER) RETURN NUMBER;
200
201 -- table to hols the dist ids that can be adjusted - bug 6892789
202 TYPE distribution_id_tab_type IS
203 TABLE OF AP_INVOICE_DISTRIBUTIONS_ALL.INVOICE_DISTRIBUTION_ID%TYPE
204 INDEX BY BINARY_INTEGER;
205
206 -- function modified to get the dists that can be adjusted - bug 6892789
207 FUNCTION round_base_amts(
208 X_INVOICE_ID IN NUMBER,
209 X_LINE_NUMBER IN NUMBER,
210 X_REPORTING_LEDGER_ID IN NUMBER DEFAULT NULL,
211 X_ROUND_DIST_ID_LIST OUT NOCOPY distribution_id_tab_type,
212 X_ROUNDED_AMT OUT NOCOPY NUMBER,
213 X_Debug_Info OUT NOCOPY VARCHAR2,
214 X_Debug_Context OUT NOCOPY VARCHAR2,
215 X_Calling_sequence IN VARCHAR2 )
216 RETURN BOOLEAN;
217
218 /*=============================================================================
219 | public PROCEDURE Discard_Inv_Line
220 |
221 | Discard or cancel the invoice line depending on calling mode. If error
222 | occurs, it return FALSE and error code will be populated. Otherwise,
223 | It return TRUE.
224 |
225 | Parameters
226 | P_line_rec - Invoice line record
227 | P_calling_mode - either from DISCARD, CANCEL or UNAPPLY_PREPAY
228 | p_inv_cancellable - 'Y' if invoice is canellable.
229 | P_last_updated_by
230 | P_last_update_login
231 | P_error_code - Error code indicates why it is not discardable
232 | P_calling_sequence - For debugging purpose
233 |
234 | PROGRAM FLOW
235 |
236 | 1. check if line is discardable
237 | 2. if line is discardable/cancellable and matched - reverse match
238 | 3. reset the encumberance flag, create account event
239 | 4. if there is an active distribution - reverse distribution
240 | 5. populate the out message and set the return value
241 |
242 | NOTES
243 |
244 | MODIFICATION HISTORY
245 | Date Author Description of Change
246 | 03/07/03 sfeng Created
247 |
248 *============================================================================*/
249
250 Function Discard_Inv_Line(
251 P_line_rec IN ap_invoice_lines%ROWTYPE,
252 P_calling_mode IN VARCHAR2,
253 p_inv_cancellable IN VARCHAR2 DEFAULT NULL,
254 P_last_updated_by IN NUMBER,
255 P_last_update_login IN NUMBER,
256 P_error_code OUT NOCOPY VARCHAR2,
257 P_token OUT NOCOPY VARCHAR2,
258 P_calling_sequence IN VARCHAR2) RETURN BOOLEAN;
259
260 -- Bug 5114543
261 -- Allow discard of an item line with allocated charges. This utility is placed in the spec
262 -- so that it can be invoked from ap_invoice_lines_pkg and ap_invoice_distributions_pkg.
263
264 /*=============================================================================
265 | Public Function Reverse_Charge_distributions
266 |
267 | Reverse distributions for an invoice line. This will be called for
268 | a charge line (Freight, Miscellaneous). Returns false when an error
269 | occurs and error code will be populated. Otherwise, Returns False.
270 |
271 | Parameters
272 | P_inv_line_rec - Invoice line record.
273 | p_calling_mode - DISCARD, CANCEL
274 | x_error_code - For error handling
275 | x_debug_info - For debugging purposes
276 | p_calling_sequence - For debugging purposes
277 |
278 *============================================================================*/
279
280 FUNCTION Reverse_Charge_Distributions
281 (p_inv_line_rec IN AP_INVOICE_LINES_ALL%rowtype,
282 p_calling_mode IN VARCHAR2,
283 x_error_code OUT NOCOPY VARCHAR2,
284 x_debug_info OUT NOCOPY VARCHAR2,
285 p_calling_sequence IN VARCHAR2) RETURN BOOLEAN;
286
287 END AP_INVOICE_LINES_PKG;
288