271: --* in process_batch()
272: --* - Added NVL clause in process_reversals to avoid "ORA error- Cannot insert NULL into
273: --* into TOTAL_TRANS_COST".
274: --* - Moved the old_cost.onhand_qty into ELSE part of lot_cost_cursor%FOUND in
275: --* rollup_lot_costs(). This is to initialize if there is no record in gmf_lot_costs
276: --* 19-Apr-2005 Dinesh Bug# 4165614
277: --* Passed correct shipped date to book the receive transaction in case of internal orders
278: --* Modified argument passing date for process_movements in process_receipts()
279: --* 28-Apr-2005 WmJohn Harris Bug# 4307381 -- procedure process_batch :
531: l_itemno_tab itemno_tab;
532:
533: -- Bug 13038249 Grupo viz changes Ends
534:
535: old_cost gmf_lot_costs%ROWTYPE;
536: old_cost_tab l_cost_tab_type; -- Existing lot costs of lot being rolled up
537:
538: new_cost gmf_lot_costs%ROWTYPE;
539: new_cost_tab l_cost_tab_type; -- New lot costs of lot being rolled up
534:
535: old_cost gmf_lot_costs%ROWTYPE;
536: old_cost_tab l_cost_tab_type; -- Existing lot costs of lot being rolled up
537:
538: new_cost gmf_lot_costs%ROWTYPE;
539: new_cost_tab l_cost_tab_type; -- New lot costs of lot being rolled up
540:
541: ing_cost gmf_lot_costs%ROWTYPE;
542: ing_cost_tab l_cost_tab_type; -- Batch ingredient cost
537:
538: new_cost gmf_lot_costs%ROWTYPE;
539: new_cost_tab l_cost_tab_type; -- New lot costs of lot being rolled up
540:
541: ing_cost gmf_lot_costs%ROWTYPE;
542: ing_cost_tab l_cost_tab_type; -- Batch ingredient cost
543:
544: prd_cost gmf_lot_costs%ROWTYPE;
545: prd_cost_tab l_cost_tab_type; -- Batch product cost
540:
541: ing_cost gmf_lot_costs%ROWTYPE;
542: ing_cost_tab l_cost_tab_type; -- Batch ingredient cost
543:
544: prd_cost gmf_lot_costs%ROWTYPE;
545: prd_cost_tab l_cost_tab_type; -- Batch product cost
546:
547: cur_cost_tab l_cost_tab_type; -- Current costs of batch step
548:
1307: , p_cost_type_id NUMBER
1308: )
1309: IS
1310: SELECT *
1311: FROM gmf_lot_costs glc
1312: WHERE glc.lot_number = p_lot_number
1313: AND glc.inventory_item_id = p_item_id
1314: AND glc.organization_id = p_orgn_id
1315: AND glc.cost_type_id = p_cost_type_id
1327: , p_cost_type_id NUMBER
1328: )
1329: IS
1330: SELECT *
1331: FROM gmf_lot_costs glc
1332: WHERE glc.lot_number = p_lot_number
1333: AND glc.inventory_item_id = p_item_id
1334: AND glc.organization_id = p_orgn_id
1335: AND glc.cost_type_id = p_cost_type_id
2234: END process_burdens;
2235:
2236: --**********************************************************************************************
2237: --* *
2238: --* Procedure to create a cost header for a new lot in gmf_lot_costs *
2239: --* *
2240: --**********************************************************************************************
2241:
2242:
2287: fnd_file.put_line(fnd_file.log,'Doc Type = '||p_trx_src_type_id||','||p_txn_act_id);
2288: fnd_file.put_line(fnd_file.log,'Doc ID = '||p_doc_id);
2289: END IF;
2290:
2291: INSERT INTO gmf_lot_costs
2292: ( header_id
2293: , inventory_item_id
2294: , lot_number
2295: , organization_id
2850:
2851: PROCEDURE process_adjustment
2852: IS
2853: loop_count NUMBER;
2854: l_header_id gmf_lot_costs.header_id%type;
2855: procedure_name VARCHAR2(100);
2856: BEGIN
2857:
2858: procedure_name := 'Process Adjustment';
2878: THEN
2879: clone_costs;
2880: END IF;
2881:
2882: UPDATE gmf_lot_costs
2883: SET onhand_qty = onhand_qty + transaction_row.trans_qty
2884: , last_update_date = sysdate
2885: WHERE header_id = old_cost.header_id;
2886:
2955: --*
2956: --* Dinesh 4227784 - Issue due to the above changes. Since we have added gmf_material_lot_cost_txns
2957: --* to the get_previous_costs_cur CURSOR, while querying for the prev-prev transaction
2958: --* it will ignore the reversal transactions if any, because the reversal transaction will
2959: --* not have the exact header_id as in gmf_lot_costs. Rather it will have the same header_id
2960: --* as that of its original transaction.
2961: --* So removed this table and added seperately to get new_cost_ind
2962: --*
2963: --**********************************************************************************************
2982: header_id prev_header_id,
2983: unit_cost prev_unit_cost,
2984: RANK () OVER (PARTITION BY glc.inventory_item_id, glc.organization_id, glc.cost_type_id, glc.lot_number
2985: ORDER BY glc.cost_date DESC, glc.header_id DESC) lot_cost_rank
2986: FROM gmf_lot_costs glc
2987: WHERE glc.inventory_item_id = p_item_id
2988: AND glc.lot_number = p_lot_number
2989: AND glc.organization_id = p_orgn_id
2990: AND glc.cost_type_id = p_cost_type_id
3016: ORDER BY cost_trans_id DESC
3017: ;
3018:
3019: l_prev_cost_cnt NUMBER := 0;
3020: l_prev_header_id gmf_lot_costs.header_id%TYPE;
3021: l_prev_prev_header_id gmf_lot_costs.header_id%TYPE := NULL;
3022: l_prev_unit_cost gmf_lot_costs.unit_cost%TYPE;
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3017: ;
3018:
3019: l_prev_cost_cnt NUMBER := 0;
3020: l_prev_header_id gmf_lot_costs.header_id%TYPE;
3021: l_prev_prev_header_id gmf_lot_costs.header_id%TYPE := NULL;
3022: l_prev_unit_cost gmf_lot_costs.unit_cost%TYPE;
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3025: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3018:
3019: l_prev_cost_cnt NUMBER := 0;
3020: l_prev_header_id gmf_lot_costs.header_id%TYPE;
3021: l_prev_prev_header_id gmf_lot_costs.header_id%TYPE := NULL;
3022: l_prev_unit_cost gmf_lot_costs.unit_cost%TYPE;
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3025: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3026: l_header_id gmf_lot_costs.header_id%TYPE;
3021: l_prev_prev_header_id gmf_lot_costs.header_id%TYPE := NULL;
3022: l_prev_unit_cost gmf_lot_costs.unit_cost%TYPE;
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3025: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3026: l_header_id gmf_lot_costs.header_id%TYPE;
3027: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3028: l_prev_trans_unit_cost gmf_lot_cost_details.component_cost%TYPE;
3029: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3022: l_prev_unit_cost gmf_lot_costs.unit_cost%TYPE;
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3025: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3026: l_header_id gmf_lot_costs.header_id%TYPE;
3027: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3028: l_prev_trans_unit_cost gmf_lot_cost_details.component_cost%TYPE;
3029: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3030: l_prev_new_cost_ind gmf_material_lot_cost_txns.new_cost_ind%TYPE; /* Dinesh No Bug# */
3023: l_cost_header_id gmf_material_lot_cost_txns.cost_header_id%TYPE;
3024:
3025: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3026: l_header_id gmf_lot_costs.header_id%TYPE;
3027: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3028: l_prev_trans_unit_cost gmf_lot_cost_details.component_cost%TYPE;
3029: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3030: l_prev_new_cost_ind gmf_material_lot_cost_txns.new_cost_ind%TYPE; /* Dinesh No Bug# */
3031: procedure_name VARCHAR2(100);
3227: --************************************************************************************************
3228: --* Procedure Name : PROCESS_REVERSALS2
3229: --*
3230: --* Desc: New Procedure for handling batch product reversal transactions
3231: --* In process_reversals procedure we check whether the cost record in gmf_lot_costs
3232: --* just prior to reversal transaction is its Original transaction.
3233: --* If so, we will leap frog that record so as to reverse the effect of original transaction
3234: --* in the average cost of the lot. gmf_material_lot_cost_txns will be pointed to the original
3235: --* transaction record, so that subledger posts the entry accordingly. BUT we are not handling
3265: -- Bug 9239944
3266: CURSOR get_last_wipcompletion
3267: IS
3268: SELECT mmt.transaction_id
3269: FROM gmf_lot_costs glc, gmf_material_lot_cost_txns gmt,
3270: mtl_material_transactions mmt
3271: WHERE glc.lot_number = transaction_row.lot_number
3272: AND glc.inventory_item_id = transaction_row.inventory_item_id
3273: AND glc.organization_id = transaction_row.orgn_id
3288: WHERE txns.transaction_id = p_orig_trans_id
3289: AND txns.cost_type_id = l_cost_type_id -- PK 9069363 added cost_type_id and order by
3290: Order by cost_header_id desc;
3291:
3292: l_orig_trx_header_id gmf_lot_costs.header_id%TYPE;
3293: l_orig_trx_new_cost_ind NUMBER;
3294: l_orig_trx_trans_cost NUMBER;
3295: orig_trx_cost_tab l_cost_tab_type;
3296: l_txn_cost_tab l_cost_tab_type; -- PK Bug 14487964 14541507
3294: l_orig_trx_trans_cost NUMBER;
3295: orig_trx_cost_tab l_cost_tab_type;
3296: l_txn_cost_tab l_cost_tab_type; -- PK Bug 14487964 14541507
3297:
3298: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3299: l_header_id gmf_lot_costs.header_id%TYPE;
3300: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3301: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3302: i NUMBER;
3295: orig_trx_cost_tab l_cost_tab_type;
3296: l_txn_cost_tab l_cost_tab_type; -- PK Bug 14487964 14541507
3297:
3298: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3299: l_header_id gmf_lot_costs.header_id%TYPE;
3300: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3301: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3302: i NUMBER;
3303: procedure_name VARCHAR2(100);
3296: l_txn_cost_tab l_cost_tab_type; -- PK Bug 14487964 14541507
3297:
3298: l_onhand_qty gmf_lot_costs.onhand_qty%TYPE;
3299: l_header_id gmf_lot_costs.header_id%TYPE;
3300: l_unit_cost gmf_lot_costs.unit_cost%TYPE;
3301: l_cmpnt_cost gmf_lot_cost_details.component_cost%TYPE;
3302: i NUMBER;
3303: procedure_name VARCHAR2(100);
3304: orig_completion_transid NUMBER; -- Bug 9239944
3389: THEN
3390: clone_costs;
3391: END IF;
3392:
3393: UPDATE gmf_lot_costs
3394: SET onhand_qty = onhand_qty + transaction_row.trans_qty,
3395: last_update_date = sysdate
3396: WHERE header_id = old_cost.header_id;
3397:
3397:
3398: IF(SQL%ROWCOUNT = 1) THEN
3399: l_return_status := 'S';
3400: ELSE
3401: fnd_file.put_line(fnd_file.log,'Reversals2: Error in updating gmf_lot_costs for transaction_id: '||to_char(transaction_row.transaction_id));
3402: l_return_status := 'E';
3403: RETURN;
3404: END IF;
3405:
3621: END IF;
3622: END IF;
3623: -- As there is a chance that the two organizations could be in separate companies we need to do something
3624: -- to ensure we can locate a cost for the sending transaction. If the two companies involved are the same
3625: -- we can simply query the gmf_lot_costs table. If not we have to do dig around for costs.
3626:
3627: -- Bug 13038249 Grupo viz changes start
3628: l_source_ou := org_coll_tab(p_source_orgn).ou_id ;
3629: l_target_ou := org_coll_tab(p_target_orgn).ou_id ;
8076:
8077: TYPE lot_cost_cursor_type IS REF CURSOR;
8078: Cur_lc_header lot_cost_cursor_type;
8079:
8080: TYPE header_ids_tab IS TABLE OF gmf_lot_costs.header_id%TYPE
8081: INDEX BY BINARY_INTEGER;
8082: l_header_ids_tab header_ids_tab;
8083: l_empty_header_ids_tab header_ids_tab;
8084:
8114:
8115: -- Open a cursor that retrieves only the item/lot/sublot specified
8116: OPEN Cur_lc_header FOR
8117: SELECT glc.header_id, glc.rowid
8118: FROM gmf_lot_costs glc,
8119: gmf_lot_costed_items_gt gpo
8120: WHERE glc.organization_id = gpo.organization_id
8121: AND glc.inventory_item_id = gpo.inventory_item_id
8122: AND glc.cost_type_id = l_cost_type_id
8190: END LOOP;
8191:
8192: -- Now delete all rows from main lot costs table
8193: FORALL indx IN l_rowids_tab.FIRST..l_rowids_tab.LAST
8194: DELETE FROM gmf_lot_costs
8195: WHERE rowid in l_rowids_tab(indx);
8196:
8197: fnd_file.put_line(fnd_File.LOG, ' ' || l_matl_rows_deleted || ' rows deleted from gmf_material_lot_cost_txns.');
8198: fnd_file.put_line(fnd_File.LOG, ' ' || l_cdtl_rows_deleted || ' rows deleted from gmf_lot_cost_details.');
8195: WHERE rowid in l_rowids_tab(indx);
8196:
8197: fnd_file.put_line(fnd_File.LOG, ' ' || l_matl_rows_deleted || ' rows deleted from gmf_material_lot_cost_txns.');
8198: fnd_file.put_line(fnd_File.LOG, ' ' || l_cdtl_rows_deleted || ' rows deleted from gmf_lot_cost_details.');
8199: fnd_file.put_line(fnd_File.LOG, ' ' || SQL%ROWCOUNT || ' rows deleted from gmf_lot_costs.');
8200:
8201: COMMIT;
8202:
8203: -- remove old rows and release memory.
8215: WHERE cost_type_id = l_cost_type_id
8216: AND t.final_cost_flag = 0 -- Bug 7173679
8217: AND EXISTS (
8218: SELECT 1
8219: FROM gmf_lot_costs glc,
8220: gmf_process_organizations_gt gpo
8221: WHERE glc.organization_id = gpo.organization_id
8222: AND glc.header_id = t.cost_header_id
8223: AND glc.cost_type_id = t.cost_type_id
9041: AUTHOR : Sukarna Reddy INVCONV
9042: ==========================================================*/
9043:
9044: PROCEDURE process_lot_split IS
9045: l_old_cost gmf_lot_costs%ROWTYPE;
9046: l_old_cost_tab l_cost_tab_type;
9047: l_parent_lot_number VARCHAR2(80);
9048: i NUMBER;
9049: l_new_cost NUMBER;
9198:
9199: l_unit_cost NUMBER;
9200: l_total_cost NUMBER;
9201: l_cost_tab l_cost_tab_type;
9202: l_old_cost gmf_lot_costs%rowtype;
9203: l_new_cost_tab l_cost_tab_type;
9204: procedure_name VARCHAR2(100);
9205:
9206:
9339: ==========================================================*/
9340:
9341:
9342: PROCEDURE process_lot_translate IS
9343: l_old_cost gmf_lot_costs%rowtype;
9344: l_cost_tab l_cost_tab_type;
9345: l_lot_number VARCHAR2(80);
9346: l_trans_date DATE;
9347: i PLS_INTEGER;
9871: AND lot_number = transaction_row.lot_number
9872: AND cost_type_id = l_cost_type_id;
9873:
9874: SELECT * INTO new_cost
9875: FROM gmf_lot_costs
9876: WHERE header_id = l_header_id;
9877:
9878: create_material_transaction
9879: ( p_header_id => l_header_id
10234: -- if transactions have been back-dated the algorithm will work, but might produce
10235: -- a wrong answer.
10236:
10237: -- For each replenishment we must add a new row to (or update the existing
10238: -- row in) GMF_LOT_COSTS, add new rows to (or update the existing rows in)
10239: -- GMF_LOT_COST_DETAILS and finally create a row in GMF_LOT_COST_TRANSACTIONS
10240: -- that links the inventory transaction to the row in GMF_LOT_COSTS.
10241:
10242: -- For each consumption we leave the GMF_LOT_COSTS and GMF_LOT_COST_DETAILS
10236:
10237: -- For each replenishment we must add a new row to (or update the existing
10238: -- row in) GMF_LOT_COSTS, add new rows to (or update the existing rows in)
10239: -- GMF_LOT_COST_DETAILS and finally create a row in GMF_LOT_COST_TRANSACTIONS
10240: -- that links the inventory transaction to the row in GMF_LOT_COSTS.
10241:
10242: -- For each consumption we leave the GMF_LOT_COSTS and GMF_LOT_COST_DETAILS
10243: -- rows alone and just create the GMF_LOT_COST_TRANSACTIONS row.
10244:
10238: -- row in) GMF_LOT_COSTS, add new rows to (or update the existing rows in)
10239: -- GMF_LOT_COST_DETAILS and finally create a row in GMF_LOT_COST_TRANSACTIONS
10240: -- that links the inventory transaction to the row in GMF_LOT_COSTS.
10241:
10242: -- For each consumption we leave the GMF_LOT_COSTS and GMF_LOT_COST_DETAILS
10243: -- rows alone and just create the GMF_LOT_COST_TRANSACTIONS row.
10244:
10245: --
10246: -- umoogala 21-Nov-2003
11654: END IF;
11655:
11656: -- Bug 12394608 Need to use 'AND inventory_item_id = transaction_row.inventory_item_id' as well
11657:
11658: UPDATE gmf_lot_costs
11659: SET onhand_qty = l_residual_qty
11660: WHERE header_id = (SELECT max(header_id)
11661: FROM gmf_lot_costs
11662: WHERE organization_id = transaction_row.orgn_id
11657:
11658: UPDATE gmf_lot_costs
11659: SET onhand_qty = l_residual_qty
11660: WHERE header_id = (SELECT max(header_id)
11661: FROM gmf_lot_costs
11662: WHERE organization_id = transaction_row.orgn_id
11663: AND lot_number = transaction_row.lot_number
11664: AND inventory_item_id = transaction_row.inventory_item_id)
11665: RETURNING header_id INTO new_cost.header_id;
11700:
11701: END IF;
11702:
11703: -- for all sources this needs to be updated
11704: UPDATE gmf_lot_costs
11705: SET final_cost_flag = 1
11706: WHERE header_id = new_cost.header_id;
11707:
11708: ELSE