68:
69: BEGIN
70: x_return_status := FND_API.G_RET_STS_SUCCESS ;
71:
72: IF g_debug <= gme_debug.g_log_procedure THEN
73: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
74: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
75: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
76: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
69: BEGIN
70: x_return_status := FND_API.G_RET_STS_SUCCESS ;
71:
72: IF g_debug <= gme_debug.g_log_procedure THEN
73: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
74: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
75: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
76: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
77: ' line_type: ' || p_tran_rec.line_type);
70: x_return_status := FND_API.G_RET_STS_SUCCESS ;
71:
72: IF g_debug <= gme_debug.g_log_procedure THEN
73: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
74: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
75: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
76: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
77: ' line_type: ' || p_tran_rec.line_type);
78: gme_debug.put_line ('pri Qty: ' || p_tran_rec.primary_quantity || ' ' || p_tran_rec.primary_uom ||
74: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
75: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
76: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
77: ' line_type: ' || p_tran_rec.line_type);
78: gme_debug.put_line ('pri Qty: ' || p_tran_rec.primary_quantity || ' ' || p_tran_rec.primary_uom ||
79: ' doc qty: ' || p_tran_rec.doc_qty || ' ' || p_tran_rec.doc_uom);
80: END IF;
81:
82: -- Possible validations
128: END;
129: END IF;
130:
131: IF (l_doc_qty IS NULL ) THEN
132: IF g_debug <= gme_debug.g_log_procedure THEN
133: gme_debug.put_line ('No doc quantity specified for the layer');
134: END IF;
135: x_return_status := FND_API.G_RET_STS_ERROR ;
136: FND_MESSAGE.SET_NAME('GMF', 'GMF_NO_DOC_QTY_FOR_LAYER');
129: END IF;
130:
131: IF (l_doc_qty IS NULL ) THEN
132: IF g_debug <= gme_debug.g_log_procedure THEN
133: gme_debug.put_line ('No doc quantity specified for the layer');
134: END IF;
135: x_return_status := FND_API.G_RET_STS_ERROR ;
136: FND_MESSAGE.SET_NAME('GMF', 'GMF_NO_DOC_QTY_FOR_LAYER');
137: FND_MSG_PUB.Add;
142:
143: -- Create the incoming layer
144: SELECT gmf_layer_id_s.nextval INTO l_layer_id FROM DUAL;
145:
146: IF g_debug <= gme_debug.g_log_statement THEN
147: gme_debug.put_line ('creating incoming layer: ' || l_layer_id);
148: END IF;
149:
150: INSERT INTO gmf_incoming_material_layers(
143: -- Create the incoming layer
144: SELECT gmf_layer_id_s.nextval INTO l_layer_id FROM DUAL;
145:
146: IF g_debug <= gme_debug.g_log_statement THEN
147: gme_debug.put_line ('creating incoming layer: ' || l_layer_id);
148: END IF;
149:
150: INSERT INTO gmf_incoming_material_layers(
151: layer_id,
201: WHERE batch_id = p_tran_rec.transaction_source_id
202: AND delete_mark = 0;
203:
204: IF l_req_count = 0 THEN
205: IF g_debug <= gme_debug.g_log_statement THEN
206: gme_debug.put_line ('creating batch requirements before creating VIB details');
207: END IF;
208: -- Create the requirements
209: GMF_VIB.Create_Batch_Requirements(
202: AND delete_mark = 0;
203:
204: IF l_req_count = 0 THEN
205: IF g_debug <= gme_debug.g_log_statement THEN
206: gme_debug.put_line ('creating batch requirements before creating VIB details');
207: END IF;
208: -- Create the requirements
209: GMF_VIB.Create_Batch_Requirements(
210: 1.0,
218: RETURN;
219: END IF;
220: END IF;
221:
222: IF g_debug <= gme_debug.g_log_statement THEN
223: gme_debug.put_line ('now calling Create_VIB_Details');
224: END IF;
225:
226: -- Now generate the VIB details for this product transaction.
219: END IF;
220: END IF;
221:
222: IF g_debug <= gme_debug.g_log_statement THEN
223: gme_debug.put_line ('now calling Create_VIB_Details');
224: END IF;
225:
226: -- Now generate the VIB details for this product transaction.
227: GMF_VIB.Create_VIB_Details (
232: x_return_status,
233: x_msg_count,
234: x_msg_data);
235:
236: IF g_debug <= gme_debug.g_log_statement THEN
237: gme_debug.put_line ('done creating vib details. status/msg: ' || x_return_status ||'/'|| x_msg_data);
238: END IF;
239:
240: IF g_debug <= gme_debug.g_log_procedure THEN
233: x_msg_count,
234: x_msg_data);
235:
236: IF g_debug <= gme_debug.g_log_statement THEN
237: gme_debug.put_line ('done creating vib details. status/msg: ' || x_return_status ||'/'|| x_msg_data);
238: END IF;
239:
240: IF g_debug <= gme_debug.g_log_procedure THEN
241: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
236: IF g_debug <= gme_debug.g_log_statement THEN
237: gme_debug.put_line ('done creating vib details. status/msg: ' || x_return_status ||'/'|| x_msg_data);
238: END IF;
239:
240: IF g_debug <= gme_debug.g_log_procedure THEN
241: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
242: END IF;
243:
244: EXCEPTION
237: gme_debug.put_line ('done creating vib details. status/msg: ' || x_return_status ||'/'|| x_msg_data);
238: END IF;
239:
240: IF g_debug <= gme_debug.g_log_procedure THEN
241: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
242: END IF;
243:
244: EXCEPTION
245: WHEN OTHERS THEN
242: END IF;
243:
244: EXCEPTION
245: WHEN OTHERS THEN
246: gme_debug.put_line ('Exiting api (thru when others) ' || g_pkg_name || '.' || l_api_name);
247: FND_MESSAGE.SET_NAME('GMI','GMI_DXFR_SQL_ERROR');
248: FND_MESSAGE.SET_TOKEN('ERRCODE',SQLCODE);
249: FND_MESSAGE.SET_TOKEN('ERRM',SQLERRM);
250: FND_MSG_PUB.Add;
325:
326: BEGIN
327: x_return_status := FND_API.G_RET_STS_SUCCESS ;
328:
329: IF g_debug <= gme_debug.g_log_procedure THEN
330: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
331: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
332: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
333: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
326: BEGIN
327: x_return_status := FND_API.G_RET_STS_SUCCESS ;
328:
329: IF g_debug <= gme_debug.g_log_procedure THEN
330: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
331: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
332: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
333: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
334: ' line_type: ' || p_tran_rec.line_type);
327: x_return_status := FND_API.G_RET_STS_SUCCESS ;
328:
329: IF g_debug <= gme_debug.g_log_procedure THEN
330: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
331: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
332: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
333: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
334: ' line_type: ' || p_tran_rec.line_type);
335: gme_debug.put_line ('pri Qty: ' || p_tran_rec.primary_quantity || ' ' || p_tran_rec.primary_uom ||
331: gme_debug.put_line ('processing batch: ' || p_tran_rec.transaction_source_id || ' item/org/lot/txnId/reverseId: ' ||
332: p_tran_rec.inventory_item_id ||'/'|| p_tran_rec.organization_id || '/' ||
333: p_tran_rec.lot_number ||'/'|| p_tran_rec.transaction_id ||'/'|| p_tran_rec.reverse_id ||
334: ' line_type: ' || p_tran_rec.line_type);
335: gme_debug.put_line ('pri Qty: ' || p_tran_rec.primary_quantity || ' ' || p_tran_rec.primary_uom ||
336: ' doc qty: ' || p_tran_rec.doc_qty || ' ' || p_tran_rec.doc_uom);
337: END IF;
338:
339: -- Possible validations
351: RETURN;
352: END IF;
353: IF (p_tran_rec.line_type <> -1 and p_tran_rec.line_type <> 2) THEN
354: x_return_status := FND_API.G_RET_STS_ERROR ;
355: gme_debug.put_line ('Error-GMF: Only Ingredients and By-Products allowed for outgoing layers');
356: FND_MESSAGE.SET_NAME('GMF', 'GMF_NON_ING_TRANS');
357: FND_MSG_PUB.Add;
358: RETURN;
359: END IF;
385: END IF;
386:
387: IF (l_doc_qty IS NULL ) THEN
388: x_return_status := FND_API.G_RET_STS_ERROR ;
389: IF g_debug <= gme_debug.g_log_procedure THEN
390: gme_debug.put_line ('No doc quantity specified for the layer');
391: END IF;
392: FND_MESSAGE.SET_NAME('GMF', 'GMF_NO_DOC_QTY_FOR_LAYER');
393: FND_MSG_PUB.Add;
386:
387: IF (l_doc_qty IS NULL ) THEN
388: x_return_status := FND_API.G_RET_STS_ERROR ;
389: IF g_debug <= gme_debug.g_log_procedure THEN
390: gme_debug.put_line ('No doc quantity specified for the layer');
391: END IF;
392: FND_MESSAGE.SET_NAME('GMF', 'GMF_NO_DOC_QTY_FOR_LAYER');
393: FND_MSG_PUB.Add;
394: RETURN;
408: -- If the reverse transaction is alrady used in
409: -- VIB details, get the quantity used in VIB details.
410: -- We need to leave that much qty to reverse those VIB details later.
411:
412: IF g_debug <= gme_debug.g_log_statement THEN
413: gme_debug.put_line ('Reversal. get the quantity used in VIB details, if any.');
414: END IF;
415:
416: BEGIN
409: -- VIB details, get the quantity used in VIB details.
410: -- We need to leave that much qty to reverse those VIB details later.
411:
412: IF g_debug <= gme_debug.g_log_statement THEN
413: gme_debug.put_line ('Reversal. get the quantity used in VIB details, if any.');
414: END IF;
415:
416: BEGIN
417: SELECT -sum(nvl(consume_ib_doc_qty,0)), l.ROWID
423: l.layer_id = v.consume_layer_id (+)
424: GROUP BY l.ROWID;
425:
426:
427: IF g_debug <= gme_debug.g_log_statement THEN
428: gme_debug.put_line ('Reversal. quantity already used in VIB details is: ' ||
429: l_rev_consume_ib_doc_qty);
430: END IF;
431:
424: GROUP BY l.ROWID;
425:
426:
427: IF g_debug <= gme_debug.g_log_statement THEN
428: gme_debug.put_line ('Reversal. quantity already used in VIB details is: ' ||
429: l_rev_consume_ib_doc_qty);
430: END IF;
431:
432: l_remaining_ib_doc_qty := l_rev_consume_ib_doc_qty;
444: NULL;
445: END;
446: END IF;
447:
448: IF g_debug <= gme_debug.g_log_statement THEN
449: gme_debug.put_line ('l_remaining_ib_doc_qty: ' || l_remaining_ib_doc_qty);
450: END IF;
451:
452: IF l_remaining_ib_doc_qty > 0 THEN
445: END;
446: END IF;
447:
448: IF g_debug <= gme_debug.g_log_statement THEN
449: gme_debug.put_line ('l_remaining_ib_doc_qty: ' || l_remaining_ib_doc_qty);
450: END IF;
451:
452: IF l_remaining_ib_doc_qty > 0 THEN
453: -- If ingredients were consumed after the product was yielded, there are
454: -- VIB details pointing to the NULL consumption layers. If possible,
455: -- Update them to consume from this layer. This is done only if the product
456: -- Layer is not posted to subledgerand the cost is not frozen.
457:
458: IF g_debug <= gme_debug.g_log_statement THEN
459: gme_debug.put_line ('getting null consumption layers from VIB details, if any');
460: END IF;
461:
462: FOR n IN c_null_vib_rows LOOP
455: -- Update them to consume from this layer. This is done only if the product
456: -- Layer is not posted to subledgerand the cost is not frozen.
457:
458: IF g_debug <= gme_debug.g_log_statement THEN
459: gme_debug.put_line ('getting null consumption layers from VIB details, if any');
460: END IF;
461:
462: FOR n IN c_null_vib_rows LOOP
463:
460: END IF;
461:
462: FOR n IN c_null_vib_rows LOOP
463:
464: IF g_debug <= gme_debug.g_log_statement THEN
465: gme_debug.put_line ('found null consumption layers. prodLayer/ConsLayer/lineType: ' ||
466: n.prod_layer_id||'/'||n.consume_layer_id||'/'||n.line_type);
467: END IF;
468:
461:
462: FOR n IN c_null_vib_rows LOOP
463:
464: IF g_debug <= gme_debug.g_log_statement THEN
465: gme_debug.put_line ('found null consumption layers. prodLayer/ConsLayer/lineType: ' ||
466: n.prod_layer_id||'/'||n.consume_layer_id||'/'||n.line_type);
467: END IF;
468:
469: BEGIN
494:
495: -- If ingredient qty is more then what is needed.
496: IF n.consume_ib_doc_qty <= l_remaining_ib_doc_qty THEN
497:
498: IF g_debug <= gme_debug.g_log_statement THEN
499: gme_debug.put_line ('If ingredient qty is more then what is needed.');
500: END IF;
501:
502: UPDATE gmf_batch_vib_details
495: -- If ingredient qty is more then what is needed.
496: IF n.consume_ib_doc_qty <= l_remaining_ib_doc_qty THEN
497:
498: IF g_debug <= gme_debug.g_log_statement THEN
499: gme_debug.put_line ('If ingredient qty is more then what is needed.');
500: END IF;
501:
502: UPDATE gmf_batch_vib_details
503: SET consume_layer_id = l_layer_id,
510: -- Split the row into 2.
511: -- Create another row with NULL layer for remaining quantity
512: -- First convert the consume quantity to primary UM.
513:
514: IF g_debug <= gme_debug.g_log_statement THEN
515: gme_debug.put_line ('If ingredient qty is less then what is needed...split the row into 2');
516: END IF;
517:
518: l_consume_ib_doc_qty := n.consume_ib_doc_qty - l_remaining_ib_doc_qty;
511: -- Create another row with NULL layer for remaining quantity
512: -- First convert the consume quantity to primary UM.
513:
514: IF g_debug <= gme_debug.g_log_statement THEN
515: gme_debug.put_line ('If ingredient qty is less then what is needed...split the row into 2');
516: END IF;
517:
518: l_consume_ib_doc_qty := n.consume_ib_doc_qty - l_remaining_ib_doc_qty;
519:
589: NULL; -- Skip to the next row
590: END;
591: END LOOP;
592:
593: IF g_debug <= gme_debug.g_log_statement THEN
594: gme_debug.put_line ('done processing consumption layers from VIB details');
595: END IF;
596:
597: END IF;
590: END;
591: END LOOP;
592:
593: IF g_debug <= gme_debug.g_log_statement THEN
594: gme_debug.put_line ('done processing consumption layers from VIB details');
595: END IF;
596:
597: END IF;
598:
595: END IF;
596:
597: END IF;
598:
599: IF g_debug <= gme_debug.g_log_statement THEN
600: gme_debug.put_line ('creating new outgoing layers...');
601: END IF;
602:
603: INSERT INTO gmf_outgoing_material_layers(
596:
597: END IF;
598:
599: IF g_debug <= gme_debug.g_log_statement THEN
600: gme_debug.put_line ('creating new outgoing layers...');
601: END IF;
602:
603: INSERT INTO gmf_outgoing_material_layers(
604: layer_id,
628: p_tran_rec.last_updated_by,
629: sysdate,
630: p_tran_rec.last_update_login);
631:
632: IF g_debug <= gme_debug.g_log_statement THEN
633: gme_debug.put_line (sql%ROWCOUNT || ' rows inserted');
634: END IF;
635:
636: x_return_status := FND_API.G_RET_STS_SUCCESS;
629: sysdate,
630: p_tran_rec.last_update_login);
631:
632: IF g_debug <= gme_debug.g_log_statement THEN
633: gme_debug.put_line (sql%ROWCOUNT || ' rows inserted');
634: END IF;
635:
636: x_return_status := FND_API.G_RET_STS_SUCCESS;
637:
635:
636: x_return_status := FND_API.G_RET_STS_SUCCESS;
637:
638:
639: IF g_debug <= gme_debug.g_log_procedure THEN
640: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
641: END IF;
642:
643: EXCEPTION
636: x_return_status := FND_API.G_RET_STS_SUCCESS;
637:
638:
639: IF g_debug <= gme_debug.g_log_procedure THEN
640: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
641: END IF;
642:
643: EXCEPTION
644: WHEN OTHERS THEN
717: BEGIN
718: x_return_status := FND_API.G_RET_STS_SUCCESS ;
719:
720:
721: IF g_debug <= gme_debug.g_log_procedure THEN
722: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
723: gme_debug.put_line ('processing batch: ' || p_rsrc_rec.doc_id || ' lineID: ' || p_rsrc_rec.line_id ||
724: ' rsrc/org/txnId/reverseId: ' || p_rsrc_rec.resources ||'/'|| p_rsrc_rec.organization_id || '/' ||
725: p_rsrc_rec.poc_trans_id ||'/'|| p_rsrc_rec.reverse_id);
718: x_return_status := FND_API.G_RET_STS_SUCCESS ;
719:
720:
721: IF g_debug <= gme_debug.g_log_procedure THEN
722: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
723: gme_debug.put_line ('processing batch: ' || p_rsrc_rec.doc_id || ' lineID: ' || p_rsrc_rec.line_id ||
724: ' rsrc/org/txnId/reverseId: ' || p_rsrc_rec.resources ||'/'|| p_rsrc_rec.organization_id || '/' ||
725: p_rsrc_rec.poc_trans_id ||'/'|| p_rsrc_rec.reverse_id);
726: gme_debug.put_line ('transQty: ' || p_rsrc_rec.resource_usage || ' ' || p_rsrc_rec.trans_qty_um ||
719:
720:
721: IF g_debug <= gme_debug.g_log_procedure THEN
722: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
723: gme_debug.put_line ('processing batch: ' || p_rsrc_rec.doc_id || ' lineID: ' || p_rsrc_rec.line_id ||
724: ' rsrc/org/txnId/reverseId: ' || p_rsrc_rec.resources ||'/'|| p_rsrc_rec.organization_id || '/' ||
725: p_rsrc_rec.poc_trans_id ||'/'|| p_rsrc_rec.reverse_id);
726: gme_debug.put_line ('transQty: ' || p_rsrc_rec.resource_usage || ' ' || p_rsrc_rec.trans_qty_um ||
727: ' doc qty: ' || p_doc_qty || ' ' || p_doc_um);
722: gme_debug.put_line ('Entering api ' || g_pkg_name || '.' || l_api_name);
723: gme_debug.put_line ('processing batch: ' || p_rsrc_rec.doc_id || ' lineID: ' || p_rsrc_rec.line_id ||
724: ' rsrc/org/txnId/reverseId: ' || p_rsrc_rec.resources ||'/'|| p_rsrc_rec.organization_id || '/' ||
725: p_rsrc_rec.poc_trans_id ||'/'|| p_rsrc_rec.reverse_id);
726: gme_debug.put_line ('transQty: ' || p_rsrc_rec.resource_usage || ' ' || p_rsrc_rec.trans_qty_um ||
727: ' doc qty: ' || p_doc_qty || ' ' || p_doc_um);
728: END IF;
729:
730: -- Possible validations
927: p_rsrc_rec.last_update_login);
928:
929: x_return_status := FND_API.G_RET_STS_SUCCESS;
930:
931: IF g_debug <= gme_debug.g_log_procedure THEN
932: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
933: END IF;
934:
935: EXCEPTION
928:
929: x_return_status := FND_API.G_RET_STS_SUCCESS;
930:
931: IF g_debug <= gme_debug.g_log_procedure THEN
932: gme_debug.put_line ('Exiting api ' || g_pkg_name || '.' || l_api_name);
933: END IF;
934:
935: EXCEPTION
936: WHEN OTHERS THEN