DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_COPYDOC_S5

Source


1 PACKAGE BODY po_copydoc_s5 AS
2 /* $Header: POXCPO5B.pls 120.2 2006/09/07 10:37:45 ajarora noship $*/
3 
4 --< Shared Proc FPJ Start >
5 -- Debugging booleans used to bypass logging when turned off
6 g_debug_stmt CONSTANT BOOLEAN := PO_DEBUG.is_debug_stmt_on;
7 g_debug_unexp CONSTANT BOOLEAN := PO_DEBUG.is_debug_unexp_on;
8 
9 g_pkg_name CONSTANT VARCHAR2(20) := 'PO_COPYDOC_S5';
10 g_module_prefix CONSTANT VARCHAR2(30) := 'po.plsql.' || g_pkg_name || '.';
11 --< Shared Proc FPJ End >
12 
13 --<Encumbrance FPJ: add sob_id to param list>
14 PROCEDURE validate_distribution(
15   x_action_code             IN      VARCHAR2,
16   x_to_doc_subtype	    IN      po_headers.type_lookup_code%TYPE,
17   x_po_distribution_record  IN OUT NOCOPY  po_distributions%ROWTYPE,
18   x_po_header_id            IN      po_distributions.po_header_id%TYPE,
19   x_po_line_id              IN      po_distributions.po_line_id%TYPE,
20   x_line_location_id        IN      po_distributions.line_location_id%TYPE,
21   x_online_report_id        IN      po_online_report_text.online_report_id%TYPE,
22   x_sequence                IN OUT NOCOPY  po_online_report_text.sequence%TYPE,
23   x_line_num                IN      po_online_report_text.line_num%TYPE,
24   x_shipment_num            IN      po_online_report_text.shipment_num%TYPE,
25   x_sob_id                  IN      FINANCIALS_SYSTEM_PARAMETERS.set_of_books_id%TYPE,
26   x_return_code             OUT NOCOPY     NUMBER
27 ) IS
28 
29   COPYDOC_DISTRIBUTION_FAILURE  EXCEPTION;
30   x_progress                    VARCHAR2(4) := NULL;
31   x_internal_return_code        NUMBER := NULL;
32   x_tax_code_id			NUMBER := NULL;
33 
34 BEGIN
35 
36   x_progress := '001';
37   IF g_debug_stmt THEN               --< Shared Proc FPJ > Add correct debugging
38       PO_DEBUG.debug_stmt
39           (p_log_head => g_module_prefix||'validate_distribution',
40            p_token    => 'invoked',
41            p_message  => 'action_code: ' ||x_action_code||' to_doc_subtype: '||
42                    x_to_doc_subtype||' online_report ID: '||x_online_report_id||
43                    ' header ID: '||x_po_header_id||' line ID: '||x_po_line_id||
44                    ' ship ID: '||x_line_location_id||' dist ID: '||
45                    x_po_distribution_record.po_distribution_id);
46   END IF;
47 
48   /* reset for new record */
49   x_po_distribution_record.po_header_id     := x_po_header_id;
50   x_po_distribution_record.po_line_id       := x_po_line_id;
51   x_po_distribution_record.line_location_id := x_line_location_id;
52 
53   BEGIN
54     SELECT po_distributions_s.nextval
55     INTO   x_po_distribution_record.po_distribution_id
56     FROM   SYS.DUAL;
57   EXCEPTION
58     WHEN OTHERS THEN
59       x_po_distribution_record.po_distribution_id := NULL;
60       po_copydoc_s1.copydoc_sql_error('validate_distribution', x_progress, sqlcode,
61                                       x_online_report_id,
62                                       x_sequence,
63                                       x_line_num, x_shipment_num, x_po_distribution_record.distribution_num);
64       RAISE COPYDOC_DISTRIBUTION_FAILURE;
65   END;
66 
67   x_progress := '002';
68 
69   --<ENCUMBRANCE FPJ START>
70   IF(x_to_doc_subtype = 'BLANKET' ) THEN
71      --distribution belongs to an encumbered BPA
72      x_tax_code_id := NULL;
73      x_po_distribution_record.encumbered_flag := NULL;
74      x_po_distribution_record.encumbered_amount := NULL;
75      x_po_distribution_record.unencumbered_amount:= NULL;
76      x_po_distribution_record.unencumbered_quantity := NULL;
77      x_po_distribution_record.mrc_encumbered_amount := NULL;
78      x_po_distribution_record.mrc_unencumbered_amount := NULL;
79 
80   ELSE
81      --<ENCUMBRANCE FPJ END>
82      --distribution is not from an encumbered BPA
83 
84      BEGIN
85 	  SELECT tax_code_id
86 	  INTO   x_tax_code_id
87 	  FROM   po_line_locations
88 	  WHERE  line_location_id = x_line_location_id;
89      EXCEPTION
90        WHEN OTHERS THEN
91 	 x_po_distribution_record.po_distribution_id := NULL;
92 	 po_copydoc_s1.copydoc_sql_error('validate_distribution'
93                                         , x_progress
94                                         , sqlcode
95 					, x_online_report_id
96 					, x_sequence
97 					, x_line_num
98                                         , x_shipment_num
99                                         , x_po_distribution_record.distribution_num);
100 	 RAISE COPYDOC_DISTRIBUTION_FAILURE;
101      END;
102 
103   END IF; --distribution type is PA
104 
105   -- if there is no tax name on shipment, then wipe out
106   -- recovery_rate, recoverable_tax and nonrecoverable_tax
107   if x_tax_code_id is null then
108      x_po_distribution_record.recovery_rate := NULL;
109      x_po_distribution_record.recoverable_tax := NULL;
110      x_po_distribution_record.nonrecoverable_tax := NULL;
111   end if;
112 
113     x_po_distribution_record.amount_billed:= NULL;
114 
115     --Bug# 5481061 : Using the prevent_encumbrance_flag from orginal document
116     --rather than defaulting.Commented the line below.
117     --x_po_distribution_record.prevent_encumbrance_flag := 'N';
118 
119     /* Standard */
120     x_po_distribution_record.created_by        := fnd_global.user_id;
121     x_po_distribution_record.creation_date     := SYSDATE;
122     x_po_distribution_record.last_updated_by   := fnd_global.user_id;
123     x_po_distribution_record.last_update_date  := SYSDATE;
124     x_po_distribution_record.last_update_login := fnd_global.login_id;
125 
126     x_po_distribution_record.program_application_id := NULL;
127     x_po_distribution_record.program_id             := NULL;
128     x_po_distribution_record.program_update_date    := NULL;
129     x_po_distribution_record.request_id             := NULL;
130 
131     x_po_distribution_record.quantity_billed    := 0;
132     x_po_distribution_record.quantity_cancelled := 0;
133     x_po_distribution_record.quantity_delivered := 0;
134 
135     x_po_distribution_record.tax_recovery_override_flag := 'N';
136 
137 --    x_po_distribution_record.base_amount_billed := NULL;    -- June 07, 1999,   bgu
138 
139     /* reference planned po */
140     x_po_distribution_record.source_distribution_id := NULL;
141 
142     --<ENCUMBRANCE FPJ START> Use SYSDATE for GL date on new dist
143     If (x_po_distribution_record.gl_encumbered_date IS NOT NULL) Then
144        PO_CORE_S.get_period_name(
145           x_sob_id => x_sob_id
146        ,  x_period => x_po_distribution_record.gl_encumbered_period_name
147        ,  x_gl_date => x_po_distribution_record.gl_encumbered_date
148        );
149     Else
150        x_po_distribution_record.gl_encumbered_period_name := NULL;
151     End If;
152     --<ENCUMBRANCE FPJ END>
153 
154   x_return_code := 0;
155 
156   IF g_debug_stmt THEN               --< Shared Proc FPJ > Add correct debugging
157       PO_DEBUG.debug_end
158           (p_log_head => g_module_prefix||'validate_distribution');
159   END IF;
160 
161 EXCEPTION
162 
163   WHEN COPYDOC_DISTRIBUTION_FAILURE THEN
164     x_return_code := -1;
165     IF g_debug_stmt THEN             --< Shared Proc FPJ > Add correct debugging
166         PO_DEBUG.debug_stmt
167             (p_log_head => g_module_prefix||'validate_distribution',
168              p_token    => x_progress,
169              p_message  => 'COPYDOC_DISTRIBUTION_FAILURE exception caught.');
170     END IF;
171   WHEN OTHERS THEN
172     x_return_code := -1;
173     IF g_debug_unexp THEN            --< Shared Proc FPJ > Add correct debugging
174         PO_DEBUG.debug_exc
175             (p_log_head => g_module_prefix||'validate_distribution',
176              p_progress => x_progress);
177     END IF;
178 END validate_distribution;
179 
180 --< Shared Proc FPJ Start >
181 ---------------------------------------------------------------------------
182 --Start of Comments
183 --Name: generate_accounts
184 --Pre-reqs:
185 --  None.
186 --Modifies:
187 --  PO_ONLINE_REPORT_TEXT
188 --Locks:
189 --  None.
190 --Function:
191 --  Generates new accounts for the given document, and sets them in
192 --  x_po_distribution_rec.  If any account generation error occurs, then
193 --  inserts error messages into PO_ONLINE_REPORT_TEXT, and x_po_distribution_rec
194 --  will remain unchanged.
195 --Parameters:
196 --IN:
197 --p_online_report_id
198 --p_po_header_rec
199 --p_po_line_rec
200 --p_po_shipment_rec
201 --IN OUT:
202 --x_po_distribution_rec
203 --x_sequence
204 --  The sequence used for the online report error messages, which gets
205 --  incremented.
206 --OUT:
207 --x_return_status
208 --  FND_API.g_ret_sts_success - if account generation is successful
209 --  FND_API.g_ret_sts_error - if account generation error occurs
210 --  FND_API.g_ret_sts_unexp_error - if unexpected error occurs
211 --End of Comments
212 ---------------------------------------------------------------------------
213 PROCEDURE generate_accounts
214 (
215     x_return_status       OUT    NOCOPY VARCHAR2,
216     p_online_report_id    IN     NUMBER,
217     p_po_header_rec       IN     PO_HEADERS%ROWTYPE,
218     p_po_line_rec         IN     PO_LINES%ROWTYPE,
219     p_po_shipment_rec     IN     PO_LINE_LOCATIONS%ROWTYPE,
220     x_po_distribution_rec IN OUT NOCOPY PO_DISTRIBUTIONS%ROWTYPE,
221     x_sequence            IN OUT NOCOPY NUMBER
222 )
223 IS
224 
225 l_api_name              CONSTANT VARCHAR2(30) := 'generate_accounts'; --<BUG 3407630>
226 l_gen_acct_success      BOOLEAN;
227 l_accrual_success       BOOLEAN;
228 l_budget_success        BOOLEAN;
229 l_charge_success        BOOLEAN;
230 l_dest_charge_success   BOOLEAN;
231 l_dest_variance_success BOOLEAN;
232 l_variance_success      BOOLEAN;
233 l_new_combination       BOOLEAN;
234 
235 l_accrual_account_id       PO_DISTRIBUTIONS_ALL.accrual_account_id%TYPE;
236 l_budget_account_id        PO_DISTRIBUTIONS_ALL.budget_account_id%TYPE;
237 l_code_combination_id      PO_DISTRIBUTIONS_ALL.code_combination_id%TYPE;
238 l_dest_charge_account_id   PO_DISTRIBUTIONS_ALL.dest_charge_account_id%TYPE;
239 l_dest_variance_account_id PO_DISTRIBUTIONS_ALL.dest_variance_account_id%TYPE;
240 l_variance_account_id      PO_DISTRIBUTIONS_ALL.variance_account_id%TYPE;
241 
242 l_accrual_account_desc       VARCHAR2(2000);
243 l_budget_account_desc        VARCHAR2(2000);
244 l_charge_account_desc        VARCHAR2(2000);
245 l_dest_charge_account_desc   VARCHAR2(2000);
246 l_dest_variance_account_desc VARCHAR2(2000);
247 l_variance_account_desc      VARCHAR2(2000);
248 
249 l_accrual_account_flex       VARCHAR2(2000);
250 l_budget_account_flex        VARCHAR2(2000);
251 l_charge_account_flex        VARCHAR2(2000);
252 l_dest_charge_account_flex   VARCHAR2(2000);
253 l_dest_variance_account_flex VARCHAR2(2000);
254 l_variance_account_flex      VARCHAR2(2000);
255 
256 l_wf_item_key          PO_HEADERS_ALL.wf_item_key%TYPE;
257 l_chart_of_accounts_id GL_SETS_OF_BOOKS.chart_of_accounts_id%TYPE;
258 l_po_encumbrance_flag  FINANCIALS_SYSTEM_PARAMS_ALL.purch_encumbrance_flag%TYPE;
259 l_fb_error_msg         PO_ONLINE_REPORT_TEXT.text_line%TYPE;
260 l_progress             VARCHAR2(3);
261 l_acct_gen_error       BOOLEAN := FALSE;
262 l_func_unit_price      PO_LINES_ALL.unit_price%TYPE; -- Bug 3463242
263 
264 BEGIN
265     l_progress := '000';
266     IF g_debug_stmt THEN
267         PO_DEBUG.debug_stmt
268             (p_log_head => g_module_prefix||'generate_accounts',
269              p_token    => 'invoked',
270              p_message  => 'online_report ID: '||p_online_report_id||
271                            ' header ID: '||p_po_header_rec.po_header_id||
272                            ' line ID: '||p_po_line_rec.po_line_id||
273                            ' ship ID: '||p_po_shipment_rec.line_location_id||
274                         ' dist ID: '||x_po_distribution_rec.po_distribution_id);
275     END IF;
276 
277     x_return_status := FND_API.g_ret_sts_success;
278 
279     l_progress := '010';
280 
281     --SQL What: Get the chart of accounts ID for the current set of books and
282     --          the Purchasing encumbrance flag of the current OU
283     --SQL Why: Need to pass into account generator workflow
284     SELECT gsob.chart_of_accounts_id,
285            NVL(fspa.purch_encumbrance_flag, 'N')
286       INTO l_chart_of_accounts_id,
287            l_po_encumbrance_flag
288       FROM gl_sets_of_books gsob,
289            financials_system_params_all fspa
290      WHERE fspa.org_id = p_po_header_rec.org_id
291        AND fspa.set_of_books_id = gsob.set_of_books_id;
292 
293     l_progress := '020';
294 
295     --<Bug 3407630, Bug 3463242 START>
296     l_func_unit_price := p_po_line_rec.unit_price
297                          * NVL(x_po_distribution_rec.rate, 1);
298 
299     IF g_debug_stmt THEN
300       PO_DEBUG.debug_stmt(p_log_head => g_module_prefix || l_api_name,
301                           p_token    => l_progress,
302                           p_message  => 'unit price in functional currency: '||
303                                         l_func_unit_price);
304     END IF;
305     --<Bug 3407630, Bug 3463242 END>
306 
307     l_gen_acct_success :=
308         PO_WF_BUILD_ACCOUNT_INIT.start_workflow
309             (x_purchasing_ou_id            => p_po_header_rec.org_id,
310              x_transaction_flow_header_id  => p_po_shipment_rec.transaction_flow_header_id,
311              x_dest_charge_success         => l_dest_charge_success,
312              x_dest_variance_success       => l_dest_variance_success,
313              x_dest_charge_account_id      => l_dest_charge_account_id,
314              x_dest_variance_account_id    => l_dest_variance_account_id,
315              x_dest_charge_account_desc    => l_dest_charge_account_desc,
316              x_dest_variance_account_desc  => l_dest_variance_account_desc,
317              x_dest_charge_account_flex    => l_dest_charge_account_flex,
318              x_dest_variance_account_flex  => l_dest_variance_account_flex,
319              x_charge_success              => l_charge_success,
320              x_budget_success              => l_budget_success,
321              x_accrual_success             => l_accrual_success,
322              x_variance_success            => l_variance_success,
323              x_code_combination_id         => l_code_combination_id,
324              x_budget_account_id           => l_budget_account_id,
325              x_accrual_account_id          => l_accrual_account_id,
326              x_variance_account_id         => l_variance_account_id,
327              x_charge_account_flex         => l_charge_account_flex,
328              x_budget_account_flex         => l_budget_account_flex,
329              x_accrual_account_flex        => l_accrual_account_flex,
330              x_variance_account_flex       => l_variance_account_flex,
331              x_charge_account_desc         => l_charge_account_desc,
332              x_budget_account_desc         => l_budget_account_desc,
333              x_accrual_account_desc        => l_accrual_account_desc,
334              x_variance_account_desc       => l_variance_account_desc,
335              x_coa_id                      => l_chart_of_accounts_id,
336              x_bom_resource_id             => x_po_distribution_rec.bom_resource_id,
337              x_bom_cost_element_id         => NULL,
338              x_category_id                 => p_po_line_rec.category_id,
339              x_destination_type_code       => x_po_distribution_rec.destination_type_code,
340              x_deliver_to_location_id      => x_po_distribution_rec.deliver_to_location_id,
341              x_destination_organization_id => x_po_distribution_rec.destination_organization_id,
342              x_destination_subinventory    => x_po_distribution_rec.destination_subinventory,
343              x_expenditure_type            => x_po_distribution_rec.expenditure_type,
344              x_expenditure_organization_id => x_po_distribution_rec.expenditure_organization_id,
345              x_expenditure_item_date       => x_po_distribution_rec.expenditure_item_date,
346              x_item_id                     => p_po_line_rec.item_id,
347              x_line_type_id                => p_po_line_rec.line_type_id,
348              x_result_billable_flag        => NULL,
349              x_agent_id                    => p_po_header_rec.agent_id,
350              x_project_id                  => x_po_distribution_rec.project_id,
351              x_from_type_lookup_code       => NULL,
352              x_from_header_id              => NULL,
353              x_from_line_id                => NULL,
354              x_task_id                     => x_po_distribution_rec.task_id,
355              x_deliver_to_person_id        => x_po_distribution_rec.deliver_to_person_id,
356              x_type_lookup_code            => p_po_header_rec.type_lookup_code,
357              x_vendor_id                   => p_po_header_rec.vendor_id,
358              x_wip_entity_id               => x_po_distribution_rec.wip_entity_id,
359              x_wip_entity_type             => NULL,
360              x_wip_line_id                 => x_po_distribution_rec.wip_line_id,
361              x_wip_repetitive_schedule_id  => x_po_distribution_rec.wip_repetitive_schedule_id,
362              x_wip_operation_seq_num       => x_po_distribution_rec.wip_operation_seq_num,
363              x_wip_resource_seq_num        => x_po_distribution_rec.wip_resource_seq_num,
364              x_po_encumberance_flag        => l_po_encumbrance_flag,
365              x_gl_encumbered_date          => x_po_distribution_rec.gl_encumbered_date,
366              wf_itemkey                    => l_wf_item_key,
367              x_new_combination             => l_new_combination,
368              header_att1                   => p_po_header_rec.attribute1,
369              header_att2                   => p_po_header_rec.attribute2,
370              header_att3                   => p_po_header_rec.attribute3,
371              header_att4                   => p_po_header_rec.attribute4,
372              header_att5                   => p_po_header_rec.attribute5,
373              header_att6                   => p_po_header_rec.attribute6,
374              header_att7                   => p_po_header_rec.attribute7,
375              header_att8                   => p_po_header_rec.attribute8,
376              header_att9                   => p_po_header_rec.attribute9,
377              header_att10                  => p_po_header_rec.attribute10,
378              header_att11                  => p_po_header_rec.attribute11,
379              header_att12                  => p_po_header_rec.attribute12,
380              header_att13                  => p_po_header_rec.attribute13,
381              header_att14                  => p_po_header_rec.attribute14,
382              header_att15                  => p_po_header_rec.attribute15,
383              line_att1                     => p_po_line_rec.attribute1,
384              line_att2                     => p_po_line_rec.attribute2,
385              line_att3                     => p_po_line_rec.attribute3,
386              line_att4                     => p_po_line_rec.attribute4,
387              line_att5                     => p_po_line_rec.attribute5,
388              line_att6                     => p_po_line_rec.attribute6,
389              line_att7                     => p_po_line_rec.attribute7,
390              line_att8                     => p_po_line_rec.attribute8,
391              line_att9                     => p_po_line_rec.attribute9,
392              line_att10                    => p_po_line_rec.attribute10,
393              line_att11                    => p_po_line_rec.attribute11,
394              line_att12                    => p_po_line_rec.attribute12,
395              line_att13                    => p_po_line_rec.attribute13,
396              line_att14                    => p_po_line_rec.attribute14,
397              line_att15                    => p_po_line_rec.attribute15,
398              shipment_att1                 => p_po_shipment_rec.attribute1,
399              shipment_att2                 => p_po_shipment_rec.attribute2,
400              shipment_att3                 => p_po_shipment_rec.attribute3,
401              shipment_att4                 => p_po_shipment_rec.attribute4,
402              shipment_att5                 => p_po_shipment_rec.attribute5,
403              shipment_att6                 => p_po_shipment_rec.attribute6,
404              shipment_att7                 => p_po_shipment_rec.attribute7,
405              shipment_att8                 => p_po_shipment_rec.attribute8,
406              shipment_att9                 => p_po_shipment_rec.attribute9,
407              shipment_att10                => p_po_shipment_rec.attribute10,
408              shipment_att11                => p_po_shipment_rec.attribute11,
409              shipment_att12                => p_po_shipment_rec.attribute12,
410              shipment_att13                => p_po_shipment_rec.attribute13,
411              shipment_att14                => p_po_shipment_rec.attribute14,
412              shipment_att15                => p_po_shipment_rec.attribute15,
413              distribution_att1             => x_po_distribution_rec.attribute1,
414              distribution_att2             => x_po_distribution_rec.attribute2,
415              distribution_att3             => x_po_distribution_rec.attribute3,
416              distribution_att4             => x_po_distribution_rec.attribute4,
417              distribution_att5             => x_po_distribution_rec.attribute5,
418              distribution_att6             => x_po_distribution_rec.attribute6,
419              distribution_att7             => x_po_distribution_rec.attribute7,
420              distribution_att8             => x_po_distribution_rec.attribute8,
421              distribution_att9             => x_po_distribution_rec.attribute9,
422              distribution_att10            => x_po_distribution_rec.attribute10,
423              distribution_att11            => x_po_distribution_rec.attribute11,
424              distribution_att12            => x_po_distribution_rec.attribute12,
425              distribution_att13            => x_po_distribution_rec.attribute13,
426              distribution_att14            => x_po_distribution_rec.attribute14,
427              distribution_att15            => x_po_distribution_rec.attribute15,
428              FB_ERROR_MSG                  => l_fb_error_msg,
429              x_award_id	                   => x_po_distribution_rec.award_id,
430              x_vendor_site_id              => p_po_header_rec.vendor_site_id,
431              p_func_unit_price             => l_func_unit_price, -- Bug 3463242
432              -- <Complex Work R12 Start>
433              p_distribution_type           => x_po_distribution_rec.distribution_type,
434              p_payment_type                => p_po_shipment_rec.payment_type
435              -- <Complex Work R12 End>
436              );
437 
438     l_progress := '030';
439 
440     -- Check the individual boolean statuses for the accounts, and add error
441     -- messages if any of them failed
442 
443     IF (NOT l_accrual_success) THEN
444         l_progress := '040';
445         FND_MESSAGE.set_name(application => 'PO',
446                              name        => 'PO_PDOI_ACCRUAL_FAILED');
447         PO_COPYDOC_S1.online_report
448             (x_online_report_id => p_online_report_id,
449              x_sequence         => x_sequence,
450              x_message          => FND_MESSAGE.get,
451              x_line_num         => p_po_line_rec.line_num,
452              x_shipment_num     => p_po_shipment_rec.shipment_num,
453              x_distribution_num => x_po_distribution_rec.distribution_num);
454         l_acct_gen_error := TRUE;
455 
456         IF g_debug_stmt THEN
457             PO_DEBUG.debug_stmt
458                 (p_log_head => g_module_prefix||'generate_accounts',
459                  p_token    => l_progress,
460                  p_message  => 'Accrual account failed.');
461         END IF;
462     END IF;  --< if not accrual success>
463 
464     IF (NOT l_budget_success) THEN
465         l_progress := '050';
466         FND_MESSAGE.set_name(application => 'PO',
467                              name        => 'PO_PDOI_BUDGET_FAILED');
468         PO_COPYDOC_S1.online_report
469             (x_online_report_id => p_online_report_id,
470              x_sequence         => x_sequence,
471              x_message          => FND_MESSAGE.get,
472              x_line_num         => p_po_line_rec.line_num,
473              x_shipment_num     => p_po_shipment_rec.shipment_num,
474              x_distribution_num => x_po_distribution_rec.distribution_num);
475         l_acct_gen_error := TRUE;
476 
477         IF g_debug_stmt THEN
478             PO_DEBUG.debug_stmt
479                 (p_log_head => g_module_prefix||'generate_accounts',
480                  p_token    => l_progress,
481                  p_message  => 'Budget account failed.');
482         END IF;
483     END IF;  --< if not budget success>
484 
485     IF (NOT l_charge_success) OR
486        (NVL(l_code_combination_id, -1) IN (-1,0))
487     THEN
488         l_progress := '060';
489         FND_MESSAGE.set_name(application => 'PO',
490                              name        => 'PO_PDOI_CHARGE_FAILED');
491         PO_COPYDOC_S1.online_report
492             (x_online_report_id => p_online_report_id,
493              x_sequence         => x_sequence,
494              x_message          => FND_MESSAGE.get,
495              x_line_num         => p_po_line_rec.line_num,
496              x_shipment_num     => p_po_shipment_rec.shipment_num,
497              x_distribution_num => x_po_distribution_rec.distribution_num);
498         l_acct_gen_error := TRUE;
499 
500         IF g_debug_stmt THEN
501             PO_DEBUG.debug_stmt
502                 (p_log_head => g_module_prefix||'generate_accounts',
503                  p_token    => l_progress,
504                  p_message  => 'Charge account failed.');
505         END IF;
506     END IF;  --< if not charge success>
507 
508     IF (NOT l_variance_success) THEN
509         l_progress := '070';
510         FND_MESSAGE.set_name(application => 'PO',
511                              name        => 'PO_PDOI_VARIANCE_FAILED');
512         PO_COPYDOC_S1.online_report
513             (x_online_report_id => p_online_report_id,
514              x_sequence         => x_sequence,
515              x_message          => FND_MESSAGE.get,
516              x_line_num         => p_po_line_rec.line_num,
517              x_shipment_num     => p_po_shipment_rec.shipment_num,
518              x_distribution_num => x_po_distribution_rec.distribution_num);
519         l_acct_gen_error := TRUE;
520 
521         IF g_debug_stmt THEN
522             PO_DEBUG.debug_stmt
523                 (p_log_head => g_module_prefix||'generate_accounts',
524                  p_token    => l_progress,
525                  p_message  => 'Variance account failed.');
526         END IF;
527     END IF;  --< if not variance success>
528 
529     IF (NOT l_dest_charge_success) THEN
530         l_progress := '080';
531         FND_MESSAGE.set_name(application => 'PO',
532                              name        => 'PO_PDOI_DEST_CHARGE_FAILED');
533         PO_COPYDOC_S1.online_report
534             (x_online_report_id => p_online_report_id,
535              x_sequence         => x_sequence,
536              x_message          => FND_MESSAGE.get,
537              x_line_num         => p_po_line_rec.line_num,
538              x_shipment_num     => p_po_shipment_rec.shipment_num,
539              x_distribution_num => x_po_distribution_rec.distribution_num);
540         l_acct_gen_error := TRUE;
541 
542         IF g_debug_stmt THEN
543             PO_DEBUG.debug_stmt
544                 (p_log_head => g_module_prefix||'generate_accounts',
545                  p_token    => l_progress,
546                  p_message  => 'Dest charge account failed.');
547         END IF;
548     END IF;  --< if not dest charge success>
549 
550     IF (NOT l_dest_variance_success) THEN
551         l_progress := '090';
552         FND_MESSAGE.set_name(application => 'PO',
553                              name        => 'PO_PDOI_DEST_VARIANCE_FAILED');
554         PO_COPYDOC_S1.online_report
555             (x_online_report_id => p_online_report_id,
556              x_sequence         => x_sequence,
557              x_message          => FND_MESSAGE.get,
558              x_line_num         => p_po_line_rec.line_num,
559              x_shipment_num     => p_po_shipment_rec.shipment_num,
560              x_distribution_num => x_po_distribution_rec.distribution_num);
561         l_acct_gen_error := TRUE;
562 
563         IF g_debug_stmt THEN
564             PO_DEBUG.debug_stmt
565                 (p_log_head => g_module_prefix||'generate_accounts',
566                  p_token    => l_progress,
567                  p_message  => 'Dest variance account failed.');
568         END IF;
569     END IF;  --< if not dest variance success>
570 
571     IF (NOT l_gen_acct_success) OR (l_acct_gen_error) THEN
572         l_progress := '100';
573 
574         IF (l_fb_error_msg IS NULL) AND (NOT l_acct_gen_error) THEN
575             -- No error message returned at all from WF, so use a default msg
576             l_fb_error_msg := FND_MESSAGE.get_string
577                                 (appin => 'PO',
578                                  namein => 'PO_ACCT_GEN_WF_FAILED');
579         END IF;
580 
581         IF (l_fb_error_msg IS NOT NULL) THEN
582             PO_COPYDOC_S1.online_report
583                 (x_online_report_id => p_online_report_id,
584                  x_sequence         => x_sequence,
585                  x_message          => l_fb_error_msg,
586                  x_line_num         => p_po_line_rec.line_num,
587                  x_shipment_num     => p_po_shipment_rec.shipment_num,
588                  x_distribution_num => x_po_distribution_rec.distribution_num);
589         END IF;
590 
591         IF g_debug_stmt THEN
592             PO_DEBUG.debug_stmt
593                 (p_log_head => g_module_prefix||'generate_accounts',
594                  p_token    => l_progress,
595                  p_message  => 'Account generation failure.');
596         END IF;
597 
598         -- Raise exception to exit without modifying the distribution record
599         RAISE FND_API.g_exc_error;
600     END IF;  --< if not gen account success>
601 
602     IF g_debug_stmt THEN
603         PO_DEBUG.debug_stmt
604             (p_log_head => g_module_prefix||'generate_accounts',
605              p_token    => l_progress,
606              p_message  => 'Account generation successful.');
607     END IF;
608 
609     -- Account generation was successful, so copy values into distribution rec
610     x_po_distribution_rec.accrual_account_id := l_accrual_account_id;
611     x_po_distribution_rec.budget_account_id := l_budget_account_id;
612     x_po_distribution_rec.code_combination_id := l_code_combination_id;
613     x_po_distribution_rec.dest_charge_account_id := l_dest_charge_account_id;
614     x_po_distribution_rec.dest_variance_account_id :=l_dest_variance_account_id;
615     x_po_distribution_rec.variance_account_id := l_variance_account_id;
616 
617 EXCEPTION
618     WHEN FND_API.g_exc_error THEN
619         -- If caught, then copydoc errors are already inserted, so just set
620         -- the return status.
621         x_return_status := FND_API.g_ret_sts_error;
622     WHEN OTHERS THEN
623         x_return_status := FND_API.g_ret_sts_unexp_error;
624         PO_COPYDOC_S1.copydoc_sql_error
625             (x_routine          => 'PO_COPYDOC_S5.generate_accounts',
626              x_progress         => l_progress,
627              x_sqlcode          => SQLCODE,
628              x_online_report_id => p_online_report_id,
629              x_sequence         => x_sequence,
630              x_line_num         => p_po_line_rec.line_num,
631              x_shipment_num     => p_po_shipment_rec.shipment_num,
632              x_distribution_num => x_po_distribution_rec.distribution_num);
633         IF g_debug_unexp THEN
634             PO_DEBUG.debug_exc
635                 (p_log_head => g_module_prefix||'generate_accounts',
636                  p_progress => l_progress);
637         END IF;
638 END generate_accounts;
639 --< Shared Proc FPJ End >
640 
641 END po_copydoc_s5;