68: l_err_msg := '';
69: l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
70:
71: if (l_debug = 'Y') then
72: FND_FILE.PUT_LINE(FND_FILE.LOG,'Compute layer actual cost ...');
73: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer ID : ' || to_char(i_layer_id));
74: FND_FILE.PUT_LINE(FND_FILE.LOG,'cost hook : ' || to_char(i_cost_hook));
75: end if;
76:
69: l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
70:
71: if (l_debug = 'Y') then
72: FND_FILE.PUT_LINE(FND_FILE.LOG,'Compute layer actual cost ...');
73: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer ID : ' || to_char(i_layer_id));
74: FND_FILE.PUT_LINE(FND_FILE.LOG,'cost hook : ' || to_char(i_cost_hook));
75: end if;
76:
77:
70:
71: if (l_debug = 'Y') then
72: FND_FILE.PUT_LINE(FND_FILE.LOG,'Compute layer actual cost ...');
73: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer ID : ' || to_char(i_layer_id));
74: FND_FILE.PUT_LINE(FND_FILE.LOG,'cost hook : ' || to_char(i_cost_hook));
75: end if;
76:
77:
78: /* For WIP component issue and negative component return,layers have already
223: l_err_msg := '';
224: l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
225:
226: if (l_debug = 'Y') then
227: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consume/Create Layers...');
228: end if;
229:
230: if ((i_txn_action_id = 1) /* Issue from stores */
231: OR (i_interorg_rec = 0) /* interorg shipment */
248: redundant */
249: ) then
250: l_stmt_num := 10;
251: if (l_debug = 'Y') then
252: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consumption Transaction ...');
253: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
254: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
255: end if;
256: consume_layers(
249: ) then
250: l_stmt_num := 10;
251: if (l_debug = 'Y') then
252: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consumption Transaction ...');
253: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
254: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
255: end if;
256: consume_layers(
257: i_org_id,
250: l_stmt_num := 10;
251: if (l_debug = 'Y') then
252: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consumption Transaction ...');
253: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
254: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
255: end if;
256: consume_layers(
257: i_org_id,
258: i_txn_id,
303: OR ( i_txn_action_id = 26 and i_txn_qty > 0 ) /*logical Receipt*/
304: ) then
305: l_stmt_num := 20;
306: if (l_debug = 'Y') then
307: FND_FILE.PUT_LINE(FND_FILE.LOG,'Transaction creates inventory layers ...');
308: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
309: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
310: end if;
311: create_layers(
304: ) then
305: l_stmt_num := 20;
306: if (l_debug = 'Y') then
307: FND_FILE.PUT_LINE(FND_FILE.LOG,'Transaction creates inventory layers ...');
308: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
309: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
310: end if;
311: create_layers(
312: i_org_id,
305: l_stmt_num := 20;
306: if (l_debug = 'Y') then
307: FND_FILE.PUT_LINE(FND_FILE.LOG,'Transaction creates inventory layers ...');
308: FND_FILE.PUT_LINE(FND_FILE.LOG,'Action ID : ' || to_char(i_txn_action_id));
309: FND_FILE.PUT_LINE(FND_FILE.LOG,'Primary Qty : ' || to_char(i_txn_qty));
310: end if;
311: create_layers(
312: i_org_id,
313: i_txn_id,
341: /* scrap transaction */
342: l_stmt_num := 30;
343: if (i_cost_hook = 1) then
344: if (l_debug = 'Y') then
345: FND_FILE.PUT_LINE(FND_FILE.LOG,'Scrap transaction with cost hook');
346: end if;
347: return;
348: else
349: if (l_debug = 'Y') then
346: end if;
347: return;
348: else
349: if (l_debug = 'Y') then
350: FND_FILE.PUT_LINE(FND_FILE.LOG,'Scrap transaction inserts into MCACD');
351: end if;
352: insert into mtl_cst_actual_cost_details (
353: transaction_id,
354: organization_id,
530: l_src_number := to_char(i_txn_id);
531: end if;
532:
533: if (l_debug = 'Y') then
534: FND_FILE.PUT_LINE(FND_FILE.LOG,'get_source_number ...');
535: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src Type : ' || to_char(i_txn_src_type));
536: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src ID : ' || to_char(i_src_id));
537: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Source : ' || l_src_number);
538: end if;
531: end if;
532:
533: if (l_debug = 'Y') then
534: FND_FILE.PUT_LINE(FND_FILE.LOG,'get_source_number ...');
535: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src Type : ' || to_char(i_txn_src_type));
536: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src ID : ' || to_char(i_src_id));
537: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Source : ' || l_src_number);
538: end if;
539:
532:
533: if (l_debug = 'Y') then
534: FND_FILE.PUT_LINE(FND_FILE.LOG,'get_source_number ...');
535: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src Type : ' || to_char(i_txn_src_type));
536: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src ID : ' || to_char(i_src_id));
537: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Source : ' || l_src_number);
538: end if;
539:
540: return l_src_number;
533: if (l_debug = 'Y') then
534: FND_FILE.PUT_LINE(FND_FILE.LOG,'get_source_number ...');
535: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src Type : ' || to_char(i_txn_src_type));
536: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Src ID : ' || to_char(i_src_id));
537: FND_FILE.PUT_LINE(FND_FILE.LOG,'Txn Source : ' || l_src_number);
538: end if;
539:
540: return l_src_number;
541: EXCEPTION
540: return l_src_number;
541: EXCEPTION
542: when no_data_found then
543: l_src_number := to_char(i_txn_id);
544: FND_FILE.PUT_LINE(FND_FILE.LOG,'No data found, using transaction ID');
545: return l_src_number;
546:
547: END get_source_number;
548:
629: where transaction_id = i_txn_id;
630:
631: /* Write to log file */
632: if (l_debug = 'Y') then
633: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert Row in MCLACD...');
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
630:
631: /* Write to log file */
632: if (l_debug = 'Y') then
633: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert Row in MCLACD...');
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
631: /* Write to log file */
632: if (l_debug = 'Y') then
633: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert Row in MCLACD...');
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
639: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_layer_id :' || to_char(i_actual_layer_id));
632: if (l_debug = 'Y') then
633: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert Row in MCLACD...');
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
639: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_layer_id :' || to_char(i_actual_layer_id));
640: end if;
633: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert Row in MCLACD...');
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
639: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_layer_id :' || to_char(i_actual_layer_id));
640: end if;
641:
634: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_id:' || to_char(i_layer_id));
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
639: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_layer_id :' || to_char(i_actual_layer_id));
640: end if;
641:
642: select count(*)
635: FND_FILE.PUT_LINE(FND_FILE.LOG,'cur_layer:' || to_char(i_cur_layer_id));
636: FND_FILE.PUT_LINE(FND_FILE.LOG,'qty :'|| to_char(i_qty));
637: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_cost_table:' || (i_actual_cost_table));
638: FND_FILE.PUT_LINE(FND_FILE.LOG,'layer_cost_table:' || (i_layer_cost_table));
639: FND_FILE.PUT_LINE(FND_FILE.LOG,'actual_layer_id :' || to_char(i_actual_layer_id));
640: end if;
641:
642: select count(*)
643: into l_mclacd_exists
687: x_zero_cost_flag => l_zero_cost_flag
688: );
689:
690: if (l_return_status <> fnd_api.g_ret_sts_success) then
691: FND_FILE.put_line(FND_FILE.log, l_msg_data);
692: l_api_message := 'get_zeroCostIssue_flag returned unexpected error';
693: FND_MESSAGE.set_name('BOM','CST_API_MESSAGE');
694: FND_MESSAGE.set_token('TEXT', l_api_message);
695: FND_MSG_pub.add;
696: raise fnd_api.g_exc_unexpected_error;
697: end if;
698:
699: if (l_debug = 'Y') then
700: FND_FILE.PUT_LINE(FND_FILE.LOG,'zero_cost_flag: '|| to_char(l_zero_cost_flag));
701: end if;
702:
703: insert into mtl_cst_layer_act_cost_details (
704: transaction_id,
761: x_zero_cost_flag => l_zero_cost_flag
762: );
763:
764: if (l_return_status <> fnd_api.g_ret_sts_success) then
765: FND_FILE.put_line(FND_FILE.log, l_msg_data);
766: l_api_message := 'get_zeroCostIssue_flag returned unexpected error';
767: FND_MESSAGE.set_name('BOM','CST_API_MESSAGE');
768: FND_MESSAGE.set_token('TEXT', l_api_message);
769: FND_MSG_pub.add;
770: raise fnd_api.g_exc_unexpected_error;
771: end if;
772:
773: if (l_debug = 'Y') then
774: FND_FILE.PUT_LINE(FND_FILE.LOG,'zero_cost_flag: '|| to_char(l_zero_cost_flag));
775: end if;
776:
777: insert into mtl_cst_layer_act_cost_details (
778: transaction_id,
1140: x_zero_cost_flag => l_zero_cost_flag
1141: );
1142:
1143: if (l_return_status <> fnd_api.g_ret_sts_success) then
1144: FND_FILE.put_line(FND_FILE.log, l_msg_data);
1145: l_api_message := 'get_zeroCostIssue_flag returned unexpected error';
1146: FND_MESSAGE.set_name('BOM','CST_API_MESSAGE');
1147: FND_MESSAGE.set_token('TEXT', l_api_message);
1148: FND_MSG_pub.add;
1149: raise fnd_api.g_exc_unexpected_error;
1150: end if;
1151:
1152: if (l_debug = 'Y') then
1153: FND_FILE.PUT_LINE(FND_FILE.LOG,'zero_cost_flag: '|| to_char(l_zero_cost_flag));
1154: end if;
1155: insert into mtl_cst_layer_act_cost_details (
1156: transaction_id,
1157: organization_id,
1212: x_zero_cost_flag => l_zero_cost_flag
1213: );
1214:
1215: if (l_return_status <> fnd_api.g_ret_sts_success) then
1216: FND_FILE.put_line(FND_FILE.log, l_msg_data);
1217: l_api_message := 'get_zeroCostIssue_flag returned unexpected error';
1218: FND_MESSAGE.set_name('BOM','CST_API_MESSAGE');
1219: FND_MESSAGE.set_token('TEXT', l_api_message);
1220: FND_MSG_pub.add;
1221: raise fnd_api.g_exc_unexpected_error;
1222: end if;
1223:
1224: if (l_debug = 'Y') then
1225: FND_FILE.PUT_LINE(FND_FILE.LOG,'zero_cost_flag: '|| to_char(l_zero_cost_flag));
1226: end if;
1227:
1228: l_stmt_num := 20;
1229:
1278:
1279: end if;
1280: end if;
1281: if (l_debug = 'Y') then
1282: FND_FILE.PUT_LINE(FND_FILE.LOG,sql%rowcount || ' records inserted using stmt : ' || to_char(l_stmt_num));
1283: end if;
1284:
1285: if ((l_err_num <> 0) and (l_err_num <> 999)) then
1286: raise process_error;
1392:
1393: /* If expense item, then insert into MCACD using current costs. No inventory layer created */
1394: IF (i_exp_flag = 1) THEN
1395: IF (l_debug = 'Y') THEN
1396: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert into MCACD for expense flag of 1...');
1397: END IF;
1398:
1399: l_stmt_num := 5;
1400: SELECT COUNT(*)
1573: FROM cst_inv_layers
1574: WHERE layer_id = i_layer_id;
1575:
1576: IF (l_debug = 'Y') THEN
1577: FND_FILE.PUT_LINE(FND_FILE.LOG,'Last Inventory Layer : ' || l_inv_layer_id);
1578: END IF;
1579:
1580: /* Obtain cost table, whose costs need to be used to insert into MCLACD
1581: If cost_hook is present, use MCACD, else use costs from MCTCD, or the latest
1602: END IF;
1603: END IF;
1604:
1605: IF (l_debug = 'Y') THEN
1606: FND_FILE.PUT_LINE(FND_FILE.LOG,'Actual cost table : ' || l_actual_cost_table);
1607: END IF;
1608:
1609: /* Insert into MCLACD */
1610: l_stmt_num := 40;
1647: (i_txn_action_id = 32 AND i_txn_src_type = 5) OR /* Assembly completion */
1648: (i_interorg_rec = 1))) /* Interorg receipt */
1649: THEN
1650: IF (l_debug = 'Y') then
1651: FND_FILE.PUT_LINE(FND_FILE.LOG,'Apply layer material overhead ...');
1652: END IF;
1653: l_stmt_num := 50;
1654: apply_layer_material_ovhd(
1655: i_org_id,
1679: END IF;
1680: END IF;
1681:
1682: IF (l_debug = 'Y') THEN
1683: FND_FILE.PUT_LINE(FND_FILE.LOG,' l_inv_layer_id ' ||l_inv_layer_id);
1684: END IF;
1685: /* Check if a layer need to be created */
1686: l_merge := CSTPACHK.LayerMerge_Hook(
1687: i_txn_id => i_txn_id,
1692:
1693: IF (l_merge <> 0 AND l_merge <> 1) OR (l_err_num <> 0) THEN
1694: IF l_debug = 'Y' THEN
1695: l_stmt_num := 15;
1696: fnd_file.put_line(
1697: fnd_file.log,
1698: 'CSTPACHK.layer_hook errors out with '||
1699: 'l_merge ='||l_merge||','||
1700: 'l_err_num = '||l_err_num||','||
1693: IF (l_merge <> 0 AND l_merge <> 1) OR (l_err_num <> 0) THEN
1694: IF l_debug = 'Y' THEN
1695: l_stmt_num := 15;
1696: fnd_file.put_line(
1697: fnd_file.log,
1698: 'CSTPACHK.layer_hook errors out with '||
1699: 'l_merge ='||l_merge||','||
1700: 'l_err_num = '||l_err_num||','||
1701: 'l_err_code = '||l_err_code||','||
1720: AND cil.layer_quantity < 0
1721: AND cil.layer_quantity > cql.layer_quantity;
1722:
1723: IF (l_debug = 'Y') THEN
1724: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_count '||l_count);
1725: END IF;
1726:
1727: IF (l_count = 0) THEN
1728: /* Check the type of the current transaction and the transaction that
1733: FROM cst_inv_layers
1734: WHERE inv_layer_id = l_inv_layer_id;
1735:
1736: IF (l_debug = 'Y') THEN
1737: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_txn_id '||l_last_txn_id);
1738: END IF;
1739:
1740: l_stmt_num := 65;
1741: BEGIN
1750: AND mmt.rcv_transaction_id = rt1.transaction_id (+)
1751: AND rt1.parent_transaction_id = rt2.transaction_id (+);
1752:
1753: IF (l_debug = 'Y') THEN
1754: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_txn_type_id '||l_last_txn_type_id);
1755: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_rcv_txn_id '||l_last_rcv_txn_id);
1756: END IF;
1757: EXCEPTION
1758: when no_data_found then
1751: AND rt1.parent_transaction_id = rt2.transaction_id (+);
1752:
1753: IF (l_debug = 'Y') THEN
1754: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_txn_type_id '||l_last_txn_type_id);
1755: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_rcv_txn_id '||l_last_rcv_txn_id);
1756: END IF;
1757: EXCEPTION
1758: when no_data_found then
1759: l_last_txn_type_id := -1;
1759: l_last_txn_type_id := -1;
1760: l_last_rcv_txn_id := -1;
1761: END;
1762:
1763: FND_FILE.PUT_LINE(FND_FILE.LOG,'i_txn_id '||i_txn_id);
1764: l_stmt_num := 70;
1765: SELECT mmt.transaction_type_id,
1766: decode(rt2.parent_transaction_id,-1,rt2.transaction_id,rt2.parent_transaction_id)
1767: INTO l_txn_type_id,
1773: AND mmt.rcv_transaction_id = rt1.transaction_id (+)
1774: AND rt1.parent_transaction_id = rt2.transaction_id (+);
1775:
1776: IF (l_debug = 'Y') THEN
1777: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_txn_type_id '||l_txn_type_id);
1778: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_rcv_txn_id '||l_rcv_txn_id);
1779: END IF;
1780:
1781: l_stmt_num := 75;
1774: AND rt1.parent_transaction_id = rt2.transaction_id (+);
1775:
1776: IF (l_debug = 'Y') THEN
1777: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_txn_type_id '||l_txn_type_id);
1778: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_rcv_txn_id '||l_rcv_txn_id);
1779: END IF;
1780:
1781: l_stmt_num := 75;
1782: IF ( ( (l_txn_type_id = l_last_txn_type_id)
1805: AND cost_element_id = 2
1806: AND level_type = 1;
1807:
1808: IF (l_debug = 'Y') THEN
1809: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_moh '||l_last_moh);
1810: END IF;
1811: l_stmt_num := 85;
1812:
1813: SELECT nvl(SUM(actual_cost),0)
1820: AND cost_element_id = 2
1821: AND level_type = 1;
1822:
1823: IF (l_debug = 'Y') THEN
1824: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_moh '||l_moh);
1825: END IF;
1826:
1827: IF (l_last_moh=l_moh) THEN
1828: l_create := 0;
1846:
1847:
1848:
1849: IF (l_debug = 'Y') THEN
1850: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_last_layer_cost '||l_last_layer_cost);
1851: END IF;
1852: l_stmt_num := 87;
1853:
1854:
1863: AND level_type = 1;
1864:
1865:
1866: IF (l_debug = 'Y') THEN
1867: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_layer_cost '||l_layer_cost);
1868: END IF;
1869:
1870:
1871: IF (l_last_layer_cost=l_layer_cost) THEN
1875: END IF;
1876: END IF;
1877: ELSE
1878: IF (l_debug = 'Y') THEN
1879: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_actual_cost_table '||l_actual_cost_table);
1880: END IF;
1881: IF (l_actual_cost_table = 'CILCD') THEN
1882: l_create := 0;
1883: END IF;
1886: END IF;
1887: END IF;
1888:
1889: IF (l_debug = 'Y') THEN
1890: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_create '||l_create);
1891: END IF;
1892:
1893: IF (l_create = 0) THEN
1894: IF (l_debug = 'Y') THEN
1891: END IF;
1892:
1893: IF (l_create = 0) THEN
1894: IF (l_debug = 'Y') THEN
1895: FND_FILE.PUT_LINE(FND_FILE.LOG,'Adding inventory layers ...');
1896: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1897: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1898: END IF;
1899:
1892:
1893: IF (l_create = 0) THEN
1894: IF (l_debug = 'Y') THEN
1895: FND_FILE.PUT_LINE(FND_FILE.LOG,'Adding inventory layers ...');
1896: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1897: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1898: END IF;
1899:
1900: /* Get transaction source ID for the transaction */
1893: IF (l_create = 0) THEN
1894: IF (l_debug = 'Y') THEN
1895: FND_FILE.PUT_LINE(FND_FILE.LOG,'Adding inventory layers ...');
1896: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1897: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1898: END IF;
1899:
1900: /* Get transaction source ID for the transaction */
1901: l_stmt_num := 86;
1932: INTO l_inv_layer_id
1933: FROM dual;
1934:
1935: IF (l_debug = 'Y') THEN
1936: FND_FILE.PUT_LINE(FND_FILE.LOG,'Creating inventory layers ...');
1937: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1938: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1939: END IF;
1940:
1933: FROM dual;
1934:
1935: IF (l_debug = 'Y') THEN
1936: FND_FILE.PUT_LINE(FND_FILE.LOG,'Creating inventory layers ...');
1937: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1938: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1939: END IF;
1940:
1941: /* Update MCLACD entries */
1934:
1935: IF (l_debug = 'Y') THEN
1936: FND_FILE.PUT_LINE(FND_FILE.LOG,'Creating inventory layers ...');
1937: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Number : ' || to_char(l_inv_layer_id));
1938: FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory Layer Quantity : ' || to_char(i_txn_qty));
1939: END IF;
1940:
1941: /* Update MCLACD entries */
1942: l_stmt_num := 100;
1945: WHERE transaction_id = i_txn_id
1946: AND organization_id = i_org_id
1947: AND layer_id = i_layer_id;
1948:
1949: FND_FILE.PUT_LINE(FND_FILE.LOG, sql%rowcount || ' records updated in mclacd for ' || l_inv_layer_id);
1950:
1951: /* Get transaction source ID for the transaction */
1952: l_stmt_num := 105;
1953: SELECT transaction_source_id
2010: i_prg_id,
2011: sysdate);
2012:
2013: IF (l_debug = 'Y') THEN
2014: FND_FILE.PUT_LINE(FND_FILE.LOG, 'Inventory layer created');
2015: END IF;
2016:
2017: /* Delete cost details for the inventory layer from CILCD. No rows should
2018: be present. Just a safety check */
2062: inv_layer_id,
2063: cost_element_id,
2064: level_type;
2065:
2066: FND_FILE.PUT_LINE(FND_FILE.LOG, sql%rowcount || ' records copied from mclacd for ' || l_inv_layer_id);
2067: /* Update layer cost in CIL */
2068: l_stmt_num := 130;
2069: IF (nvl(i_interorg_rec,-1) <> 3) THEN
2070: UPDATE cst_inv_layers
2089: AND inv_layer_id = l_inv_layer_id;
2090: END IF;
2091:
2092: IF (l_debug = 'Y') THEN
2093: FND_FILE.PUT_LINE(FND_FILE.LOG,'CIL cost updated from CILCD');
2094: END IF;
2095: END IF; /* l_create = 0 */
2096:
2097: /* Create cursor to find any negative layers, order in FIFO/LIFO method */
2112:
2113: l_qty_available := abs(i_txn_qty);
2114:
2115: IF (l_debug = 'Y') then
2116: FND_FILE.PUT_LINE(
2117: FND_FILE.LOG,
2118: 'Qty available for replenishment : ' || to_char(l_qty_available));
2119: END IF;
2120:
2113: l_qty_available := abs(i_txn_qty);
2114:
2115: IF (l_debug = 'Y') then
2116: FND_FILE.PUT_LINE(
2117: FND_FILE.LOG,
2118: 'Qty available for replenishment : ' || to_char(l_qty_available));
2119: END IF;
2120:
2121: /* Loop while positive quantity is available, get the next negative layer and
2325: l_debug := FND_PROFILE.VALUE('MRP_DEBUG');
2326:
2327: l_stmt_num := 5;
2328: if (l_debug = 'Y') then
2329: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consuming inventory layers from CG layer : ' || to_char(i_layer_id));
2330: end if;
2331: select count(*)
2332: into l_layers_exist
2333: from cst_inv_layers
2334: where layer_id = i_layer_id;
2335:
2336: if (l_layers_exist = 0) then
2337: if (l_debug = 'Y') then
2338: FND_FILE.PUT_LINE(FND_FILE.LOG,'Creating negative layer ...');
2339: end if;
2340:
2341: /* Bug 2325297
2342: Create Layers is called with i_interorg_rec parameter as NULL
2383:
2384: l_stmt_num := 7;
2385: if (l_exp_item = 1) then
2386: if (l_debug = 'Y') then
2387: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert into MCACD for expense item...');
2388: end if;
2389: select count(*) into l_count
2390: from cst_layer_cost_details
2391: where layer_id = i_layer_id;
2505: l_err_msg);
2506: IF l_err_num <> 0 THEN
2507: IF l_debug = 'Y' THEN
2508: l_stmt_num := 15;
2509: fnd_file.put_line(
2510: fnd_file.log,
2511: 'CSTPACHK.layer_hook errors out with '||
2512: 'l_err_num = '||l_err_num||','||
2513: 'l_err_code = '||l_err_code||','||
2506: IF l_err_num <> 0 THEN
2507: IF l_debug = 'Y' THEN
2508: l_stmt_num := 15;
2509: fnd_file.put_line(
2510: fnd_file.log,
2511: 'CSTPACHK.layer_hook errors out with '||
2512: 'l_err_num = '||l_err_num||','||
2513: 'l_err_code = '||l_err_code||','||
2514: 'l_err_msg = '||l_err_msg
2540: where organization_id = i_org_id
2541: and secondary_inventory_name = l_subinv;
2542:
2543: if (l_debug = 'Y') then
2544: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer specific consumption...');
2545: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer hook : ' || to_char(l_layer_hook));
2546: FND_FILE.PUT_LINE(FND_FILE.LOG,'Source ID : ' || to_char(l_src_id));
2547: end if;
2548: if (l_expsub = 1) then
2541: and secondary_inventory_name = l_subinv;
2542:
2543: if (l_debug = 'Y') then
2544: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer specific consumption...');
2545: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer hook : ' || to_char(l_layer_hook));
2546: FND_FILE.PUT_LINE(FND_FILE.LOG,'Source ID : ' || to_char(l_src_id));
2547: end if;
2548: if (l_expsub = 1) then
2549: IF (l_debug = 'Y') THEN
2542:
2543: if (l_debug = 'Y') then
2544: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer specific consumption...');
2545: FND_FILE.PUT_LINE(FND_FILE.LOG,'Layer hook : ' || to_char(l_layer_hook));
2546: FND_FILE.PUT_LINE(FND_FILE.LOG,'Source ID : ' || to_char(l_src_id));
2547: end if;
2548: if (l_expsub = 1) then
2549: IF (l_debug = 'Y') THEN
2550: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert into MCACD for the Item Coming from Exp Sub Inv ...');
2546: FND_FILE.PUT_LINE(FND_FILE.LOG,'Source ID : ' || to_char(l_src_id));
2547: end if;
2548: if (l_expsub = 1) then
2549: IF (l_debug = 'Y') THEN
2550: FND_FILE.PUT_LINE(FND_FILE.LOG,'Insert into MCACD for the Item Coming from Exp Sub Inv ...');
2551: END IF;
2552:
2553: l_stmt_num := 21;
2554: SELECT COUNT(*)
2697: expense subinv for asset item should come from only the next layer that
2698: would be consumed if it were from asset subinv */
2699: l_stmt_num := 27;
2700: if (l_debug = 'Y') then
2701: FND_FILE.PUT_LINE(FND_FILE.LOG,'Consumption from exp subinv');
2702: end if;
2703:
2704: get_layers_consumed(
2705: i_txn_id => i_txn_id,
2714: );
2715: else
2716: l_stmt_num := 30;
2717: if (l_debug = 'Y') then
2718: fnd_file.put_line(fnd_file.log, 'Regular consumption ');
2719: end if;
2720:
2721: get_layers_consumed(
2722: i_txn_id => i_txn_id,
2820: )
2821: ) then
2822: l_stmt_num :=60;
2823: if (l_debug = 'Y') then
2824: FND_FILE.PUT_LINE(FND_FILE.LOG,'Calling apply_layer_material_ovhd...');
2825: end if;
2826: apply_layer_material_ovhd(
2827: i_org_id,
2828: i_txn_id,
2857: update cst_inv_layers
2858: set layer_quantity = nvl(layer_quantity,0)-l_inv_layer_table(i).layer_quantity
2859: where inv_layer_id = l_inv_layer_table(i).inv_layer_id;
2860: if (l_debug = 'Y') then
2861: FND_FILE.PUT_LINE(FND_FILE.LOG,'CIL.layer_qty changed by ' || to_char(l_inv_layer_table(i).layer_quantity));
2862: end if;
2863: end if;
2864: END LOOP;
2865: END IF; /* IF l_inv_layer_table.COUNT >0 THEN */
2947: l_err_num := 0;
2948: l_err_code := '';
2949: l_err_msg := '';
2950: IF l_debug = 'Y' THEN
2951: fnd_file.put_line(
2952: fnd_file.log,
2953: 'Entering get_layers_consumed for transaction '||i_txn_id||
2954: ' and a required quantity of '||l_required_qty||
2955: ' with a consumption mode of '||consume_mode
2948: l_err_code := '';
2949: l_err_msg := '';
2950: IF l_debug = 'Y' THEN
2951: fnd_file.put_line(
2952: fnd_file.log,
2953: 'Entering get_layers_consumed for transaction '||i_txn_id||
2954: ' and a required quantity of '||l_required_qty||
2955: ' with a consumption mode of '||consume_mode
2956: );
2961: Instead, we just need to get a reference cost from the earliest / latest layer */
2962:
2963: IF consume_mode = 'EXPSUB' THEN
2964: IF l_debug = 'Y' THEN
2965: fnd_file.put_line(fnd_file.log,'EXPSUB consumption');
2966: END IF;
2967: IF i_cost_method = 5 THEN
2968: l_stmt_num := 10;
2969: SELECT MIN(inv_layer_id)
3019:
3020: /* 1. Positive quantity in the layer specified by the layer hook */
3021: IF (l_custom_layer > 0) AND (l_required_qty > 0) THEN
3022: IF l_debug = 'Y' THEN
3023: fnd_file.put_line(fnd_file.log,'Trying custom layer '||l_custom_layer);
3024: END IF;
3025: l_stmt_num := 30;
3026: SELECT inv_layer_id, layer_quantity
3027: INTO l_inv_layer_rec.inv_layer_id,l_inv_layer_rec.layer_quantity
3032: IF l_required_qty < l_inv_layer_rec.layer_quantity THEN
3033: l_inv_layer_rec.layer_quantity := l_required_qty;
3034: END IF;
3035: IF l_debug = 'Y' THEN
3036: fnd_file.put_line(
3037: fnd_file.log,
3038: 'Using custom layer '||l_custom_layer||' for '||l_inv_layer_rec.layer_quantity
3039: );
3040: END IF;
3033: l_inv_layer_rec.layer_quantity := l_required_qty;
3034: END IF;
3035: IF l_debug = 'Y' THEN
3036: fnd_file.put_line(
3037: fnd_file.log,
3038: 'Using custom layer '||l_custom_layer||' for '||l_inv_layer_rec.layer_quantity
3039: );
3040: END IF;
3041: l_required_qty := l_required_qty - l_inv_layer_rec.layer_quantity;
3048: /* 2. Drive the layer specified by the layer hook negative only if there are no
3049: other positive layers */
3050: IF (l_custom_layer > 0) AND (l_required_qty > 0) THEN
3051: IF l_debug = 'Y' THEN
3052: fnd_file.put_line(fnd_file.log,'Driving custom layer '||l_custom_layer||' negative?');
3053: END IF;
3054: l_stmt_num := 40;
3055: SELECT count(*)
3056: INTO l_pos_layer_exist
3059: AND inv_layer_id <> l_custom_layer
3060: AND layer_quantity > 0;
3061: IF l_pos_layer_exist = 0 THEN
3062: IF l_debug = 'Y' THEN
3063: fnd_file.put_line(fnd_file.log,'Driving custom layer '||l_custom_layer||' negative');
3064: END IF;
3065: l_inv_layer_rec.inv_layer_id := l_custom_layer;
3066: l_inv_layer_rec.layer_quantity := l_required_qty;
3067: l_required_qty := 0;
3073:
3074: /* 3. Positive quantity from the layers specified in the layers hook in the order that they are specified */
3075: IF l_required_qty > 0 THEN
3076: IF l_debug = 'Y' THEN
3077: fnd_file.put_line(fnd_file.log,'Trying custom layers');
3078: END IF;
3079: l_stmt_num := 50;
3080: CSTPACHK.layers_hook (
3081: i_txn_id => i_txn_id,
3086: o_err_code => l_err_code,
3087: o_err_msg => l_err_msg
3088: );
3089: IF l_err_num <> 0 THEN
3090: fnd_file.put_line(fnd_file.log,'Error in calling CSTPACHK.layers_hook');
3091: RAISE process_error;
3092: END IF;
3093: l_layers_hook := 0;
3094: l_layers_list := '(-1';
3092: END IF;
3093: l_layers_hook := 0;
3094: l_layers_list := '(-1';
3095: IF l_debug = 'Y' THEN
3096: fnd_file.put_line(fnd_file.log,'There are '||l_custom_layers.COUNT||' custom layers');
3097: END IF;
3098: IF l_custom_layers.COUNT > 0 THEN
3099: FOR i IN l_custom_layers.FIRST..l_custom_layers.LAST LOOP
3100: EXIT WHEN l_required_qty = 0;
3098: IF l_custom_layers.COUNT > 0 THEN
3099: FOR i IN l_custom_layers.FIRST..l_custom_layers.LAST LOOP
3100: EXIT WHEN l_required_qty = 0;
3101: IF l_debug = 'Y' THEN
3102: fnd_file.put_line(
3103: fnd_file.log,
3104: 'Trying to consume '||l_custom_layers(i).layer_quantity||
3105: ' from custom layer '||l_custom_layers(i).inv_layer_id
3106: );
3099: FOR i IN l_custom_layers.FIRST..l_custom_layers.LAST LOOP
3100: EXIT WHEN l_required_qty = 0;
3101: IF l_debug = 'Y' THEN
3102: fnd_file.put_line(
3103: fnd_file.log,
3104: 'Trying to consume '||l_custom_layers(i).layer_quantity||
3105: ' from custom layer '||l_custom_layers(i).inv_layer_id
3106: );
3107: END IF;
3120: l_err_num := -1;
3121: l_err_msg := 'Custom layer '||l_custom_layers(i).inv_layer_id||
3122: ' and quantity '||l_custom_layers(i).layer_quantity||
3123: ' is not valid';
3124: fnd_file.put_line(
3125: fnd_file.log, l_err_msg
3126: );
3127: RAISE process_error;
3128: END;
3121: l_err_msg := 'Custom layer '||l_custom_layers(i).inv_layer_id||
3122: ' and quantity '||l_custom_layers(i).layer_quantity||
3123: ' is not valid';
3124: fnd_file.put_line(
3125: fnd_file.log, l_err_msg
3126: );
3127: RAISE process_error;
3128: END;
3129: -- ignore the layer if it has been specified by the layer hook to avoid double counting.
3133: END IF;
3134: l_required_qty := l_required_qty - l_inv_layer_rec.layer_quantity;
3135: l_stmt_num := 60;
3136: IF l_debug = 'Y' THEN
3137: fnd_file.put_line(
3138: fnd_file.log,
3139: 'Using custom layer '||l_custom_layers(i).inv_layer_id||
3140: ' for '||l_inv_layer_rec.layer_quantity
3141: );
3134: l_required_qty := l_required_qty - l_inv_layer_rec.layer_quantity;
3135: l_stmt_num := 60;
3136: IF l_debug = 'Y' THEN
3137: fnd_file.put_line(
3138: fnd_file.log,
3139: 'Using custom layer '||l_custom_layers(i).inv_layer_id||
3140: ' for '||l_inv_layer_rec.layer_quantity
3141: );
3142: END IF;
3153: /* 4. Positive quantity from the layer that was created for the delivery that this
3154: return / correction corresponds to */
3155: IF (consume_mode = 'SPECIFIC') AND (i_src_id IS NOT NULL) AND (l_required_qty > 0) then
3156: IF l_debug = 'Y' THEN
3157: fnd_file.put_line(fnd_file.log,'Trying original delivery');
3158: END IF;
3159: -- check if the current transaction is a return to receiving or correction
3160: l_stmt_num := 65;
3161: SELECT COUNT(*)
3179: AND mmt_rtr.transaction_id = i_txn_id;
3180: EXCEPTION
3181: WHEN OTHERS THEN
3182: IF (l_debug = 'Y') THEN
3183: FND_FILE.PUT_LINE(
3184: FND_FILE.LOG,
3185: 'No delivery is found for transaction ' || i_txn_id
3186: );
3187: END IF;
3180: EXCEPTION
3181: WHEN OTHERS THEN
3182: IF (l_debug = 'Y') THEN
3183: FND_FILE.PUT_LINE(
3184: FND_FILE.LOG,
3185: 'No delivery is found for transaction ' || i_txn_id
3186: );
3187: END IF;
3188: END;
3196: l_stmt_num := 80;
3197: sql_stmt := sql_stmt || ' AND inv_layer_id NOT IN '|| l_layers_list;
3198: END IF;
3199: IF l_debug = 'Y' THEN
3200: fnd_file.put_line(
3201: fnd_file.log,
3202: 'Using SQL '||sql_stmt||' with '||l_rtr_txn_id||','||l_custom_layer
3203: );
3204: END IF;
3197: sql_stmt := sql_stmt || ' AND inv_layer_id NOT IN '|| l_layers_list;
3198: END IF;
3199: IF l_debug = 'Y' THEN
3200: fnd_file.put_line(
3201: fnd_file.log,
3202: 'Using SQL '||sql_stmt||' with '||l_rtr_txn_id||','||l_custom_layer
3203: );
3204: END IF;
3205: OPEN inv_layer_cursor FOR sql_stmt USING l_rtr_txn_id, l_custom_layer;
3220: /* 5. Positive quantity from the layers that was created for the deliveries for
3221: the same PO or completions from the same job in FIFO/LIFO manner */
3222: IF (consume_mode = 'SPECIFIC') AND (i_src_id IS NOT NULL) AND (l_required_qty > 0) THEN
3223: IF l_debug = 'Y' THEN
3224: fnd_file.put_line(fnd_file.log,'Trying other layers with the same source');
3225: END IF;
3226: l_stmt_num := 90;
3227: sql_stmt := 'SELECT inv_layer_id,layer_quantity FROM cst_inv_layers'
3228: ||' WHERE layer_id = :i AND transaction_source_id = :j AND layer_quantity > 0 '
3238: l_stmt_num := 105;
3239: sql_stmt := sql_stmt || ' ORDER BY creation_date, inv_layer_id';
3240: END IF;
3241: IF l_debug = 'Y' THEN
3242: fnd_file.put_line(
3243: fnd_file.log,
3244: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_source_id||
3245: ','||l_rtr_txn_id||','||l_custom_layer
3246: );
3239: sql_stmt := sql_stmt || ' ORDER BY creation_date, inv_layer_id';
3240: END IF;
3241: IF l_debug = 'Y' THEN
3242: fnd_file.put_line(
3243: fnd_file.log,
3244: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_source_id||
3245: ','||l_rtr_txn_id||','||l_custom_layer
3246: );
3247: END IF;
3263: same PO or completions from the same job negative only if there are
3264: no other positive layers */
3265: IF (consume_mode = 'SPECIFIC') AND (i_src_id IS NOT NULL) AND (l_required_qty > 0) THEN
3266: IF l_debug = 'Y' THEN
3267: fnd_file.put_line(
3268: fnd_file.log,
3269: 'Driving earliest/latest layer with the same source negative?'
3270: );
3271: END IF;
3264: no other positive layers */
3265: IF (consume_mode = 'SPECIFIC') AND (i_src_id IS NOT NULL) AND (l_required_qty > 0) THEN
3266: IF l_debug = 'Y' THEN
3267: fnd_file.put_line(
3268: fnd_file.log,
3269: 'Driving earliest/latest layer with the same source negative?'
3270: );
3271: END IF;
3272: l_stmt_num := 115;
3278: l_stmt_num := 120;
3279: sql_stmt := sql_stmt || ' AND inv_layer_id NOT IN ' || l_layers_list;
3280: END IF;
3281: IF l_debug = 'Y' THEN
3282: fnd_file.put_line(
3283: fnd_file.log,
3284: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_custom_layer||
3285: ','||l_source_id
3286: );
3279: sql_stmt := sql_stmt || ' AND inv_layer_id NOT IN ' || l_layers_list;
3280: END IF;
3281: IF l_debug = 'Y' THEN
3282: fnd_file.put_line(
3283: fnd_file.log,
3284: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_custom_layer||
3285: ','||l_source_id
3286: );
3287: END IF;
3304: AND transaction_source_id = l_source_id;
3305: END IF;
3306: IF l_inv_layer_rec.inv_layer_id IS NOT NULL THEN
3307: IF l_debug = 'Y' THEN
3308: fnd_file.put_line(
3309: fnd_file.log,
3310: 'Driving earliest/latest layer with the same source negative'
3311: );
3312: END IF;
3305: END IF;
3306: IF l_inv_layer_rec.inv_layer_id IS NOT NULL THEN
3307: IF l_debug = 'Y' THEN
3308: fnd_file.put_line(
3309: fnd_file.log,
3310: 'Driving earliest/latest layer with the same source negative'
3311: );
3312: END IF;
3313: l_inv_layer_rec.layer_quantity := l_required_qty;
3322:
3323: /* 7. Positive quantity from all layers in FIFO/LIFO manner */
3324: IF l_required_qty > 0 THEN
3325: IF l_debug = 'Y' THEN
3326: fnd_file.put_line(fnd_file.log,'General consumption');
3327: END IF;
3328: l_stmt_num := 140;
3329: sql_stmt := 'SELECT inv_layer_id,layer_quantity FROM cst_inv_layers WHERE layer_id = :i'
3330: ||' AND inv_layer_id <> :j AND NVL(transaction_source_id,-2) <> :k'
3340: l_stmt_num := 155;
3341: sql_stmt := sql_stmt || ' ORDER BY creation_date, inv_layer_id';
3342: END IF;
3343: IF l_debug = 'Y' THEN
3344: fnd_file.put_line(
3345: fnd_file.log,
3346: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_custom_layer||
3347: ','||l_source_id
3348: );
3341: sql_stmt := sql_stmt || ' ORDER BY creation_date, inv_layer_id';
3342: END IF;
3343: IF l_debug = 'Y' THEN
3344: fnd_file.put_line(
3345: fnd_file.log,
3346: 'Using SQL '||sql_stmt||' with '||i_layer_id||','||l_custom_layer||
3347: ','||l_source_id
3348: );
3349: END IF;
3363:
3364: /* 8. Drive the overall earliest / latest layer negative */
3365: IF l_required_qty > 0 THEN
3366: IF l_debug = 'Y' THEN
3367: fnd_file.put_line(fnd_file.log,'Driving earliest/latest layer negative');
3368: END IF;
3369: IF l_debug = 'Y' THEN
3370: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_neg_qty ' || to_char(l_required_qty));
3371: END IF;
3366: IF l_debug = 'Y' THEN
3367: fnd_file.put_line(fnd_file.log,'Driving earliest/latest layer negative');
3368: END IF;
3369: IF l_debug = 'Y' THEN
3370: FND_FILE.PUT_LINE(FND_FILE.LOG,'l_neg_qty ' || to_char(l_required_qty));
3371: END IF;
3372: l_stmt_num := 165;
3373: sql_stmt := 'SELECT inv_layer_id,layer_quantity FROM cst_inv_layers WHERE layer_id = :i';
3374: IF i_cost_method = 5 THEN
3376: ELSE
3377: sql_stmt := sql_stmt || ' ORDER BY creation_date,inv_layer_id';
3378: END IF;
3379: IF l_debug = 'Y' THEN
3380: fnd_file.put_line(fnd_file.log,'Using SQL '||sql_stmt||' with '||i_layer_id);
3381: END IF;
3382: OPEN inv_layer_cursor FOR sql_stmt USING i_layer_id;
3383: FETCH inv_layer_cursor into l_inv_layer_rec.inv_layer_id,l_inv_layer_rec.layer_quantity;
3384: l_inv_layer_rec.layer_quantity := l_required_qty;
3394: o_err_code := l_err_code;
3395: o_err_msg := l_err_msg;
3396: when others then
3397: rollback;
3398: FND_FILE.PUT_LINE(FND_FILE.LOG,SQLCODE ||' ' ||to_char(l_stmt_num)||' '||substr(SQLERRM,1,200));
3399: o_err_num := SQLCODE;
3400: o_err_msg := 'CSTPLENG.get_layers_consumed (' || to_char(l_stmt_num) || '): ' || substr(SQLERRM,1,200);
3401: END get_layers_consumed;
3402:
3618: -- Find out if there are any material overhead rows for the layer
3619: -- which have actual cost value.
3620:
3621: if(l_debug = 'Y') then
3622: fnd_file.put_line(fnd_file.log, 'In apply_layer_material_ovhd!!!!');
3623: end if;
3624:
3625: l_stmt_num := 10;
3626: /* Changes for MOH Absorption Rules */
3645: RAISE moh_rules_error;
3646: END IF;
3647:
3648: IF(l_earn_moh = 0) THEN
3649: fnd_file.put_line(fnd_file.log, '--Material Overhead Absorption Overidden--'); ELSE
3650:
3651: l_stmt_num := 11;
3652:
3653: select count(*)
3773:
3774: l_stmt_num := 35;
3775:
3776: if(l_debug = 'Y') then
3777: fnd_file.put_line(fnd_file.log, 'Inserting into MACS');
3778: end if;
3779:
3780: Insert into mtl_actual_cost_subelement(
3781: transaction_id,
3886:
3887:
3888: l_stmt_num := 55;
3889: if(l_debug = 'Y') then
3890: fnd_file.put_line(fnd_file.log, 'Inserting into MACS');
3891: end if;
3892:
3893: Insert into mtl_actual_cost_subelement(
3894: transaction_id,
3946: and cost_element_id = 2
3947: and level_type = decode(i_level, 1,1,level_type);
3948:
3949: if l_debug = 'Y' then
3950: FND_FILE.PUT_LINE(FND_FILE.LOG, 'movh.l_mat_ovhds = '
3951: || to_char(l_mat_ovhds)
3952: || ' , stmt '
3953: || to_char(l_stmt_num));
3954: end if;
3966: and cost_element_id = 2
3967: and level_type = decode(i_level,1,1,level_type);
3968:
3969: if l_debug = 'Y' then
3970: FND_FILE.PUT_LINE(FND_FILE.LOG, 'movh.mclacd_ovhd = '
3971: || to_char(l_mclacd_ovhd)
3972: || ' , stmt '
3973: || to_char(l_stmt_num));
3974: end if;
3990: and layer_id = i_layer_id
3991: and cost_element_id = 2;
3992:
3993: if l_debug = 'Y' then
3994: FND_FILE.PUT_LINE(FND_FILE.LOG, 'movh.l_ovhd_cost = '
3995: || to_char(l_ovhd_cost)
3996: || ' ,stmt '
3997: || to_char(l_stmt_num));
3998: end if;
4045: and mclacd.cost_element_id = 2;
4046: end if;
4047:
4048: if l_debug = 'Y' then
4049: FND_FILE.PUT_LINE(FND_FILE.LOG, 'movh.updating mclacd...l_ovhd_cost = '
4050: || to_char(l_ovhd_cost)
4051: || ' , stmt '
4052: || to_char(l_stmt_num));
4053: end if;
4102: i_prg_id,
4103: sysdate);
4104:
4105: if l_debug = 'Y' then
4106: FND_FILE.PUT_LINE(FND_FILE.LOG, 'movh.insertign mclacd...l_ovhd_cost = '
4107: || to_char(l_ovhd_cost)
4108: || ',txn_lyr = '
4109: || to_char(i_layer_qty)
4110: || ' , stmt '
4240: where transaction_id = i_txn_id
4241: and organization_id = i_org_id;
4242:
4243: if (l_count = 0) then
4244: FND_FILE.PUT_LINE(FND_FILE.LOG, 'No records in MCLACD');
4245: end if;
4246:
4247: /* Insert MCACD (by summing up MCLACD) only if it's not a scrap txn.
4248: Beware: there will be time where MCACD exists, such as when cost hook is used.
4860: raise no_mctcd_error;
4861: end if;
4862: */
4863: if l_mctcd_exist = 0 then
4864: FND_FILE.PUT_LINE(FND_FILE.LOG,'No mctcd rows');
4865: end if;
4866:
4867: l_stmt_num := 10;
4868:
5089: from cst_inv_layers cil
5090: where cil.layer_id = i_layer_id
5091: and cil.inv_layer_id = l_inv_layer_id;
5092:
5093: FND_FILE.PUT_LINE(FND_FILE.LOG, 'layer qty = ' || to_char(l_layer_qty));
5094: l_stmt_num := 70;
5095:
5096: CSTPLENG.calc_layer_average_cost(
5097: i_org_id,