[Home] [Help]
PACKAGE BODY: APPS.WMS_CARTNZN_PUB
Source
1 PACKAGE BODY WMS_CARTNZN_PUB AS
2 /* $Header: WMSCRTNB.pls 120.15.12010000.2 2008/08/19 09:53:37 anviswan ship $*/
3 --
4 -- File : WMSCRTNB.pls
5 -- Content : WMS_CARTNZN_PUB package specification
6 -- Description : WMS cartonization API
7 -- Notes :
8 -- Modified : 09/12/2000 cjandhya created
9
10
11 -- API name : cartonize
12 -- Type : group
13 -- Function : populates the cartonization_id, container_item_id columns,
14 -- of rows belonging to a particular move order header id in
15 -- mtl_material_transactions_temp.
16
17 -- Pre-reqs : Those columns wouldn't be populated if the cartonization_id
18 -- for that row is already populated,
19 -- or if values for organization_id, inventory_item_id ,
20 -- primary qunatity, transaction_quantity, transaction_uom,
21 -- trans action_temp_id are not all filled or if there is no
22 -- conversion defined between primary and transaction uoms of
23 -- the item of interest. each item has to be assigned to a
24 -- category of contained_item category set and that category
25 -- should have some container items.
26 -- The lines that can be packed together are identified by the
27 -- carton_grouping_id(MTL_TXN_REQEST_LINES) for the
28 -- move_order_line_id of that line.
29
30
31 -- Parameters :
32 -- p_api_version Standard Input Parameter
33 -- p_init_msg_list Standard Input Parameter
34 -- p_commit Standard Input Parameter
35 -- p_validation_level Standard Input Parameter
36 -- p_out_bound specifies if the call is for outbound process
37 -- p_org_id organization_id
38 -- p_move_order_header_id header_id for the lines to be cartonized
39
40
41 -- Output Parameters
42 -- x_return_status Standard Output Parameter
43 -- x_msg_count Standard Output Parameter
44 -- x_msg_data Standard Output Parameter
45
46 -- Version
47 -- Currently version is 1.0
48
49 PROCEDURE insert_ph (
50 p_move_order_header_id IN NUMBER,
51 p_current_header_id IN NUMBER,
52 x_return_status OUT NOCOPY NUMBER
53 );
54
55 PROCEDURE cartonize_pick_slip (
56 p_org_id IN NUMBER,
57 p_move_order_header_id IN NUMBER,
58 p_subinventory_name IN VARCHAR2,
59 x_return_status OUT NOCOPY VARCHAR2
60 );
61
62 PROCEDURE cartonize_customer_logic (
63 p_org_id IN NUMBER,
64 p_move_order_header_id IN NUMBER,
65 p_subinventory_name IN VARCHAR2,
66 x_return_status OUT NOCOPY VARCHAR2
67 );
68
69 PROCEDURE cartonize_default_logic (
70 p_org_id IN NUMBER,
71 p_move_order_header_id IN NUMBER,
72 p_out_bound IN VARCHAR2,
73 x_return_status OUT NOCOPY VARCHAR2,
74 x_msg_count OUT NOCOPY NUMBER,
75 x_msg_data OUT NOCOPY VARCHAR2
76 );
77
78 PROCEDURE cartonize_single_item (
79 x_return_status OUT NOCOPY VARCHAR2,
80 x_msg_count OUT NOCOPY NUMBER,
81 x_msg_data OUT NOCOPY VARCHAR2,
82 p_out_bound IN VARCHAR2,
83 p_org_id IN NUMBER,
84 p_move_order_header_id IN NUMBER,
85 p_subinventory_name IN VARCHAR2 DEFAULT NULL
86 );
87
88 PROCEDURE cartonize_mixed_item (
89 x_return_status OUT NOCOPY VARCHAR2,
90 x_msg_count OUT NOCOPY NUMBER,
91 x_msg_data OUT NOCOPY VARCHAR2,
92 p_out_bound IN VARCHAR2,
93 p_org_id IN NUMBER,
94 p_move_order_header_id IN NUMBER,
95 p_transaction_header_id IN NUMBER,
96 p_disable_cartonization IN VARCHAR2 DEFAULT 'N',
97 p_subinventory_name IN VARCHAR2 DEFAULT NULL,
98 p_stop_level IN NUMBER DEFAULT NULL,
99 p_pack_level IN NUMBER
100 );
101
102 PROCEDURE rulebased_cartonization(
103 x_return_status OUT NOCOPY VARCHAR2,
104 x_msg_count OUT NOCOPY NUMBER,
105 x_msg_data OUT NOCOPY VARCHAR2,
106 p_out_bound IN VARCHAR2,
107 p_org_id IN NUMBER,
108 p_move_order_header_id IN NUMBER,
109 p_input_for_bulk IN WMS_BULK_PICK.bulk_input_rec DEFAULT null
110 );
111
112
113 G_PKG_NAME CONSTANT VARCHAR2(30) := 'WMS_CARTNZN_PUB';
114 g_current_release_level CONSTANT NUMBER := WMS_CONTROL.G_CURRENT_RELEASE_LEVEL;
115 g_j_release_level CONSTANT NUMBER := INV_RELEASE.G_J_RELEASE_LEVEL;
116 g_k_release_level CONSTANT NUMBER := INV_RELEASE.G_K_RELEASE_LEVEL; -- ER : 6682436
117 g_move_order_pick_wave CONSTANT NUMBER := inv_globals.g_move_order_pick_wave;
118 g_cartonize_pick_slip VARCHAR2(1) := 'N';
119
120 -- Sets the table on which we want to perform the operations insert,
121 -- delete, update etc
122
123 TABLE_NAME VARCHAR2(200) := 'mtl_material_transactions_temp';
124
125 -- mode in which cartonization is called, values 'Y' or 'N'
126
127 OUTBOUND VARCHAR2(1) := 'N';
128 CURR_HEADER_ID_FOR_MIXED NUMBER;
129 PREV_HEADER_ID_FOR_MIXED NUMBER;
130
131 -- variable used to store the error code, pushed into stack on error
132 ERROR_CODE VARCHAR2(30) := NULL;
133 ERROR_MSG VARCHAR2(255) := NULL;
134
135
136 -- Record type used to store the original and the transaction_temp_id
137 -- split from it
138
139 TYPE t_temp_id_rel_rec IS RECORD
140 (
141 orig_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE ,
142 splt_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE,
143 primary_quantity NUMBER,
144 secondary_quantity NUMBER,
145 processed VARCHAR2(1) := 'N');
146
147
148 TYPE t_temp_id_rel_tb IS TABLE OF t_temp_id_rel_rec INDEX BY BINARY_INTEGER;
149
150 -- TABLE used to store the original and the transaction_temp_id
151 -- split from it
152
153 TEMP_ID_TABLE t_temp_id_rel_tb;
154
155 TEMP_ID_TABLE_INDEX NUMBER := 0;
156
157 --Variable storing if log is enabled
158 g_trace_on NUMBER := NULL;
159
160 --for device integration
161 SUBTYPE WDR_ROW IS WMS_DEVICE_REQUESTS%ROWTYPE;
162
163 SUBTYPE MMTT_ROW_TYPE IS MTL_MATERIAL_TRANSACTIONS_TEMP%ROWTYPE;
164
165 SUBTYPE WCT_ROW_TYPE IS WMS_CARTONIZATION_TEMP%ROWTYPE;
166
167 TYPE lpn_alloc_flag_rec IS RECORD
168 ( transaction_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE ,
169 lpn_alloc_flag VARCHAR2(1)
170 );
171
172 TYPE lpn_alloc_flag_tb IS TABLE OF lpn_alloc_flag_rec INDEX BY BINARY_INTEGER;
173
174 -- TABLE used to store whether transaction_temp_id is fully allocated
175 -- partially allocated, or not allocated
176
177 t_lpn_alloc_flag_table lpn_alloc_flag_tb;
178
179
180 -- Table that needs to be passed inv_rcv_common_apis for splitting
181 -- mtl_transaction_lots_temp and mtl_serial_numbers_temp
182
183 api_table inv_rcv_common_apis.trans_rec_tb_tp;
184
185 -- This value is incremented and inserted into sequence_id of the table
186 -- wms_packaging_hist on every insert
187 --sequence_id NUMBER := 1;
188
189 -- Keeps track of what level we are currently cartonizing
190 pack_level NUMBER := 0;
191
192
193 dummy_header_id NUMBER := -1;
194 dummy_temp_id NUMBER := -1;
195
196 -- Mode in which cartonization is called
197 packaging_mode NUMBER := 1;
198
199 -- caching items associated with LPNs and packages
200 cache_package_id NUMBER := -1;
201 cache_pkg_item_id NUMBER := NULL;
202
203 cache_lpn_id NUMBER := -1;
204 cache_lpn_item_id NUMBER := NULL;
205
206 --Bug 3528061 fix
207 --Variable storing the allocate_serials_flag for the organization
208 g_allocate_serial_flag VARCHAR2(1) := NULL;
209
210 --Bug#7168367.This will hold if cartonization is enabled at sublevel or not
211 -- 1 - At org level
212 -- 3 - At sublevel
213 g_sublvlctrl VARCHAR2(1) := '2';
214
215 TYPE attr_rec IS RECORD
216 ( inventory_item_id NUMBER,
217 gross_weight NUMBER,
218 content_volume NUMBER,
219 gross_weight_uom_code VARCHAR2(3),
220 content_volume_uom_code VARCHAR2(3),
221 tare_weight NUMBER,
222 tare_weight_uom_code VARCHAR2(3)
223 );
224
225 TYPE attr_tb IS TABLE OF attr_rec INDEX BY BINARY_INTEGER;
226
227 lpn_attr_table attr_tb;
228 pkg_attr_table attr_tb;
229
230 --Bug 2520774 fix
231 l_auto_pick_confirm_flag VARCHAR2(1) := 'N';
232
233
234 FUNCTION to_mmtt(wct_rec wct_row_type) RETURN mmtt_row_type
235 IS
236 mmt_rec mmtt_row_type;
237 BEGIN
238
239 mmt_rec.transaction_header_id:=wct_rec.transaction_header_id;
240 mmt_rec.transaction_temp_id:=wct_rec.transaction_temp_id;
241 mmt_rec.source_code:=wct_rec.source_code;
242 mmt_rec.source_line_id:=wct_rec.source_line_id;
243 mmt_rec.transaction_mode:=wct_rec.transaction_mode;
244 mmt_rec.lock_flag:=wct_rec.lock_flag;
245 mmt_rec.last_update_date:=wct_rec.last_update_date;
246 mmt_rec.last_updated_by:=wct_rec.last_updated_by;
247 mmt_rec.creation_date:=wct_rec.creation_date;
248 mmt_rec.created_by:=wct_rec.created_by;
249 mmt_rec.last_update_login:=wct_rec.last_update_login;
250 mmt_rec.request_id:=wct_rec.request_id;
251 mmt_rec.program_application_id:=wct_rec.program_application_id;
252 mmt_rec.program_id:=wct_rec.program_id;
253 mmt_rec.program_update_date:=wct_rec.program_update_date;
254 mmt_rec.inventory_item_id:=wct_rec.inventory_item_id;
255 mmt_rec.revision:=wct_rec.revision;
256 mmt_rec.organization_id:=wct_rec.organization_id;
257 mmt_rec.subinventory_code:=wct_rec.subinventory_code;
258 mmt_rec.locator_id:=wct_rec.locator_id;
259 mmt_rec.transaction_quantity:=wct_rec.transaction_quantity;
260 mmt_rec.primary_quantity:=wct_rec.primary_quantity;
261 mmt_rec.transaction_uom:=wct_rec.transaction_uom;
262 mmt_rec.transaction_cost:=wct_rec.transaction_cost;
263 mmt_rec.transaction_type_id:=wct_rec.transaction_type_id;
264 mmt_rec.transaction_action_id:=wct_rec.transaction_action_id;
265 mmt_rec.transaction_source_type_id:=wct_rec.transaction_source_type_id;
266 mmt_rec.transaction_source_id:=wct_rec.transaction_source_id;
267 mmt_rec.transaction_source_name:=wct_rec.transaction_source_name;
268 mmt_rec.transaction_date:=wct_rec.transaction_date;
269 mmt_rec.acct_period_id:=wct_rec.acct_period_id;
270 mmt_rec.distribution_account_id:=wct_rec.distribution_account_id;
271 mmt_rec.transaction_reference:=wct_rec.transaction_reference;
272 mmt_rec.requisition_line_id:=wct_rec.requisition_line_id;
273 mmt_rec.requisition_distribution_id:=wct_rec.requisition_distribution_id;
274 mmt_rec.reason_id:=wct_rec.reason_id;
275 mmt_rec.lot_number:=wct_rec.lot_number;
276 mmt_rec.lot_expiration_date:=wct_rec.lot_expiration_date;
277 mmt_rec.serial_number:=wct_rec.serial_number;
278 mmt_rec.receiving_document:=wct_rec.receiving_document;
279 mmt_rec.demand_id:=wct_rec.demand_id;
280 mmt_rec.rcv_transaction_id:=wct_rec.rcv_transaction_id;
281 mmt_rec.move_transaction_id:=wct_rec.move_transaction_id;
282 mmt_rec.completion_transaction_id:=wct_rec.completion_transaction_id;
283 mmt_rec.wip_entity_type:=wct_rec.wip_entity_type;
284 mmt_rec.schedule_id:=wct_rec.schedule_id;
285 mmt_rec.repetitive_line_id:=wct_rec.repetitive_line_id;
286 mmt_rec.employee_code:=wct_rec.employee_code;
287 mmt_rec.primary_switch:=wct_rec.primary_switch;
288 mmt_rec.schedule_update_code:=wct_rec.schedule_update_code;
289 mmt_rec.setup_teardown_code:=wct_rec.setup_teardown_code;
290 mmt_rec.item_ordering:=wct_rec.item_ordering;
291 mmt_rec.negative_req_flag:=wct_rec.negative_req_flag;
292 mmt_rec.operation_seq_num:=wct_rec.operation_seq_num;
293 mmt_rec.picking_line_id:=wct_rec.picking_line_id;
294 mmt_rec.trx_source_line_id:=wct_rec.trx_source_line_id;
295 mmt_rec.trx_source_delivery_id:=wct_rec.trx_source_delivery_id;
296 mmt_rec.physical_adjustment_id:=wct_rec.physical_adjustment_id;
297 mmt_rec.cycle_count_id:=wct_rec.cycle_count_id;
298 mmt_rec.rma_line_id:=wct_rec.rma_line_id;
299 mmt_rec.customer_ship_id:=wct_rec.customer_ship_id;
300 mmt_rec.currency_code:=wct_rec.currency_code;
301 mmt_rec.currency_conversion_rate:=wct_rec.currency_conversion_rate;
302 mmt_rec.currency_conversion_type:=wct_rec.currency_conversion_type;
303 mmt_rec.currency_conversion_date:=wct_rec.currency_conversion_date;
304 mmt_rec.ussgl_transaction_code:=wct_rec.ussgl_transaction_code;
305 mmt_rec.vendor_lot_number:=wct_rec.vendor_lot_number;
306 mmt_rec.encumbrance_account:=wct_rec.encumbrance_account;
307 mmt_rec.encumbrance_amount:=wct_rec.encumbrance_amount;
308 mmt_rec.ship_to_location:=wct_rec.ship_to_location;
309 mmt_rec.shipment_number:=wct_rec.shipment_number;
310 mmt_rec.transfer_cost:=wct_rec.transfer_cost;
311 mmt_rec.transportation_cost:=wct_rec.transportation_cost;
312 mmt_rec.transportation_account:=wct_rec.transportation_account;
313 mmt_rec.freight_code:=wct_rec.freight_code;
314 mmt_rec.containers:=wct_rec.containers;
315 mmt_rec.waybill_airbill:=wct_rec.waybill_airbill;
316 mmt_rec.expected_arrival_date:=wct_rec.expected_arrival_date;
317 mmt_rec.transfer_subinventory:=wct_rec.transfer_subinventory;
318 mmt_rec.transfer_organization:=wct_rec.transfer_organization;
319 mmt_rec.transfer_to_location:=wct_rec.transfer_to_location;
320 mmt_rec.new_average_cost:=wct_rec.new_average_cost;
321 mmt_rec.value_change:=wct_rec.value_change;
322 mmt_rec.percentage_change:=wct_rec.percentage_change;
323 mmt_rec.material_allocation_temp_id:=wct_rec.material_allocation_temp_id;
324 mmt_rec.demand_source_header_id:=wct_rec.demand_source_header_id;
325 mmt_rec.demand_source_line:=wct_rec.demand_source_line;
326 mmt_rec.demand_source_delivery:=wct_rec.demand_source_delivery;
327 mmt_rec.item_segments:=wct_rec.item_segments;
328 mmt_rec.item_description:=wct_rec.item_description;
329 mmt_rec.item_trx_enabled_flag:=wct_rec.item_trx_enabled_flag;
330 mmt_rec.item_location_control_code:=wct_rec.item_location_control_code;
331 mmt_rec.item_restrict_subinv_code:=wct_rec.item_restrict_subinv_code;
332 mmt_rec.item_restrict_locators_code:=wct_rec.item_restrict_locators_code;
333 mmt_rec.item_revision_qty_control_code:=wct_rec.item_revision_qty_control_code;
334 mmt_rec.item_primary_uom_code:=wct_rec.item_primary_uom_code;
335 mmt_rec.item_uom_class:=wct_rec.item_uom_class;
336 mmt_rec.item_shelf_life_code:=wct_rec.item_shelf_life_code;
337 mmt_rec.item_shelf_life_days:=wct_rec.item_shelf_life_days;
338 mmt_rec.item_lot_control_code:=wct_rec.item_lot_control_code;
339 mmt_rec.item_serial_control_code:=wct_rec.item_serial_control_code;
343 mmt_rec.department_code:=wct_rec.department_code;
340 mmt_rec.item_inventory_asset_flag:=wct_rec.item_inventory_asset_flag;
341 mmt_rec.allowed_units_lookup_code:=wct_rec.allowed_units_lookup_code;
342 mmt_rec.department_id:=wct_rec.department_id;
344 mmt_rec.wip_supply_type:=wct_rec.wip_supply_type;
345 mmt_rec.supply_subinventory:=wct_rec.supply_subinventory;
346 mmt_rec.supply_locator_id:=wct_rec.supply_locator_id;
347 mmt_rec.valid_subinventory_flag:=wct_rec.valid_subinventory_flag;
348 mmt_rec.valid_locator_flag:=wct_rec.valid_locator_flag;
349 mmt_rec.locator_segments:=wct_rec.locator_segments;
350 mmt_rec.current_locator_control_code:=wct_rec.current_locator_control_code;
351 mmt_rec.number_of_lots_entered:=wct_rec.number_of_lots_entered;
352 mmt_rec.wip_commit_flag:=wct_rec.wip_commit_flag;
353 mmt_rec.next_lot_number:=wct_rec.next_lot_number;
354 mmt_rec.lot_alpha_prefix:=wct_rec.lot_alpha_prefix;
355 mmt_rec.next_serial_number:=wct_rec.next_serial_number;
356 mmt_rec.serial_alpha_prefix:=wct_rec.serial_alpha_prefix;
357 mmt_rec.shippable_flag:=wct_rec.shippable_flag;
358 mmt_rec.posting_flag:=wct_rec.posting_flag;
359 mmt_rec.required_flag:=wct_rec.required_flag;
360 mmt_rec.process_flag:=wct_rec.process_flag;
361 mmt_rec.error_code:=wct_rec.error_code;
362 mmt_rec.error_explanation:=wct_rec.error_explanation;
363 mmt_rec.attribute_category:=wct_rec.attribute_category;
364 mmt_rec.attribute1:=wct_rec.attribute1;
365 mmt_rec.attribute2:=wct_rec.attribute2;
366 mmt_rec.attribute3:=wct_rec.attribute3;
367 mmt_rec.attribute4:=wct_rec.attribute4;
368 mmt_rec.attribute5:=wct_rec.attribute5;
369 mmt_rec.attribute6:=wct_rec.attribute6;
370 mmt_rec.attribute7:=wct_rec.attribute7;
371 mmt_rec.attribute8:=wct_rec.attribute8;
372 mmt_rec.attribute9:=wct_rec.attribute9;
373 mmt_rec.attribute10:=wct_rec.attribute10;
374 mmt_rec.attribute11:=wct_rec.attribute11;
375 mmt_rec.attribute12:=wct_rec.attribute12;
376 mmt_rec.attribute13:=wct_rec.attribute13;
377 mmt_rec.attribute14:=wct_rec.attribute14;
378 mmt_rec.attribute15:=wct_rec.attribute15;
379 mmt_rec.movement_id:=wct_rec.movement_id;
380 mmt_rec.reservation_quantity:=wct_rec.reservation_quantity;
381 mmt_rec.shipped_quantity:=wct_rec.shipped_quantity;
382 mmt_rec.transaction_line_number:=wct_rec.transaction_line_number;
383 mmt_rec.task_id:=wct_rec.task_id;
384 mmt_rec.to_task_id:=wct_rec.to_task_id;
385 mmt_rec.source_task_id:=wct_rec.source_task_id;
386 mmt_rec.project_id:=wct_rec.project_id;
387 mmt_rec.source_project_id:=wct_rec.source_project_id;
388 mmt_rec.pa_expenditure_org_id:=wct_rec.pa_expenditure_org_id;
389 mmt_rec.to_project_id:=wct_rec.to_project_id;
390 mmt_rec.expenditure_type:=wct_rec.expenditure_type;
391 mmt_rec.final_completion_flag:=wct_rec.final_completion_flag;
392 mmt_rec.transfer_percentage:=wct_rec.transfer_percentage;
393 mmt_rec.transaction_sequence_id:=wct_rec.transaction_sequence_id;
394 mmt_rec.material_account:=wct_rec.material_account;
395 mmt_rec.material_overhead_account:=wct_rec.material_overhead_account;
396 mmt_rec.resource_account:=wct_rec.resource_account;
397 mmt_rec.outside_processing_account:=wct_rec.outside_processing_account;
398 mmt_rec.overhead_account:=wct_rec.overhead_account;
399 mmt_rec.flow_schedule:=wct_rec.flow_schedule;
400 mmt_rec.cost_group_id:=wct_rec.cost_group_id;
401 mmt_rec.demand_class:=wct_rec.demand_class;
402 mmt_rec.qa_collection_id:=wct_rec.qa_collection_id;
403 mmt_rec.kanban_card_id:=wct_rec.kanban_card_id;
404 mmt_rec.overcompletion_transaction_qty:=wct_rec.overcompletion_transaction_qty;
405 mmt_rec.overcompletion_primary_qty:=wct_rec.overcompletion_primary_qty;
406 mmt_rec.overcompletion_transaction_id:=wct_rec.overcompletion_transaction_id;
407 mmt_rec.end_item_unit_number:=wct_rec.end_item_unit_number;
408 mmt_rec.scheduled_payback_date:=wct_rec.scheduled_payback_date;
409 mmt_rec.line_type_code:=wct_rec.line_type_code;
410 mmt_rec.parent_transaction_temp_id:=wct_rec.parent_transaction_temp_id;
411 mmt_rec.put_away_strategy_id:=wct_rec.put_away_strategy_id;
412 mmt_rec.put_away_rule_id:=wct_rec.put_away_rule_id;
413 mmt_rec.pick_strategy_id:=wct_rec.pick_strategy_id;
414 mmt_rec.pick_rule_id:=wct_rec.pick_rule_id;
415 mmt_rec.move_order_line_id:=wct_rec.move_order_line_id;
416 mmt_rec.task_group_id:=wct_rec.task_group_id;
417 mmt_rec.pick_slip_number:=wct_rec.pick_slip_number;
418 mmt_rec.reservation_id:=wct_rec.reservation_id;
419 mmt_rec.common_bom_seq_id:=wct_rec.common_bom_seq_id;
420 mmt_rec.common_routing_seq_id:=wct_rec.common_routing_seq_id;
421 mmt_rec.org_cost_group_id:=wct_rec.org_cost_group_id;
422 mmt_rec.cost_type_id:=wct_rec.cost_type_id;
423 mmt_rec.transaction_status:=wct_rec.transaction_status;
424 mmt_rec.standard_operation_id:=wct_rec.standard_operation_id;
425 mmt_rec.task_priority:=wct_rec.task_priority;
426 mmt_rec.wms_task_type:=wct_rec.wms_task_type;
427 mmt_rec.parent_line_id:=wct_rec.parent_line_id;
428 mmt_rec.transfer_cost_group_id:=wct_rec.transfer_cost_group_id;
429 mmt_rec.lpn_id:=wct_rec.lpn_id;
430 mmt_rec.transfer_lpn_id:=wct_rec.transfer_lpn_id;
431 mmt_rec.wms_task_status:=wct_rec.wms_task_status;
432 mmt_rec.content_lpn_id:=wct_rec.content_lpn_id;
433 mmt_rec.container_item_id:=wct_rec.container_item_id;
434 mmt_rec.cartonization_id:=wct_rec.cartonization_id;
435 mmt_rec.pick_slip_date:=wct_rec.pick_slip_date;
439 mmt_rec.rebuild_job_name:=wct_rec.rebuild_job_name;
436 mmt_rec.rebuild_item_id:=wct_rec.rebuild_item_id;
437 mmt_rec.rebuild_serial_number:=wct_rec.rebuild_serial_number;
438 mmt_rec.rebuild_activity_id:=wct_rec.rebuild_activity_id;
440 mmt_rec.organization_type:=wct_rec.organization_type;
441 mmt_rec.transfer_organization_type:=wct_rec.transfer_organization_type;
442 mmt_rec.owning_organization_id:=wct_rec.owning_organization_id;
443 mmt_rec.owning_tp_type:=wct_rec.owning_tp_type;
444 mmt_rec.xfr_owning_organization_id:=wct_rec.xfr_owning_organization_id;
445 mmt_rec.transfer_owning_tp_type:=wct_rec.transfer_owning_tp_type;
446 mmt_rec.planning_organization_id:=wct_rec.planning_organization_id;
447 mmt_rec.planning_tp_type:=wct_rec.planning_tp_type;
448 mmt_rec.xfr_planning_organization_id:=wct_rec.xfr_planning_organization_id;
449 mmt_rec.transfer_planning_tp_type:=wct_rec.transfer_planning_tp_type;
450 mmt_rec.secondary_uom_code:=wct_rec.secondary_uom_code;
451 mmt_rec.secondary_transaction_quantity:=wct_rec.secondary_transaction_quantity;
452 mmt_rec.transaction_batch_id:=wct_rec.transaction_batch_id;
453 mmt_rec.transaction_batch_seq:=wct_rec.transaction_batch_seq;
454 mmt_rec.allocated_lpn_id:=wct_rec.allocated_lpn_id;
455 mmt_rec.schedule_number:=wct_rec.schedule_number;
456 mmt_rec.scheduled_flag:=wct_rec.scheduled_flag;
457 mmt_rec.class_code:=wct_rec.class_code;
458 mmt_rec.schedule_group:=wct_rec.schedule_group;
459 mmt_rec.build_sequence:=wct_rec.build_sequence;
460 mmt_rec.bom_revision:=wct_rec.bom_revision;
461 mmt_rec.routing_revision:=wct_rec.routing_revision;
462 mmt_rec.bom_revision_date:=wct_rec.bom_revision_date;
463 mmt_rec.routing_revision_date:=wct_rec.routing_revision_date;
464 mmt_rec.alternate_bom_designator:=wct_rec.alternate_bom_designator;
465 mmt_rec.alternate_routing_designator:=wct_rec.alternate_routing_designator;
466 mmt_rec.operation_plan_id:=wct_rec.operation_plan_id;
467 mmt_rec.move_order_header_id:=wct_rec.move_order_header_id;
468 mmt_rec.serial_allocated_flag:=wct_rec.serial_allocated_flag;
469
470 RETURN mmt_rec;
471
472 END;
473
474
475 PROCEDURE create_wct(p_move_order_header_id IN NUMBER,
476 p_transaction_header_id IN NUMBER,
477 p_input_for_bulk IN WMS_BULK_PICK.BULK_INPUT_REC := null)
478 IS
479
480 mmtt_rec MMTT_ROW_TYPE;
481
482 CURSOR c1(mo_hdr_id NUMBER) IS
483 /* added the index hint with the suggestion of apps performance team */
484 SELECT /*+index (mmtt,mtl_material_trans_temp_n14)*/ mmtt.* FROM
485 mtl_material_transactions_temp mmtt, mtl_txn_request_lines
486 mtrl WHERE mtrl.header_id = mo_hdr_id AND
487 mmtt.move_order_line_id = mtrl.line_id AND
488 --2513907 fix
489 mmtt.container_item_id IS null;
490
491 CURSOR c2(txn_hdr_id NUMBER) IS
492 SELECT mmtt.* FROM
493 mtl_material_transactions_temp mmtt
494 WHERE
495 mmtt.transaction_header_id = txn_hdr_id;
496
497 -- following cursors added for patchset J bulk picking ---------------
498
499 CURSOR c11_bulk_all_fast(p_organization_id NUMBER) IS
500 SELECT mmtt.* FROM
501 mtl_material_transactions_temp mmtt,mtl_allocations_gtmp mag
502 WHERE mmtt.wms_task_status = 8 -- unreleased
503 And mmtt.cartonization_id IS null -- not cartonized
504 And mmtt.organization_id = p_organization_id
505 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
506 AND mmtt.move_order_header_id = mag.move_order_header_id
507 AND (mmtt.serial_allocated_flag <> 'Y' OR
508 mmtt.serial_allocated_flag IS NULL ) --Should not bulk
509 --Bug3628747
510 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
511 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
512 AND Exists ( select 1
513 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
514 Where wdd.move_order_line_id = mmtt.move_order_line_id
515 AND wdd.delivery_detail_id = wda.delivery_Detail_id
516 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
517 )
518 for update of mmtt.transaction_temp_id; -- to lock the records
519
520 CURSOR c11_bulk_only_sub_item_fast(p_organization_id NUMBER) IS
521 SELECT mmtt.* FROM
522 mtl_material_transactions_temp mmtt,mtl_allocations_gtmp mag
523 WHERE mmtt.wms_task_status = 8 -- unreleased
524 And mmtt.cartonization_id IS null -- not cartonized
525 And mmtt.organization_id = p_organization_id
526 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
527 AND (mmtt.serial_allocated_flag <> 'Y' OR
528 mmtt.serial_allocated_flag IS NULL ) -- should not bulk those childs
529 --Bug3628747
530 AND mmtt.move_order_header_id = mag.move_order_header_id
531 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
532 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
533 AND Exists ( select 1
537 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
534 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
535 Where wdd.move_order_line_id = mmtt.move_order_line_id
536 AND wdd.delivery_detail_id = wda.delivery_Detail_id
538 )
539 AND ( EXISTS (SELECT 1 -- sub is bulk picking enabled
540 FROM mtl_secondary_inventories msi
541 WHERE msi.secondary_inventory_name = mmtt.subinventory_code
542 AND msi.organization_id = mmtt.organization_id
543 AND msi.enable_bulk_pick = 'Y')
544 OR EXISTS (SELECT 1 -- item is bulk picking enabled
545 FROM mtl_system_items msi
546 WHERE msi.inventory_item_id = mmtt.inventory_item_id
547 AND msi.bulk_picked_flag = 'Y')
548 )
549 for update of mmtt.transaction_temp_id; -- to lock the records
550
551
552 CURSOR c11_bulk_all(p_organization_id NUMBER) IS
553 SELECT mmtt.* FROM
554 mtl_material_transactions_temp mmtt,mtl_txn_request_headers moh,
555 wsh_pick_grouping_rules spg
556 WHERE mmtt.wms_task_status = 8 -- unreleased
557 And mmtt.cartonization_id IS null -- not cartonized
558 And mmtt.organization_id = p_organization_id
559 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
560 AND mmtt.move_order_header_id = moh.header_id
561 AND spg.pick_grouping_rule_id = moh.grouping_rule_id
562 AND spg.pick_method <>WMS_GLOBALS.PICK_METHOD_ORDER -- not order pciking
563 AND moh.move_order_type = INV_GLOBALS.g_move_order_pick_wave -- pick wave move order only
564 -- following is the logic for the input parameters
565 AND (mmtt.serial_allocated_flag <> 'Y' OR
566 mmtt.serial_allocated_flag IS NULL ) -- should not bulk those childs Bug3628747
567 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
568 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
569 AND moh.request_number between nvl(p_input_for_bulk.start_mo_request_number,moh.request_number) and
570 nvl(p_input_for_bulk.end_mo_request_number,moh.request_number)
571 AND moh.creation_date between nvl(p_input_for_bulk.start_release_date,moh.creation_date) and
572 nvl(p_input_for_bulk.end_release_date,moh.creation_date)
573 AND Exists ( select 1
574 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
575 Where wdd.move_order_line_id = mmtt.move_order_line_id
576 AND wdd.delivery_detail_id = wda.delivery_Detail_id
577 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
578 )
579 for update of mmtt.transaction_temp_id; -- to lock the records
580
581 CURSOR c11_bulk_only_sub_item(p_organization_id NUMBER) IS
582 SELECT mmtt.* FROM
583 mtl_material_transactions_temp mmtt,mtl_txn_request_headers moh,
584 wsh_pick_grouping_rules spg
585 WHERE mmtt.wms_task_status = 8 -- unreleased
586 And mmtt.cartonization_id IS null -- not cartonized
587 And mmtt.organization_id = p_organization_id
588 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
589 AND mmtt.move_order_header_id = moh.header_id
590 AND spg.pick_grouping_rule_id = moh.grouping_rule_id
591 AND spg.pick_method <>WMS_GLOBALS.PICK_METHOD_ORDER -- not order pciking
592 AND (mmtt.serial_allocated_flag <> 'Y' OR
593 mmtt.serial_allocated_flag IS NULL ) -- should not bulk those lines
594 -- Bug3628747
595 AND moh.move_order_type = INV_GLOBALS.g_move_order_pick_wave -- pick wave move order only
596 -- following is the logic for the input parameters
597 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
598 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
599 AND moh.request_number between nvl(p_input_for_bulk.start_mo_request_number,moh.request_number) and
600 nvl(p_input_for_bulk.end_mo_request_number,moh.request_number)
601 AND moh.creation_date between nvl(p_input_for_bulk.start_release_date,moh.creation_date) and
602 nvl(p_input_for_bulk.end_release_date,moh.creation_date)
603 AND Exists ( select 1
604 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
605 Where wdd.move_order_line_id = mmtt.move_order_line_id
606 AND wdd.delivery_detail_id = wda.delivery_Detail_id
607 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
608 )
609 AND ( EXISTS (SELECT 1 -- sub is bulk picking enabled
610 FROM mtl_secondary_inventories msi
611 WHERE msi.secondary_inventory_name = mmtt.subinventory_code
612 AND msi.organization_id = mmtt.organization_id
616 WHERE msi.inventory_item_id = mmtt.inventory_item_id
613 AND msi.enable_bulk_pick = 'Y')
614 OR EXISTS (SELECT 1 -- item is bulk picking enabled
615 FROM mtl_system_items msi
617 AND msi.bulk_picked_flag = 'Y')
618 )
619 for update of mmtt.transaction_temp_id; -- to lock the records
620
621 CURSOR c11_bulk_trip(p_organization_id NUMBER) IS
622 select mmtt.*
623 from wsh_delivery_legs wdl,wsh_delivery_details wdd, wsh_delivery_assignments_v wda,
624 wsh_trip_stops wts, mtl_material_transactions_temp mmtt,mtl_txn_request_headers moh,
625 wsh_pick_grouping_rules spg
626 where wts.trip_id = p_input_for_bulk.trip_id
627 and wdl.pick_up_stop_id = wts.stop_id
628 and wdl.delivery_id = wda.delivery_id
629 and wda.delivery_detail_id = wdd.delivery_detail_id
630 and mmtt.move_order_line_id = wdd.move_order_line_id
631 and mmtt.wms_task_status = 8 -- unreleased
632 And mmtt.cartonization_id IS null -- not cartonized
633 And mmtt.organization_id = p_organization_id
634 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
635 AND mmtt.move_order_header_id = moh.header_id
636 AND spg.pick_grouping_rule_id = moh.grouping_rule_id
637 AND spg.pick_method <>WMS_GLOBALS.PICK_METHOD_ORDER -- not order pciking
638 AND (mmtt.serial_allocated_flag <> 'Y' OR
639 mmtt.serial_allocated_flag IS NULL ) -- should not bulk those lines
640 --Bug3628747
641 AND moh.move_order_type = INV_GLOBALS.g_move_order_pick_wave -- pick wave move order only
642 -- following is the logic for the input parameters
643 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
644 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
645 AND moh.request_number between nvl(p_input_for_bulk.start_mo_request_number,moh.request_number) and
646 nvl(p_input_for_bulk.end_mo_request_number,moh.request_number)
647 AND moh.creation_date between nvl(p_input_for_bulk.start_release_date,moh.creation_date) and
648 nvl(p_input_for_bulk.end_release_date,moh.creation_date)
649 AND Exists ( select 1
650 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
651 Where wdd.move_order_line_id = mmtt.move_order_line_id
652 AND wdd.delivery_detail_id = wda.delivery_Detail_id
653 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
654 )
655 for update of mmtt.transaction_temp_id; -- to lock the records
656
657 CURSOR c11_bulk_trip_sub_item(p_organization_id NUMBER) IS
658 select mmtt.*
659 from wsh_delivery_legs wdl,wsh_delivery_details wdd, wsh_delivery_assignments_v wda,
660 wsh_trip_stops wts, mtl_material_transactions_temp mmtt,mtl_txn_request_headers moh,
661 wsh_pick_grouping_rules spg
662 where wts.trip_id = p_input_for_bulk.trip_id
663 and wdl.pick_up_stop_id = wts.stop_id
664 and wdl.delivery_id = wda.delivery_id
665 and wda.delivery_detail_id = wdd.delivery_detail_id
666 and mmtt.move_order_line_id = wdd.move_order_line_id
667 and mmtt.wms_task_status = 8 -- unreleased
668 And mmtt.cartonization_id IS null -- not cartonized
669 And mmtt.organization_id = p_organization_id
670 AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
671 AND mmtt.move_order_header_id = moh.header_id
672 AND spg.pick_grouping_rule_id = moh.grouping_rule_id
673 AND spg.pick_method <>WMS_GLOBALS.PICK_METHOD_ORDER -- not order pciking
674 AND (mmtt.serial_allocated_flag <> 'Y' OR
675 mmtt.serial_allocated_flag IS NULL ) -- should not bulk those lines
676 --Bug3628747
677 AND moh.move_order_type = INV_GLOBALS.g_move_order_pick_wave -- pick wave move order only
678 -- following is the logic for the input parameters
679 AND mmtt.subinventory_code = nvl(p_input_for_bulk.subinventory_code, mmtt.subinventory_code)
680 AND mmtt.inventory_item_id = nvl(p_input_for_bulk.item_id,mmtt.inventory_item_id)
681 AND moh.request_number between nvl(p_input_for_bulk.start_mo_request_number,moh.request_number) and
682 nvl(p_input_for_bulk.end_mo_request_number,moh.request_number)
683 AND moh.creation_date between nvl(p_input_for_bulk.start_release_date,moh.creation_date) and
684 nvl(p_input_for_bulk.end_release_date,moh.creation_date)
685 AND Exists ( select 1
686 From wsh_delivery_details wdd,wsh_delivery_assignments_v wda
687 Where wdd.move_order_line_id = mmtt.move_order_line_id
688 AND wdd.delivery_detail_id = wda.delivery_Detail_id
689 AND nvl(wda.delivery_id,-1) = decode(p_input_for_bulk.delivery_id,null,nvl(wda.delivery_id,-1),p_input_for_bulk.delivery_id)
690 )
691 AND ( EXISTS (SELECT 1 -- sub is bulk picking enabled
695 AND msi.enable_bulk_pick = 'Y')
692 FROM mtl_secondary_inventories msi
693 WHERE msi.secondary_inventory_name = mmtt.subinventory_code
694 AND msi.organization_id = mmtt.organization_id
696 OR EXISTS (SELECT 1 -- item is bulk picking enabled
697 FROM mtl_system_items msi
698 WHERE msi.inventory_item_id = mmtt.inventory_item_id
699 AND msi.bulk_picked_flag = 'Y')
700 )
701 for update of mmtt.transaction_temp_id; -- to lock the records
702 l_organization_id NUMBER;
703 l_return_status VARCHAR2(1);
704 l_lot_control_code NUMBER;
705 l_serial_control_code NUMBER;
706 l_fast_possible boolean;
707
708 BEGIN
709
710 if (g_trace_on = 1) then log_event('Enter create_wct'); END IF;
711
712 error_code := 'GET_CLPN_ATTR';
713
714 IF( p_move_order_header_id IS NULL AND
715 p_transaction_header_id IS NULL ) THEN
716
717 if (g_trace_on = 1) then log_event('Error- mo hdr id and txn hdr id are null'); END IF;
718 RAISE fnd_api.g_exc_unexpected_error;
719
720 END IF;
721
722 IF(p_move_order_header_id IS NOT NULL) THEN
723
724 if (g_trace_on = 1) then log_event(' mo hdr id '||p_move_order_header_id); END IF;
725
726 IF (p_move_order_header_id <> -1) THEN --- patchset J bulk picking ------------
727 if (g_trace_on = 1) then log_event('calling from pick release'); end if;
728 OPEN c1(p_move_order_header_id);
729 ELSE
730 if (g_trace_on = 1) then --log_event('PATCHSET J-- BULK PICKING -- START');
731 log_event('calling from concurrent program'); end if;
732 l_organization_id := p_input_for_bulk.organization_id;
733 if (g_trace_on = 1) then log_event(' organization_id '||l_organization_id); end if;
734
735 -- make sure the temp table is empty, the following is to improve performance
736 -- when move order number or creation dates are entered
737 delete mtl_allocations_gtmp;
738 l_fast_possible := false;
739 if p_input_for_bulk.start_mo_request_number is not null
740 or p_input_for_bulk.start_release_date is not null then -- select the move_order_headers
741 l_fast_possible := true;
742 insert into mtl_allocations_gtmp
743 (move_order_header_id)
744 select moh.header_id
745 from mtl_txn_request_headers moh,
746 wsh_pick_grouping_rules spg
747 where spg.pick_grouping_rule_id = moh.grouping_rule_id
748 AND spg.pick_method <>WMS_GLOBALS.PICK_METHOD_ORDER -- not order pciking
749 AND moh.move_order_type = INV_GLOBALS.g_move_order_pick_wave -- pick wave move order only
750 AND moh.request_number between nvl(p_input_for_bulk.start_mo_request_number,moh.request_number) and
751 nvl(p_input_for_bulk.end_mo_request_number,moh.request_number)
752 AND moh.creation_date between nvl(p_input_for_bulk.start_release_date,moh.creation_date) and
753 nvl(p_input_for_bulk.end_release_date,moh.creation_date);
754 end if;
755
756 if (p_input_for_bulk.trip_id is null) then
757 if (p_input_for_bulk.only_sub_item = 1) then
758 if (l_fast_possible) then
759 if (g_trace_on = 1) then log_event('OPEN c11_bulk_only_sub_item_fast'); end if;
760 OPEN c11_bulk_only_sub_item_fast(l_organization_id);
761 else
762 if (g_trace_on = 1) then log_event('OPEN c11_bulk_only_sub_item'); end if;
763
764 OPEN c11_bulk_only_sub_item(l_organization_id);
765 end if;
766 else
767 if (l_fast_possible) then
768 if (g_trace_on = 1) then log_event('OPEN c11_bulk_all_fast'); end if;
769 OPEN c11_bulk_all_fast(l_organization_id);
770 else
771 if (g_trace_on = 1) then log_event('OPEN c11_bulk_all'); end if;
772 OPEN c11_bulk_all(l_organization_id);
773 end if;
774 end if;
775 else
776 if (p_input_for_bulk.only_sub_item = 1) then
777 if (g_trace_on = 1) then log_event('OPEN c11_bulk_trip_sub_item'); end if;
778 OPEN c11_bulk_trip_sub_item(l_organization_id);
779 else
780 if (g_trace_on = 1) then log_event('OPEN c11_bulk_trip'); end if;
781 OPEN c11_bulk_trip(l_organization_id);
782 end if;
783 end if;
784 END IF;
785 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING -- END'); end if;
786 ELSIF(p_transaction_header_id IS NOT NULL) THEN
787
788 if (g_trace_on = 1) then log_event(' txn hdr id '||p_transaction_header_id); END IF;
789
790 OPEN c2(p_transaction_header_id);
791
792 END IF;
793
794 LOOP
795 mmtt_rec := NULL;
796
797 IF(p_move_order_header_id IS NOT NULL) THEN
801 EXIT WHEN c1%notfound;
798 IF (p_move_order_header_id <> -1) THEN -- patchset J bulk picking -----
799 IF c1%isopen THEN
800 FETCH c1 INTO mmtt_rec;
802 END IF;
803 ELSE
804 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING -- START'); end if;
805 IF c11_bulk_all%isopen THEN
806 FETCH c11_bulk_all INTO mmtt_rec;
807 EXIT WHEN c11_bulk_all%notfound;
808 ELSIF c11_bulk_only_sub_item%isopen THEN
809 FETCH c11_bulk_only_sub_item INTO mmtt_rec;
810 EXIT WHEN c11_bulk_only_sub_item%notfound;
811 ELSIF c11_bulk_trip%isopen THEN
812 FETCH c11_bulk_trip INTO mmtt_rec;
813 EXIT WHEN c11_bulk_trip%notfound;
814 ELSIF c11_bulk_trip_sub_item%isopen THEN
815 FETCH c11_bulk_trip_sub_item INTO mmtt_rec;
816 EXIT WHEN c11_bulk_trip_sub_item%notfound;
817 ELSIF c11_bulk_all_fast%isopen THEN
818 FETCH c11_bulk_all_fast INTO mmtt_rec;
819 EXIT WHEN c11_bulk_all_fast%notfound;
820 ELSIF c11_bulk_only_sub_item_fast%isopen THEN
821 FETCH c11_bulk_only_sub_item_fast INTO mmtt_rec;
822 EXIT WHEN c11_bulk_only_sub_item_fast%notfound;
823 END IF;
824 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING -- END'); end if;
825 END IF;
826
827 ELSIF(p_transaction_header_id IS NOT NULL) THEN
828
829 IF c2%isopen THEN
830 FETCH c2 INTO mmtt_rec;
831 EXIT WHEN c2%notfound;
832 END IF;
833 END IF;
834
835 --- patchset J bulk picking -----
836 if mmtt_rec.parent_line_id is not null then -- child line
837 if (g_trace_on = 1) then -- log_event('PATCHSET J-- BULK PICKING -- START');
838 log_event('checking the lot and serial control code'); end if;
839 select lot_control_code,serial_number_control_code
840 into l_lot_control_code,l_serial_control_code
841 from mtl_system_items_b msi, mtl_material_transactions_temp mmtt
842 where mmtt.transaction_temp_id = mmtt_rec.transaction_Temp_id
843 and mmtt.organization_id = msi.organization_id
844 and msi.inventory_item_id = mmtt.inventory_item_id;
845 if (g_trace_on = 1) then log_event('transaction_temp_id:'|| mmtt_rec.transaction_Temp_id ||
846 ' lot control code :'||l_lot_control_code ||
847 ' serial control code :'||l_serial_control_code);
848 end if;
849 if (g_trace_on = 1) then log_event('nullify the parent_line_id for the child task '); end if;
850
851 update mtl_material_transactions_temp
852 set parent_line_id = null
853 where transaction_temp_id = mmtt_rec.transaction_Temp_id;
854
855 -- call update_parent_mmtt to change the qty or delete the parent line --------
856 if (g_trace_on = 1) then log_event('calling update_parent_mmtt ....'); end if;
857 inv_trx_util_pub.update_parent_mmtt(x_return_status => l_return_status
858 , p_parent_line_id =>mmtt_rec.parent_line_id
859 , p_child_line_id => mmtt_rec.transaction_Temp_id
860 , p_lot_control_code => l_lot_control_code
861 , p_serial_control_code => l_serial_control_code);
862 if (g_trace_on = 1) then log_event('returning from update_parent_mmtt:'||l_return_status); end if;
863 if (l_return_status <> fnd_api.g_ret_sts_success) then
864 RAISE fnd_api.g_exc_unexpected_error;
865 end if;
866 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING --END'); end if;
867 end if;
868
869 ---- end of patchset J bulk picking -------------------
870 if (g_trace_on = 1) then log_event('Insert transaction temp id:'||mmtt_rec.transaction_temp_id); end if;
871 if (g_trace_on = 1) then log_event('transaction quantity:'||mmtt_rec.transaction_quantity); end if;
872 if (g_trace_on = 1) then log_event('secondary transaction quantity:'||mmtt_rec.secondary_transaction_quantity); end if; --invconv kkillams
873 INSERT INTO wms_cartonization_temp
874 (transaction_header_id,
875 transaction_temp_id,
876 source_code,
877 source_line_id,
878 transaction_mode,
879 lock_flag,
880 last_update_date,
881 last_updated_by,
882 creation_date,
883 created_by,
884 last_update_login,
885 request_id,
886 program_application_id,
887 program_id,
888 program_update_date,
889 inventory_item_id,
890 revision,
891 organization_id,
892 subinventory_code,
893 locator_id,
894 transaction_quantity,
895 primary_quantity,
896 transaction_uom,
897 transaction_cost,
898 transaction_type_id,
899 transaction_action_id,
900 transaction_source_type_id,
901 transaction_source_id,
905 distribution_account_id,
902 transaction_source_name,
903 transaction_date,
904 acct_period_id,
906 transaction_reference,
907 requisition_line_id,
908 requisition_distribution_id,
909 reason_id,
910 lot_number,
911 lot_expiration_date,
912 serial_number,
913 receiving_document,
914 demand_id,
915 rcv_transaction_id,
916 move_transaction_id,
917 completion_transaction_id,
918 wip_entity_type,
919 schedule_id,
920 repetitive_line_id,
921 employee_code,
922 primary_switch,
923 schedule_update_code,
924 setup_teardown_code,
925 item_ordering,
926 negative_req_flag,
927 operation_seq_num,
928 picking_line_id,
929 trx_source_line_id,
930 trx_source_delivery_id,
931 physical_adjustment_id,
932 cycle_count_id,
933 rma_line_id,
934 customer_ship_id,
935 currency_code,
936 currency_conversion_rate,
937 currency_conversion_type,
938 currency_conversion_date,
939 ussgl_transaction_code,
940 vendor_lot_number,
941 encumbrance_account,
942 encumbrance_amount,
943 ship_to_location,
944 shipment_number,
945 transfer_cost,
946 transportation_cost,
947 transportation_account,
948 freight_code,
949 containers,
950 waybill_airbill,
951 expected_arrival_date,
952 transfer_subinventory,
953 transfer_organization,
954 transfer_to_location,
955 new_average_cost,
956 value_change,
957 percentage_change,
958 material_allocation_temp_id,
959 demand_source_header_id,
960 demand_source_line,
961 demand_source_delivery,
962 item_segments,
963 item_description,
964 item_trx_enabled_flag,
965 item_location_control_code,
966 item_restrict_subinv_code,
967 item_restrict_locators_code,
968 item_revision_qty_control_code,
969 item_primary_uom_code,
970 item_uom_class,
971 item_shelf_life_code,
972 item_shelf_life_days,
973 item_lot_control_code,
974 item_serial_control_code,
975 item_inventory_asset_flag,
976 allowed_units_lookup_code,
977 department_id,
978 department_code,
979 wip_supply_type,
980 supply_subinventory,
981 supply_locator_id,
982 valid_subinventory_flag,
983 valid_locator_flag,
984 locator_segments,
985 current_locator_control_code,
986 number_of_lots_entered,
987 wip_commit_flag,
988 next_lot_number,
989 lot_alpha_prefix,
990 next_serial_number,
991 serial_alpha_prefix,
992 shippable_flag,
993 posting_flag,
994 required_flag,
995 process_flag,
996 error_code,
997 error_explanation,
998 attribute_category,
999 attribute1,
1000 attribute2,
1001 attribute3,
1002 attribute4,
1003 attribute5,
1004 attribute6,
1005 attribute7,
1006 attribute8,
1007 attribute9,
1008 attribute10,
1009 attribute11,
1010 attribute12,
1011 attribute13,
1012 attribute14,
1013 attribute15,
1014 movement_id,
1015 reservation_quantity,
1016 shipped_quantity,
1017 transaction_line_number,
1018 task_id,
1019 to_task_id,
1020 source_task_id,
1021 project_id,
1022 source_project_id,
1023 pa_expenditure_org_id,
1024 to_project_id,
1025 expenditure_type,
1026 final_completion_flag,
1027 transfer_percentage,
1028 transaction_sequence_id,
1029 material_account,
1030 material_overhead_account,
1031 resource_account,
1032 outside_processing_account,
1033 overhead_account,
1034 flow_schedule,
1035 cost_group_id,
1036 demand_class,
1037 qa_collection_id,
1038 kanban_card_id,
1039 overcompletion_transaction_qty,
1040 overcompletion_primary_qty,
1041 overcompletion_transaction_id,
1042 end_item_unit_number,
1043 scheduled_payback_date,
1044 line_type_code,
1045 parent_transaction_temp_id,
1046 put_away_strategy_id,
1047 put_away_rule_id,
1048 pick_strategy_id,
1049 pick_rule_id,
1050 move_order_line_id,
1051 task_group_id,
1052 pick_slip_number,
1053 reservation_id,
1054 common_bom_seq_id,
1055 common_routing_seq_id,
1056 org_cost_group_id,
1057 cost_type_id,
1061 wms_task_type,
1058 transaction_status,
1059 standard_operation_id,
1060 task_priority,
1062 parent_line_id,
1063 --source_lot_number,
1064 transfer_cost_group_id,
1065 lpn_id,
1066 transfer_lpn_id,
1067 wms_task_status,
1068 content_lpn_id,
1069 container_item_id,
1070 cartonization_id,
1071 pick_slip_date,
1072 rebuild_item_id,
1073 rebuild_serial_number,
1074 rebuild_activity_id,
1075 rebuild_job_name,
1076 organization_type,
1077 transfer_organization_type,
1078 owning_organization_id,
1079 owning_tp_type,
1080 xfr_owning_organization_id,
1081 transfer_owning_tp_type,
1082 planning_organization_id,
1083 planning_tp_type,
1084 xfr_planning_organization_id,
1085 transfer_planning_tp_type,
1086 secondary_uom_code,
1087 secondary_transaction_quantity,
1088 transaction_batch_id,
1089 transaction_batch_seq,
1090 allocated_lpn_id,
1091 schedule_number,
1092 scheduled_flag,
1093 class_code,
1094 schedule_group,
1095 build_sequence,
1096 bom_revision,
1097 routing_revision,
1098 bom_revision_date,
1099 routing_revision_date,
1100 alternate_bom_designator,
1101 alternate_routing_designator,
1102 operation_plan_id,
1103 move_order_header_id,
1104 serial_allocated_flag)
1105 values
1106 (mmtt_rec.transaction_header_id,
1107 mmtt_rec.transaction_temp_id,
1108 mmtt_rec.source_code,
1109 mmtt_rec.source_line_id,
1110 mmtt_rec.transaction_mode,
1111 mmtt_rec.lock_flag,
1112 mmtt_rec.last_update_date,
1113 mmtt_rec.last_updated_by,
1114 mmtt_rec.creation_date,
1115 mmtt_rec.created_by,
1116 mmtt_rec.last_update_login,
1117 mmtt_rec.request_id,
1118 mmtt_rec.program_application_id,
1119 mmtt_rec.program_id,
1120 mmtt_rec.program_update_date,
1121 mmtt_rec.inventory_item_id,
1122 mmtt_rec.revision,
1123 mmtt_rec.organization_id,
1124 mmtt_rec.subinventory_code,
1125 mmtt_rec.locator_id,
1126 mmtt_rec.transaction_quantity,
1127 mmtt_rec.primary_quantity,
1128 mmtt_rec.transaction_uom,
1129 mmtt_rec.transaction_cost,
1130 mmtt_rec.transaction_type_id,
1131 mmtt_rec.transaction_action_id,
1132 mmtt_rec.transaction_source_type_id,
1133 mmtt_rec.transaction_source_id,
1134 mmtt_rec.transaction_source_name,
1135 mmtt_rec.transaction_date,
1136 mmtt_rec.acct_period_id,
1137 mmtt_rec.distribution_account_id,
1138 mmtt_rec.transaction_reference,
1139 mmtt_rec.requisition_line_id,
1140 mmtt_rec.requisition_distribution_id,
1141 mmtt_rec.reason_id,
1142 mmtt_rec.lot_number,
1143 mmtt_rec.lot_expiration_date,
1144 mmtt_rec.serial_number,
1145 mmtt_rec.receiving_document,
1146 mmtt_rec.demand_id,
1147 mmtt_rec.rcv_transaction_id,
1148 mmtt_rec.move_transaction_id,
1149 mmtt_rec.completion_transaction_id,
1150 mmtt_rec.wip_entity_type,
1151 mmtt_rec.schedule_id,
1152 mmtt_rec.repetitive_line_id,
1153 mmtt_rec.employee_code,
1154 mmtt_rec.primary_switch,
1155 mmtt_rec.schedule_update_code,
1156 mmtt_rec.setup_teardown_code,
1157 mmtt_rec.item_ordering,
1158 mmtt_rec.negative_req_flag,
1159 mmtt_rec.operation_seq_num,
1160 mmtt_rec.picking_line_id,
1161 mmtt_rec.trx_source_line_id,
1162 mmtt_rec.trx_source_delivery_id,
1163 mmtt_rec.physical_adjustment_id,
1164 mmtt_rec.cycle_count_id,
1165 mmtt_rec.rma_line_id,
1166 mmtt_rec.customer_ship_id,
1167 mmtt_rec.currency_code,
1168 mmtt_rec.currency_conversion_rate,
1169 mmtt_rec.currency_conversion_type,
1170 mmtt_rec.currency_conversion_date,
1171 mmtt_rec.ussgl_transaction_code,
1172 mmtt_rec.vendor_lot_number,
1173 mmtt_rec.encumbrance_account,
1174 mmtt_rec.encumbrance_amount,
1175 mmtt_rec.ship_to_location,
1176 mmtt_rec.shipment_number,
1177 mmtt_rec.transfer_cost,
1178 mmtt_rec.transportation_cost,
1179 mmtt_rec.transportation_account,
1180 mmtt_rec.freight_code,
1181 mmtt_rec.containers,
1182 mmtt_rec.waybill_airbill,
1183 mmtt_rec.expected_arrival_date,
1184 mmtt_rec.transfer_subinventory,
1185 mmtt_rec.transfer_organization,
1186 mmtt_rec.transfer_to_location,
1187 mmtt_rec.new_average_cost,
1188 mmtt_rec.value_change,
1189 mmtt_rec.percentage_change,
1190 mmtt_rec.material_allocation_temp_id,
1191 mmtt_rec.demand_source_header_id,
1192 mmtt_rec.demand_source_line,
1193 mmtt_rec.demand_source_delivery,
1197 mmtt_rec.item_location_control_code,
1194 mmtt_rec.item_segments,
1195 mmtt_rec.item_description,
1196 mmtt_rec.item_trx_enabled_flag,
1198 mmtt_rec.item_restrict_subinv_code,
1199 mmtt_rec.item_restrict_locators_code,
1200 mmtt_rec.item_revision_qty_control_code,
1201 mmtt_rec.item_primary_uom_code,
1202 mmtt_rec.item_uom_class,
1203 mmtt_rec.item_shelf_life_code,
1204 mmtt_rec.item_shelf_life_days,
1205 mmtt_rec.item_lot_control_code,
1206 mmtt_rec.item_serial_control_code,
1207 mmtt_rec.item_inventory_asset_flag,
1208 mmtt_rec.allowed_units_lookup_code,
1209 mmtt_rec.department_id,
1210 mmtt_rec.department_code,
1211 mmtt_rec.wip_supply_type,
1212 mmtt_rec.supply_subinventory,
1213 mmtt_rec.supply_locator_id,
1214 mmtt_rec.valid_subinventory_flag,
1215 mmtt_rec.valid_locator_flag,
1216 mmtt_rec.locator_segments,
1217 mmtt_rec.current_locator_control_code,
1218 mmtt_rec.number_of_lots_entered,
1219 mmtt_rec.wip_commit_flag,
1220 mmtt_rec.next_lot_number,
1221 mmtt_rec.lot_alpha_prefix,
1222 mmtt_rec.next_serial_number,
1223 mmtt_rec.serial_alpha_prefix,
1224 mmtt_rec.shippable_flag,
1225 mmtt_rec.posting_flag,
1226 mmtt_rec.required_flag,
1227 mmtt_rec.process_flag,
1228 mmtt_rec.error_code,
1229 mmtt_rec.error_explanation,
1230 mmtt_rec.attribute_category,
1231 mmtt_rec.attribute1,
1232 mmtt_rec.attribute2,
1233 mmtt_rec.attribute3,
1234 mmtt_rec.attribute4,
1235 mmtt_rec.attribute5,
1236 mmtt_rec.attribute6,
1237 mmtt_rec.attribute7,
1238 mmtt_rec.attribute8,
1239 mmtt_rec.attribute9,
1240 mmtt_rec.attribute10,
1241 mmtt_rec.attribute11,
1242 mmtt_rec.attribute12,
1243 mmtt_rec.attribute13,
1244 mmtt_rec.attribute14,
1245 mmtt_rec.attribute15,
1246 mmtt_rec.movement_id,
1247 mmtt_rec.reservation_quantity,
1248 mmtt_rec.shipped_quantity,
1249 mmtt_rec.transaction_line_number,
1250 mmtt_rec.task_id,
1251 mmtt_rec.to_task_id,
1252 mmtt_rec.source_task_id,
1253 mmtt_rec.project_id,
1254 mmtt_rec.source_project_id,
1255 mmtt_rec.pa_expenditure_org_id,
1256 mmtt_rec.to_project_id,
1257 mmtt_rec.expenditure_type,
1258 mmtt_rec.final_completion_flag,
1259 mmtt_rec.transfer_percentage,
1260 mmtt_rec.transaction_sequence_id,
1261 mmtt_rec.material_account,
1262 mmtt_rec.material_overhead_account,
1263 mmtt_rec.resource_account,
1264 mmtt_rec.outside_processing_account,
1265 mmtt_rec.overhead_account,
1266 mmtt_rec.flow_schedule,
1267 mmtt_rec.cost_group_id,
1268 mmtt_rec.demand_class,
1269 mmtt_rec.qa_collection_id,
1270 mmtt_rec.kanban_card_id,
1271 mmtt_rec.overcompletion_transaction_qty,
1272 mmtt_rec.overcompletion_primary_qty,
1273 mmtt_rec.overcompletion_transaction_id,
1274 mmtt_rec.end_item_unit_number,
1275 mmtt_rec.scheduled_payback_date,
1276 mmtt_rec.line_type_code,
1277 mmtt_rec.parent_transaction_temp_id,
1278 mmtt_rec.put_away_strategy_id,
1279 mmtt_rec.put_away_rule_id,
1280 mmtt_rec.pick_strategy_id,
1281 mmtt_rec.pick_rule_id,
1282 mmtt_rec.move_order_line_id,
1283 mmtt_rec.task_group_id,
1284 mmtt_rec.pick_slip_number,
1285 mmtt_rec.reservation_id,
1286 mmtt_rec.common_bom_seq_id,
1287 mmtt_rec.common_routing_seq_id,
1288 mmtt_rec.org_cost_group_id,
1289 mmtt_rec.cost_type_id,
1290 mmtt_rec.transaction_status,
1291 mmtt_rec.standard_operation_id,
1292 mmtt_rec.task_priority,
1293 mmtt_rec.wms_task_type,
1294 mmtt_rec.parent_line_id,
1295 --mmtt_rec.source_lot_number,
1296 mmtt_rec.transfer_cost_group_id,
1297 mmtt_rec.lpn_id,
1298 mmtt_rec.transfer_lpn_id,
1299 mmtt_rec.wms_task_status,
1300 mmtt_rec.content_lpn_id,
1301 mmtt_rec.container_item_id,
1302 mmtt_rec.cartonization_id,
1303 mmtt_rec.pick_slip_date,
1304 mmtt_rec.rebuild_item_id,
1305 mmtt_rec.rebuild_serial_number,
1306 mmtt_rec.rebuild_activity_id,
1307 mmtt_rec.rebuild_job_name,
1308 mmtt_rec.organization_type,
1309 mmtt_rec.transfer_organization_type,
1310 mmtt_rec.owning_organization_id,
1311 mmtt_rec.owning_tp_type,
1312 mmtt_rec.xfr_owning_organization_id,
1313 mmtt_rec.transfer_owning_tp_type,
1314 mmtt_rec.planning_organization_id,
1315 mmtt_rec.planning_tp_type,
1316 mmtt_rec.xfr_planning_organization_id,
1317 mmtt_rec.transfer_planning_tp_type,
1318 mmtt_rec.secondary_uom_code,
1319 mmtt_rec.secondary_transaction_quantity,
1320 mmtt_rec.transaction_batch_id,
1321 mmtt_rec.transaction_batch_seq,
1325 mmtt_rec.class_code,
1322 mmtt_rec.allocated_lpn_id,
1323 mmtt_rec.schedule_number,
1324 mmtt_rec.scheduled_flag,
1326 mmtt_rec.schedule_group,
1327 mmtt_rec.build_sequence,
1328 mmtt_rec.bom_revision,
1329 mmtt_rec.routing_revision,
1330 mmtt_rec.bom_revision_date,
1331 mmtt_rec.routing_revision_date,
1332 mmtt_rec.alternate_bom_designator,
1333 mmtt_rec.alternate_routing_designator,
1334 mmtt_rec.operation_plan_id,
1335 mmtt_rec.move_order_header_id,
1336 mmtt_rec.serial_allocated_flag);
1337
1338 END LOOP;
1339
1340 IF c1%isopen THEN
1341 CLOSE c1;
1342 ELSIF c2%isopen THEN
1343 CLOSE c2;
1344 END IF;
1345
1346 IF c11_bulk_all%isopen THEN
1347 CLOSE c11_bulk_all;
1348 ELSIF c11_bulk_only_sub_item%isopen THEN
1349 CLOSE c11_bulk_only_sub_item;
1350 ELSIF c11_bulk_trip%isopen THEN
1351 CLOSE c11_bulk_trip;
1352 ELSIF c11_bulk_trip_sub_item%isopen THEN
1353 CLOSE c11_bulk_trip_sub_item;
1354 ELSIF c11_bulk_all_fast%isopen THEN
1355 CLOSE c11_bulk_all_fast;
1356 ELSIF c11_bulk_only_sub_item_fast%isopen THEN
1357 CLOSE c11_bulk_only_sub_item_fast;
1358 END IF;
1359 EXCEPTION
1360 WHEN OTHERS THEN
1361 if (g_trace_on = 1) then log_event(' Error occurred in create_wct proc'||Sqlerrm); END IF;
1362 RAISE fnd_api.g_exc_unexpected_error;
1363 END create_wct;
1364
1365
1366
1367
1368
1369
1370
1371 PROCEDURE get_cached_lpn_attributes(p_lpn_id IN NUMBER,
1372 x_inventory_item_id OUT NOCOPY NUMBER,
1373 x_gross_weight OUT NOCOPY NUMBER,
1374 x_content_volume OUT NOCOPY NUMBER,
1375 x_gross_weight_uom_code OUT NOCOPY VARCHAR2,
1376 x_content_volume_uom_code OUT NOCOPY VARCHAR2,
1377 x_tare_weight OUT NOCOPY NUMBER,
1378 x_tare_weight_uom_code OUT NOCOPY VARCHAR2,
1379 x_found_flag OUT NOCOPY VARCHAR2)
1380 IS
1381 BEGIN
1382
1383 error_code := 'GET_CLPN_ATTR';
1384
1385
1386 x_inventory_item_id := lpn_attr_table(p_lpn_id).inventory_item_id;
1387 x_gross_weight := lpn_attr_table(p_lpn_id).gross_weight;
1388 x_gross_weight_uom_code := lpn_attr_table(p_lpn_id).gross_weight_uom_code;
1389 x_content_volume := lpn_attr_table(p_lpn_id).content_volume;
1390 x_content_volume_uom_code := lpn_attr_table(p_lpn_id).content_volume_uom_code;
1391 x_tare_weight := lpn_attr_table(p_lpn_id).tare_weight;
1392 x_tare_weight_uom_code := lpn_attr_table(p_lpn_id).tare_weight_uom_code;
1393 x_found_flag := 'Y';
1394 EXCEPTION
1395 WHEN OTHERS THEN
1396 x_inventory_item_id := NULL;
1397 x_gross_weight := NULL;
1398 x_gross_weight_uom_code := NULL;
1399 x_content_volume := NULL;
1400 x_content_volume_uom_code := NULL;
1401 x_tare_weight := NULL;
1402 x_tare_weight_uom_code := NULL;
1403 x_found_flag := 'N';
1404 END;
1405
1406 PROCEDURE get_cached_package_attributes(p_org_id IN NUMBER,
1407 p_package_id IN NUMBER,
1408 x_inventory_item_id OUT NOCOPY NUMBER,
1409 x_gross_weight OUT NOCOPY NUMBER,
1410 x_content_volume OUT NOCOPY NUMBER,
1411 x_gross_weight_uom_code OUT NOCOPY VARCHAR2,
1412 x_content_volume_uom_code OUT NOCOPY VARCHAR2,
1413 x_tare_weight OUT NOCOPY NUMBER,
1414 x_tare_weight_uom_code OUT NOCOPY VARCHAR2,
1415 x_found_flag OUT NOCOPY VARCHAR2)
1416
1417 IS
1418 BEGIN
1419 error_code := 'GET_CPKG_ATTR';
1420 x_inventory_item_id := pkg_attr_table(p_package_id).inventory_item_id;
1421 x_gross_weight := pkg_attr_table(p_package_id).gross_weight;
1422 x_gross_weight_uom_code := pkg_attr_table(p_package_id).gross_weight_uom_code;
1423 x_content_volume := pkg_attr_table(p_package_id).content_volume;
1424 x_content_volume_uom_code := pkg_attr_table(p_package_id).content_volume_uom_code;
1425 x_tare_weight := pkg_attr_table(p_package_id).tare_weight;
1426 x_tare_weight_uom_code := pkg_attr_table(p_package_id).tare_weight_uom_code;
1427 x_found_flag := 'Y';
1428 EXCEPTION
1429 WHEN OTHERS THEN
1430 x_inventory_item_id := NULL;
1431 x_gross_weight := NULL;
1432 x_gross_weight_uom_code := NULL;
1433 x_content_volume := NULL;
1434 x_content_volume_uom_code := NULL;
1435 x_tare_weight := NULL;
1436 x_tare_weight_uom_code := NULL;
1437 x_found_flag := 'N';
1438 END;
1439
1440
1444
1441
1442 -- Given a transaction_temp_id, this returns whether the allocated lpn is
1443 -- is fully allocated, partially allocated or no LPN allocated.
1445 FUNCTION get_lpn_alloc_flag(p_temp_id IN NUMBER)
1446 return VARCHAR2 IS
1447 l_lpn_alloc_flag VARCHAR2(1):= null;
1448 BEGIN
1449 error_code := 'GET_LPN_ALLOC';
1450
1451 l_lpn_alloc_flag := t_lpn_alloc_flag_table(p_temp_id).lpn_alloc_flag;
1452 return l_lpn_alloc_flag;
1453 EXCEPTION
1454 WHEN OTHERS THEN
1455 RETURN 'N';
1456 END get_lpn_alloc_flag;
1457
1458
1459 -- This procedures returns different attributes for an LPN
1460
1461 PROCEDURE get_lpn_attributes(p_lpn_id IN NUMBER,
1462 x_inventory_item_id OUT NOCOPY NUMBER,
1463 x_gross_weight OUT NOCOPY NUMBER,
1464 x_content_volume OUT NOCOPY NUMBER,
1465 x_gross_weight_uom_code OUT NOCOPY VARCHAR2,
1466 x_content_volume_uom_code OUT NOCOPY VARCHAR2,
1467 x_tare_weight OUT NOCOPY NUMBER,
1468 x_tare_weight_uom_code OUT NOCOPY VARCHAR2)
1469 IS
1470 l_inventory_item_id NUMBER:= NULL;
1471 l_gross_weight NUMBER:= NULL;
1472 l_content_volume NUMBER:= NULL;
1473 l_gross_weight_uom_code VARCHAR2(3):= NULL;
1474 l_content_volume_uom_code VARCHAR2(3):= NULL;
1475 l_tare_weight NUMBER := NULL;
1476 l_tare_weight_uom_code VARCHAR2(3) := NULL;
1477 l_found_flag VARCHAR2(1) := NULL;
1478
1479 BEGIN
1480 error_code := 'GET_LPN_ATTR';
1481
1482 get_cached_lpn_attributes (p_lpn_id => p_lpn_id,
1483 x_inventory_item_id => l_inventory_item_id,
1484 x_gross_weight => l_gross_weight,
1485 x_content_volume => l_content_volume,
1486 x_gross_weight_uom_code => l_gross_weight_uom_code,
1487 x_content_volume_uom_code => l_content_volume_uom_code,
1488 x_tare_weight => l_tare_weight,
1489 x_tare_weight_uom_code => l_tare_weight_uom_code,
1490 x_found_flag => l_found_flag );
1491
1492 IF( l_found_flag = 'Y') THEN
1493 if (g_trace_on = 1) then log_event(' using cached values '); END IF;
1494 x_inventory_item_id := l_inventory_item_id;
1495 x_gross_weight := l_gross_weight;
1496 x_content_volume := l_content_volume;
1497 x_gross_weight_uom_code := l_gross_weight_uom_code;
1498 x_content_volume_uom_code := l_content_volume_uom_code;
1499 x_tare_weight := l_tare_weight;
1500 x_tare_weight_uom_code := l_tare_weight_uom_code;
1501 ELSE
1502
1503 SELECT
1504 inventory_item_id,
1505 Decode(gross_weight_uom_code,NULL,0,nvl(gross_weight,0)),
1506 gross_weight_uom_code,
1507 Decode(content_volume_uom_code,NULL,0,nvl(content_volume,0)),
1508 content_volume_uom_code,
1509 Decode(tare_weight_uom_code,NULL,0,nvl(tare_weight,0)),
1510 tare_weight_uom_code
1511 INTO
1512 x_inventory_item_id,
1513 x_gross_weight,
1514 x_gross_weight_uom_code,
1515 x_content_volume,
1516 x_content_volume_uom_code,
1517 x_tare_weight,
1518 x_tare_weight_uom_code
1519 FROM
1520 wms_license_plate_numbers
1521 WHERE
1522 lpn_id = p_lpn_id;
1523
1524 lpn_attr_table(p_lpn_id).inventory_item_id := x_inventory_item_id;
1525 lpn_attr_table(p_lpn_id).gross_weight := x_gross_weight;
1526 lpn_attr_table(p_lpn_id).content_volume := x_content_volume;
1527 lpn_attr_table(p_lpn_id).gross_weight_uom_code := x_gross_weight_uom_code;
1528 lpn_attr_table(p_lpn_id).content_volume_uom_code := x_content_volume_uom_code;
1529 lpn_attr_table(p_lpn_id).tare_weight := x_tare_weight;
1530 lpn_attr_table(p_lpn_id).tare_weight_uom_code := x_tare_weight_uom_code;
1531
1532 END IF;
1533
1534
1535 if (g_trace_on = 1) then
1536 log_event(' inventory_item_id:'||x_inventory_item_id);
1537 log_event(' gross_weight:'||x_gross_weight);
1538 log_event(' gross_weight_uom_code:'||x_gross_weight_uom_code);
1539 log_event(' content_volume:'||x_content_volume);
1540 log_event(' content_volume_uom_code:'||x_content_volume_uom_code);
1541 log_event(' tare:'||x_tare_weight);
1542 log_event(' tare_uom_code:'||x_tare_weight_uom_code);
1543
1544 END IF;
1545
1546 EXCEPTION
1547 WHEN OTHERS THEN
1548 if (g_trace_on = 1) then log_event(' LPN attributes not found'); END IF;
1549 x_inventory_item_id := NULL;
1550 x_gross_weight := NULL;
1551 x_gross_weight_uom_code := NULL;
1552 x_content_volume := NULL;
1553 x_content_volume_uom_code := NULL;
1554 x_tare_weight := NULL;
1558 END get_lpn_attributes;
1555 x_tare_weight_uom_code := NULL;
1556
1557
1559
1560 -- This procedures returns different attributes for a package
1561 PROCEDURE get_package_attributes(p_org_id IN NUMBER,
1562 p_package_id IN NUMBER,
1563 x_inventory_item_id OUT NOCOPY NUMBER,
1564 x_gross_weight OUT NOCOPY NUMBER,
1565 x_content_volume OUT NOCOPY NUMBER,
1566 x_gross_weight_uom_code OUT NOCOPY VARCHAR2,
1567 x_content_volume_uom_code OUT NOCOPY VARCHAR2,
1568 x_tare_weight OUT NOCOPY NUMBER,
1569 x_tare_weight_uom_code OUT NOCOPY VARCHAR2)
1570 IS
1571
1572 l_c_inventory_item_id NUMBER:= NULL;
1573 l_c_gross_weight NUMBER:= NULL;
1574 l_c_content_volume NUMBER:= NULL;
1575 l_c_gross_weight_uom_code VARCHAR2(3):= NULL;
1576 l_c_content_volume_uom_code VARCHAR2(3):= NULL;
1577 l_c_tare_weight NUMBER:= NULL;
1578 l_c_tare_weight_uom_code VARCHAR2(3):= NULL;
1579
1580 l_found_flag VARCHAR2(1):= NULL;
1581
1582 l_gross_weight NUMBER;
1583 l_content_volume NUMBER;
1584 l_final_wt NUMBER := 0;
1585 l_final_twt NUMBER := 0;
1586 l_final_vol NUMBER := 0;
1587 l_gross_weight_uom_code VARCHAR2(3);
1588 l_content_volume_uom_code VARCHAR2(3);
1589 l_tare_weight NUMBER:= NULL;
1590 l_tare_weight_uom_code VARCHAR2(3):= NULL;
1591
1592 l_std_wt_uom VARCHAR2(3);
1593 l_std_vol_uom VARCHAR2(3);
1594 l_ut_wt NUMBER := NULL;
1595 l_ut_vol NUMBER := NULL;
1596 l_item_id NUMBER := NULL;
1597 l_wt NUMBER := NULL;
1598 l_vol NUMBER := NULL;
1599 l_twt NUMBER := NULL;
1600 l_msg VARCHAR2(255);
1601
1602 CURSOR wts_n_vols IS
1603 SELECT
1604 parent_item_id,
1605 Decode(gross_weight_uom_code,NULL,0,nvl(gross_weight,0)),
1606 gross_weight_uom_code,
1607 Decode(content_volume_uom_code,NULL,0,nvl(content_volume,0)),
1608 content_volume_uom_code,
1609 Decode(tare_weight_uom_code,NULL,0,nvl(tare_weight,0)),
1610 tare_weight_uom_code
1611 FROM
1612 WMS_PACKAGING_HIST
1613 WHERE
1614 PARENT_PACKAGE_id = p_package_id;
1615 BEGIN
1616 if (g_trace_on = 1) then log_event(' Entered get label attributes for package:'||p_package_id); END IF;
1617
1618 error_code := 'GET_PKG_ATTR';
1619
1620 get_cached_package_attributes (p_org_id => p_org_id,
1621 p_package_id => p_package_id,
1622 x_inventory_item_id => l_c_inventory_item_id,
1623 x_gross_weight => l_c_gross_weight,
1624 x_content_volume => l_c_content_volume,
1625 x_gross_weight_uom_code => l_c_gross_weight_uom_code,
1626 x_content_volume_uom_code => l_c_content_volume_uom_code,
1627 x_tare_weight => l_c_tare_weight,
1628 x_tare_weight_uom_code => l_c_tare_weight_uom_code,
1629 x_found_flag => l_found_flag );
1630
1631 IF( l_found_flag = 'Y') THEN
1632
1633 if (g_trace_on = 1) then log_event(' using cached values '); END IF;
1634 x_inventory_item_id := l_c_inventory_item_id;
1635 x_gross_weight := l_c_gross_weight;
1636 x_content_volume := l_c_content_volume;
1637 x_gross_weight_uom_code := l_c_gross_weight_uom_code;
1638 x_content_volume_uom_code := l_c_content_volume_uom_code;
1639 x_tare_weight := l_c_tare_weight;
1640 x_tare_weight_uom_code := l_c_tare_weight_uom_code;
1641
1642 ELSE
1643 x_inventory_item_id := NULL;
1644 x_gross_weight := NULL;
1645 x_gross_weight_uom_code := NULL;
1646 x_content_volume := NULL;
1647 x_content_volume_uom_code := NULL;
1648 x_tare_weight := NULL;
1649 x_tare_weight_uom_code := NULL;
1650
1651
1652 SELECT
1653 parent_item_id
1654 INTO
1655 x_inventory_item_id
1656 FROM
1657 WMS_PACKAGING_HIST
1658 WHERE
1659 PARENT_PACKAGE_id = p_package_id
1660 AND rownum < 2;
1661
1662 if (g_trace_on = 1) then log_event(' container item_id:'||x_inventory_item_id); END IF;
1663
1664 SELECT
1665 Decode(weight_uom_code,NULL,0,nvl(unit_weight,0)),
1666 Decode(volume_uom_code,NULL,0,Nvl(unit_volume,0)),
1667 weight_uom_code,
1668 volume_uom_code
1669 INTO
1670 l_ut_wt,
1671 l_ut_vol,
1675 mtl_system_items
1672 l_std_wt_uom,
1673 l_std_vol_uom
1674 FROM
1676 WHERE
1677 organization_id = p_org_id AND
1678 inventory_item_id = x_inventory_item_id;
1679
1680 if (g_trace_on = 1) then
1681 log_event(' Container Item attributes are');
1682 log_event(' unit_wt'||l_ut_wt);
1683 log_event(' Unit_vol'||l_ut_vol);
1684 log_event(' std wt uom'||l_std_wt_uom);
1685 log_event(' std vol uom '||l_std_vol_uom);
1686 END IF;
1687 OPEN wts_n_vols;
1688
1689 LOOP
1690
1691
1692
1693 if (g_trace_on = 1) then log_event(' Fetching from wts_n_vols'); END IF;
1694 FETCH wts_n_vols INTO
1695 l_item_id,
1696 l_gross_weight,
1697 l_gross_weight_uom_code,
1698 l_content_volume,
1699 l_content_volume_uom_code,
1700 l_tare_weight,
1701 l_tare_weight_uom_code;
1702
1703 EXIT WHEN wts_n_vols%notfound;
1704
1705 if (g_trace_on = 1) then
1706 log_event(' container it id'||l_item_id);
1707 log_event(' gross_weight '||l_gross_weight);
1708 log_event(' content_volume '||l_content_volume);
1709 log_event(' gross_weight_uom_code '||l_gross_weight_uom_code);
1710 log_event(' content_volume_uom_code '||l_content_volume_uom_code);
1711 log_event(' tare_weight '||l_tare_weight);
1712 log_event(' tare_weight_uom_code '||l_tare_weight_uom_code);
1713 END IF;
1714 -- Logic
1715 -- We try to convert everything to the container items wt/vol uom first
1716 -- If that is null we have to pick up first non null wt/vol uom as standard
1717 -- for each record logic should be
1718 -- if the weight uom is not null on the record
1719 -- if the std wt uom is not set
1720 -- set this uom as the standard uom
1721 -- else
1722 -- if std wt uom is different from the current uom
1723 -- convert wt to the std uom
1724 -- if conversion returns null, -1 set the wt to zero
1725 -- else
1726 -- no conversion needed
1727 -- end if
1728 -- end if
1729 -- else
1730 -- there should be no contribution of weight from this record.
1731 -- set l_gross_weight to zero
1732 -- end if;
1733 -- Same logic applies for volume
1734
1735 IF (l_gross_weight_uom_code IS NOT NULL) THEN
1736
1737 IF l_std_wt_uom IS NULL THEN
1738
1739 l_std_wt_uom := l_gross_weight_uom_code;
1740
1741 ELSIF (l_gross_weight_uom_code <> l_std_wt_uom ) THEN
1742
1743 l_wt := inv_convert.inv_um_convert
1744 ( l_item_id,
1745 5,
1746 l_gross_weight,
1747 l_gross_weight_uom_code,
1748 l_std_wt_uom,
1749 NULL,
1750 null
1751 );
1752
1753 IF( l_wt < 0 ) THEN
1754 if (g_trace_on = 1) then log_event('Error converting UOM from '||l_gross_weight_uom_code||' to '||l_std_wt_uom||' qty '||l_gross_weight); END IF;
1755 l_gross_weight := 0;
1756 ELSE
1757 l_gross_weight := l_wt;
1758 END IF;
1759
1760
1761 if (g_trace_on = 1) then log_event(' gross_weight - after conv '||l_gross_weight); END IF;
1762
1763 ELSE
1764
1765 NULL;
1766
1767 END IF;
1768
1769 ELSE
1770
1771 l_gross_weight := 0;
1772
1773 END IF;
1774
1775 IF (l_tare_weight_uom_code IS NOT NULL) THEN
1776
1777 IF l_std_wt_uom IS NULL THEN
1778
1779 l_std_wt_uom := l_tare_weight_uom_code;
1780
1781 ELSIF (l_tare_weight_uom_code <> l_std_wt_uom ) THEN
1782
1783 l_twt := inv_convert.inv_um_convert
1784 ( l_item_id,
1785 5,
1786 l_tare_weight,
1787 l_tare_weight_uom_code,
1788 l_std_wt_uom,
1789 NULL,
1790 null
1791 );
1792
1793 IF( l_twt < 0 ) THEN
1794 if (g_trace_on = 1) then log_event('Error converting UOM from '||l_tare_weight_uom_code||' to '||l_std_wt_uom||' qty '||l_tare_weight); END IF;
1795 l_tare_weight := 0;
1796 ELSE
1797 l_tare_weight := l_twt;
1798 l_tare_weight_uom_code := l_std_wt_uom;
1799 END IF;
1800
1801 if (g_trace_on = 1) then log_event(' tare_weight - after conv '||l_tare_weight); END IF;
1802
1803 ELSE
1804
1805 NULL;
1806
1807 END IF;
1808
1812
1809 ELSE
1810
1811 l_tare_weight := 0;
1813 END IF;
1814
1815
1816 l_final_wt := l_final_wt + l_gross_weight;
1817 l_final_twt := l_final_twt + l_tare_weight;
1818
1819 if (g_trace_on = 1) then log_event('new l_final_wt '||l_final_wt); END IF;
1820
1821
1822 IF (l_content_volume_uom_code IS NOT NULL) THEN
1823
1824 IF l_std_vol_uom IS NULL THEN
1825
1826 l_std_vol_uom := l_content_volume_uom_code;
1827
1828 ELSIF (l_content_volume_uom_code <> l_std_vol_uom ) THEN
1829
1830 l_vol := inv_convert.inv_um_convert
1831 ( l_item_id,
1832 5,
1833 l_content_volume,
1834 l_content_volume_uom_code,
1835 l_std_vol_uom,
1836 NULL,
1837 null
1838 );
1839
1840 IF( l_vol < 0 ) THEN
1841 if (g_trace_on = 1) then log_event('Error converting UOM from '||l_content_volume_uom_code||' to '||l_std_vol_uom||' qty '||l_content_volume); END IF;
1842 l_content_volume := 0;
1843
1844 ELSE
1845
1846 l_content_volume := l_vol;
1847
1848 END IF;
1849
1850 if (g_trace_on = 1) then log_event(' content_volume - after conv '||l_content_volume); END IF;
1851 ELSE
1852
1853 NULL;
1854
1855 END IF;
1856
1857 ELSE
1858
1859 l_content_volume := 0;
1860
1861 END IF;
1862
1863 l_final_vol := l_final_vol + l_content_volume;
1864 if (g_trace_on = 1) then log_event(' new l_final_vol '||l_final_vol); END IF;
1865
1866 END LOOP;
1867
1868 IF wts_n_vols%isopen then
1869 CLOSE wts_n_vols;
1870 END IF;
1871
1872
1873 l_final_wt := l_final_wt + l_ut_wt;
1874 l_final_twt := l_final_twt + l_ut_wt;
1875
1876 l_final_vol := greatest(l_final_vol, l_ut_vol);
1877
1878 if (g_trace_on = 1) then
1879 log_event(' l_final_wt - at end '||l_final_wt);
1880 log_event(' l_final_vol - at end '||l_final_vol);
1881 END IF;
1882
1883 x_gross_weight := l_final_wt;
1884 x_content_volume := l_final_vol;
1885 x_gross_weight_uom_code := l_std_wt_uom;
1886 x_content_volume_uom_code := l_std_vol_uom;
1887 x_tare_weight := l_final_twt;
1888 x_tare_weight_uom_code := l_std_wt_uom;
1889
1890 pkg_attr_table(p_package_id).inventory_item_id := x_inventory_item_id;
1891 pkg_attr_table(p_package_id).gross_weight := x_gross_weight;
1892 pkg_attr_table(p_package_id).content_volume := x_content_volume;
1893 pkg_attr_table(p_package_id).gross_weight_uom_code := x_gross_weight_uom_code;
1894 pkg_attr_table(p_package_id).content_volume_uom_code := x_content_volume_uom_code;
1895 pkg_attr_table(p_package_id).tare_weight := x_tare_weight;
1896 pkg_attr_table(p_package_id).tare_weight_uom_code := x_tare_weight_uom_code;
1897
1898 END IF;
1899
1900 EXCEPTION
1901 WHEN OTHERS THEN
1902 if (g_trace_on = 1) then log_event('Error Occurred in get Attributes'); END IF;
1903 l_msg := Sqlerrm;
1904 if (g_trace_on = 1) then log_event(l_msg); END IF;
1905
1906 END get_package_attributes;
1907
1908
1909 -- Returns the conatiner item associated with an LPN
1910
1911 FUNCTION get_lpn_Itemid(P_lpn_id IN NUMBER)
1912 return NUMBER
1913 IS
1914 l_ret NUMBER := NULL;
1915 BEGIN
1916 error_code := 'GET_LPN_ITM';
1917 IF( cache_lpn_id = p_lpn_id) THEN
1918
1919 RETURN cache_lpn_item_id;
1920 ELSE
1921
1922 SELECT inventory_item_id
1923 INTO l_ret
1924 FROM wms_license_plate_numbers
1925 WHERE
1926 lpn_id = p_lpn_id;
1927
1928
1929 cache_lpn_id := p_lpn_id;
1930
1931 cache_lpn_item_id := l_ret;
1932 END IF;
1933
1934 RETURN l_ret;
1935
1936 EXCEPTION
1937 WHEN OTHERS THEN
1938 RETURN NULL;
1939 END get_lpn_Itemid;
1940
1941
1942 -- Returns the conatiner item associated with a package
1943
1944 FUNCTION get_PACKAGE_Itemid(P_PACKAGE_id IN NUMBER)
1945 return NUMBER
1946 IS
1947 l_ret NUMBER := NULL;
1948 BEGIN
1949 error_code := 'GET_PKG_ATTR';
1950 IF( cache_package_id = p_package_id) THEN
1951
1952 RETURN cache_pkg_item_id;
1953 ELSE
1954 SELECT PARENT_ITEM_ID
1955 INTO l_ret
1956 FROM WMS_PACKAGING_HIST
1957 WHERE
1958 PARENT_PACKAGE_id = p_PACKAGE_id
1959 AND rownum < 2;
1960
1961
1962 cache_package_id := p_package_id;
1963
1964 cache_pkg_item_id := l_ret;
1965 END IF;
1966
1967
1971 WHEN OTHERS THEN
1968 RETURN l_ret;
1969
1970 EXCEPTION
1972 RETURN NULL;
1973 END get_package_Itemid;
1974
1975
1976 -- This procedure inserts rows into packaging history table
1977
1978 PROCEDURE insert_ph
1979 (p_orig_header_id IN NUMBER,
1980 p_transaction_temp_id IN NUMBER)
1981 IS
1982 l_header_id NUMBER;
1983 l_item_id NUMBER;
1984 l_org_id NUMBER;
1985 l_prim_qty NUMBER;
1986 l_rev VARCHAR2(3);
1987 l_clpn_id VARCHAR2(30);
1988 l_cartonization_id VARCHAR2(30);
1989 l_citem_id NUMBER;
1990 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1991 l_lot_number VARCHAR2(80);
1992 l_serial_number VARCHAR2(30);
1993 counter NUMBER := 0;
1994 v_lot_control_code NUMBER := NULL;
1995 v_serial_control_code NUMBER := NULL;
1996 l_stemp_id NUMBER := NULL;
1997 l_qty NUMBER := NULL;
1998 l_weight NUMBER := NULL;
1999 l_volume NUMBER := NULL;
2000 l_gross_weight NUMBER := NULL;
2001 l_gross_weight_uom_code VARCHAR2(3) := NULL;
2002 l_content_volume NUMBER := NULL;
2003 l_content_volume_uom_code VARCHAR2(3) := NULL;
2004 l_cont_item_id NUMBER := NULL;
2005 l_tare_weight NUMBER := NULL;
2006 l_tare_weight_uom_code VARCHAR2(3) := NULL;
2007
2008
2009 CURSOR lots is
2010 SELECT lot_number, serial_transaction_temp_id, primary_quantity
2011 FROM mtl_transaction_lots_temp
2012 WHERE
2013 transaction_temp_id = p_transaction_temp_id;
2014
2015 CURSOR serials(p_temp_id NUMBER, p_org_id NUMBER, p_item_id NUMBER) is
2016 SELECT msn.serial_number
2017 FROM
2018 mtl_serial_numbers_temp msnt,
2019 mtl_serial_numbers msn
2020 WHERE
2021 msnt.transaction_temp_id = p_temp_id AND
2022 msn.current_organization_id = p_org_id AND
2023 msn.inventory_item_id = p_item_id AND
2024 msn.serial_number >= msnt.fm_serial_number AND
2025 msn.serial_number <= msnt.to_serial_number;
2026
2027 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
2028 TYPE lot_tab_type IS TABLE OF VARCHAR2(80)
2029 INDEX BY binary_integer;
2030 TYPE serial_tab_type IS TABLE OF VARCHAR2(30)
2031 INDEX BY binary_integer;
2032 TYPE qty_tab_type IS TABLE OF NUMBER
2033 INDEX BY binary_integer;
2034
2035 lot_table lot_tab_type;
2036 serial_table serial_tab_type;
2037 qty_table qty_tab_type;
2038 l_temp_id NUMBER;
2039 l_msg VARCHAR2(100);
2040 BEGIN
2041
2042 error_code := 'INSERT_PH';
2043
2044 if (g_trace_on = 1) then log_event('entered insert_ph'); END IF;
2045 SELECT
2046 transaction_header_id,
2047 organization_id,
2048 inventory_item_id,
2049 revision,
2050 primary_quantity,
2051 content_lpn_id,
2052 cartonization_id,
2053 container_item_id
2054 INTO
2055 l_header_id,
2056 l_org_id,
2057 l_item_id,
2058 l_rev,
2059 l_prim_qty,
2060 l_clpn_id,
2061 l_cartonization_id,
2062 l_citem_id
2063 FROM
2064 wms_cartonization_temp
2065 WHERE
2066 transaction_temp_id = p_transaction_temp_id;
2067
2068 IF( p_transaction_temp_id < 0 ) THEN
2069 l_temp_id := NULL;
2070 ELSE
2071 l_temp_id := p_transaction_temp_id;
2072 END IF;
2073
2074
2075
2076 IF l_header_id > 0 THEN
2077
2078 if (g_trace_on = 1) then log_event('header_id > 0'); END IF;
2079
2080 IF l_clpn_id IS NULL THEN
2081
2082 if (g_trace_on = 1) then log_event('content_lpn_id is null'); END IF;
2083
2084 select
2085 lot_control_code,
2086 serial_number_control_code,
2087 Decode(weight_uom_code,NULL,0,nvl(unit_weight,0)),
2088 Decode(volume_uom_code,NULL,0,Nvl(unit_volume,0)),
2089 weight_uom_code,
2090 volume_uom_code
2091 INTO
2092 v_lot_control_code,
2093 v_serial_control_code,
2094 l_weight,
2095 l_volume,
2096 l_gross_weight_uom_code,
2097 l_content_volume_uom_code
2098 from mtl_system_items msi
2099 where
2100 inventory_item_id = l_item_id AND
2101 organization_id = l_org_id;
2102
2103 if (g_trace_on = 1) then
2104 log_event('lot_control_code '||v_lot_control_code );
2105 log_event('serial_control_code '||v_serial_control_code);
2106 END IF;
2107
2108 --Bug 3528061 fix
2109 IF( (outbound = 'Y') AND (g_allocate_serial_flag = 'N')) THEN
2110 if (g_trace_on = 1) then
2111 log_event('outbound and allocate_serial_flag is off');
2112 END IF;
2113 v_serial_control_code := 6;
2114 END IF;
2115 --Bug 3528061 fix
2116
2117 IF (v_lot_control_code = 2 AND v_serial_control_code IN (1,6)) THEN
2118
2119 if (g_trace_on = 1) then log_event(' Lot controlled only '); END IF;
2120 OPEN lots;
2124 EXIT WHEN lots%notfound;
2121 LOOP
2122 FETCH lots INTO l_lot_number, l_stemp_id, l_qty;
2123
2125
2126 counter := counter + 1;
2127 lot_table(counter) := l_lot_number;
2128 serial_table(counter) := NULL;
2129 qty_table(counter) := l_qty;
2130
2131
2132 END LOOP;
2133 IF( lots%isopen) then
2134 CLOSE lots;
2135 END IF;
2136
2137
2138
2139 ELSIF (v_lot_control_code = 1 AND v_serial_control_code NOT IN (1,6)) THEN
2140
2141 if (g_trace_on = 1) then log_event(' Serial controlled only '); END IF;
2142
2143 OPEN serials(p_transaction_temp_id,l_org_id, l_item_id);
2144 LOOP
2145 FETCH serials INTO l_serial_number;
2146
2147 EXIT WHEN serials%notfound;
2148 counter := counter + 1;
2149 lot_table(counter) := NULL;
2150 serial_table(counter) := l_serial_number;
2151 qty_table(counter) := 1;
2152
2153
2154 END LOOP;
2155 IF(serials%isopen) then
2156 CLOSE serials;
2157 END IF;
2158
2159
2160
2161 ELSIF (v_lot_control_code = 2 AND v_serial_control_code NOT IN (1,6)) THEN
2162
2163 if (g_trace_on = 1) then log_event(' Both lot and Serial controlled '); END IF;
2164
2165 OPEN lots;
2166 LOOP
2167 --FETCH lots.serial_transaction_temp_id, lots.lot_number INTO l_stemp_id,l_lot_number;
2168
2169 FETCH lots INTO l_lot_number, l_stemp_id, l_qty;
2170
2171 EXIT WHEN lots%notfound;
2172
2173 OPEN serials(l_stemp_id,l_org_id, l_item_id);
2174 LOOP
2175 FETCH serials INTO l_serial_number;
2176
2177 EXIT WHEN serials%notfound;
2178
2179 counter := counter + 1;
2180 lot_table(counter) := l_lot_number;
2181 serial_table(counter) := l_serial_number;
2182 qty_table(counter) := 1;
2183
2184
2185 END LOOP;
2186 IF(serials%isopen) then
2187 CLOSE serials;
2188 END IF;
2189 END LOOP;
2190
2191 IF lots%isopen then
2192 CLOSE lots;
2193 END IF;
2194
2195
2196 ELSE
2197
2198 if (g_trace_on = 1) then log_event(' No Control Item'); END IF;
2199 counter := counter + 1;
2200
2201 lot_table(counter) := NULL;
2202 serial_table(counter) := NULL;
2203 qty_table(counter) := l_prim_qty;
2204
2205
2206
2207 END IF;
2208
2209
2210 LOOP
2211 EXIT WHEN counter <= 0;
2212
2213 l_gross_weight := l_weight * qty_table(counter);
2214 l_content_volume := l_volume * qty_table(counter);
2215
2216 if (g_trace_on = 1) then
2217 log_event('gross weight '||l_gross_weight);
2218 log_event('content_volume '||l_content_volume);
2219 END IF;
2220
2221 INSERT INTO WMS_PACKAGING_HIST
2222 (
2223 organization_id,
2224 header_id,
2225 sequence_id,
2226 pack_level,
2227 inventory_item_id,
2228 creation_date,
2229 created_by,
2230 last_update_date,
2231 last_updated_by,
2232 last_update_login,
2233 revision,
2234 lot_number,
2235 fm_serial_number,
2236 to_serial_number,
2237 primary_quantity,
2238 PACKAGE_id,
2239 parent_package_id,
2240 lpn_id,
2241 parent_lpn_id,
2242 parent_item_id,
2243 gross_weight,
2244 content_volume,
2245 gross_weight_uom_code,
2246 content_volume_uom_code,
2247 packaging_mode,
2248 reference_id
2249 )
2250 VALUES
2251 (l_org_id,
2252 p_orig_header_id,
2253 wms_cartnzn_pub.g_wms_pack_hist_seq,
2254 pack_level,
2255 l_item_id,
2256 Sysdate,
2257 fnd_global.user_id,
2258 Sysdate,
2259 fnd_global.user_id,
2260 fnd_global.login_id,
2261 l_rev,
2262 lot_table(counter),
2263 serial_table(counter),
2264 serial_table(counter),
2268 null,
2265 qty_table(counter),
2266 null,
2267 l_cartonization_id,
2269 null,
2270 l_citem_id,
2271 l_gross_weight,
2272 l_content_volume,
2273 l_gross_weight_uom_code,
2274 l_content_volume_uom_code,
2275 packaging_mode,
2276 l_temp_id
2277 );
2278
2279 wms_cartnzn_pub.g_wms_pack_hist_seq := wms_cartnzn_pub.g_wms_pack_hist_seq + 1;
2280
2281 counter := counter -1;
2282 END LOOP;
2283
2284
2285 ELSE
2286 --L_CLPN_ID IS NOT NULL
2287
2288 get_lpn_attributes(p_lpn_id => l_clpn_id,
2289 x_inventory_item_id => l_cont_item_id,
2290 x_gross_weight => l_gross_weight,
2291 x_gross_weight_uom_code => l_gross_weight_uom_code,
2292 x_content_volume => l_content_volume,
2293 x_content_volume_uom_code => l_content_volume_uom_code,
2294 x_tare_weight => l_tare_weight,
2295 x_tare_weight_uom_code => l_tare_weight_uom_code
2296 );
2297
2298
2299 INSERT INTO WMS_PACKAGING_HIST
2300 (organization_id,
2301 header_id,
2302 sequence_id,
2303 pack_level,
2304 inventory_item_id,
2305 creation_date,
2306 created_by,
2307 last_update_date,
2308 last_updated_by,
2309 last_update_login,
2310 revision,
2311 lot_number,
2312 fm_serial_number,
2313 to_serial_number,
2314 primary_quantity,
2315 PACKAGE_id,
2316 parent_package_id,
2317 lpn_id,
2318 parent_lpn_id,
2319 parent_item_id,
2320 gross_weight,
2321 content_volume,
2322 gross_weight_uom_code,
2323 content_volume_uom_code,
2324 packaging_mode,
2325 reference_id
2326 )
2327 VALUES
2328 (l_org_id,
2329 p_orig_header_id,
2330 wms_cartnzn_pub.g_wms_pack_hist_seq,
2331 pack_level,
2332 NULL,
2333 Sysdate,
2334 fnd_global.user_id,
2335 Sysdate,
2336 fnd_global.user_id,
2337 fnd_global.login_id,
2338 null,
2339 null,
2340 null,
2341 NULL,
2342 1,
2343 null,
2344 l_cartonization_id,
2345 L_CLPN_ID,
2346 null,
2347 l_citem_id,
2348 l_gross_weight,
2349 l_content_volume,
2350 l_gross_weight_uom_code,
2351 l_content_volume_uom_code,
2352 packaging_mode,
2353 l_temp_id
2354 );
2355 wms_cartnzn_pub.g_wms_pack_hist_seq :=
2356 wms_cartnzn_pub.g_wms_pack_hist_seq + 1;
2357 END IF;
2358
2359 ELSE
2360 --HEADER ID < 0
2361 get_package_attributes(p_org_id => l_org_id,
2362 p_package_id => l_clpn_id,
2363 x_inventory_item_id => l_cont_item_id,
2364 x_gross_weight => l_gross_weight,
2365 x_gross_weight_uom_code => l_gross_weight_uom_code,
2366 x_content_volume => l_content_volume,
2367 x_content_volume_uom_code => l_content_volume_uom_code,
2368 x_tare_weight => l_tare_weight,
2369 x_tare_weight_uom_code => l_tare_weight_uom_code
2370 );
2371
2372
2373
2374 INSERT INTO WMS_PACKAGING_HIST
2375 (organization_id,
2376 header_id,
2377 sequence_id,
2378 pack_level,
2379 inventory_item_id,
2380 creation_date,
2381 created_by,
2382 last_update_date,
2383 last_updated_by,
2384 last_update_login,
2385 revision,
2386 lot_number,
2387 fm_serial_number,
2388 to_serial_number,
2392 lpn_id,
2389 primary_quantity,
2390 PACKAGE_id,
2391 parent_package_id,
2393 parent_lpn_id,
2394 parent_item_id,
2395 gross_weight,
2396 content_volume,
2397 gross_weight_uom_code,
2398 content_volume_uom_code,
2399 packaging_mode,
2400 reference_id,
2401 tare_weight,
2402 tare_weight_uom_code
2403 )
2404 VALUES
2405 (
2406 l_org_id,
2407 p_orig_header_id,
2408 wms_cartnzn_pub.g_wms_pack_hist_seq,
2409 pack_level,
2410 l_cont_item_id,
2411 Sysdate,
2412 fnd_global.user_id,
2413 Sysdate,
2414 fnd_global.user_id,
2415 fnd_global.login_id,
2416 null,
2417 null,
2418 null,
2419 NULL,
2420 1,
2421 l_clpn_id,
2422 l_cartonization_id,
2423 null,
2424 null,
2425 l_citem_id,
2426 l_gross_weight,
2427 l_content_volume,
2428 l_gross_weight_uom_code,
2429 l_content_volume_uom_code,
2430 packaging_mode,
2431 l_temp_id,
2432 l_tare_weight,
2433 l_tare_weight_uom_code
2434 );
2435
2436 wms_cartnzn_pub.g_wms_pack_hist_seq := wms_cartnzn_pub.g_wms_pack_hist_seq + 1;
2437 END IF;
2438
2439 EXCEPTION
2440 WHEN OTHERS THEN
2441 l_msg := Sqlerrm;
2442 if (g_trace_on = 1) then log_event('Exception occurred in insert_ph '||l_msg); END IF;
2443 END insert_ph;
2444
2445
2446 -- This returns the new transaction temp id to be used to insert
2447 -- a row in WCT for packing next level
2448
2449 FUNCTION get_next_temp_id RETURN NUMBER
2450 IS
2451 BEGIN
2452 dummy_temp_id := dummy_temp_id -1;
2453
2454 RETURN dummy_temp_id;
2455
2456 END get_next_temp_id;
2457
2458 -- This returns the new transaction header id to be used to insert
2459 -- a row in WCT for packing next level
2460
2461 FUNCTION get_next_header_id
2462 RETURN NUMBER
2463 IS
2464 BEGIN
2465 dummy_header_id := dummy_header_id -1;
2466
2467 RETURN dummy_header_id;
2468
2469 END get_next_header_id;
2470
2471
2472 -- This returns the next package to be used
2473
2474 FUNCTION get_next_package_id
2475 RETURN NUMBER
2476 IS
2477 l_package_sequence NUMBER;
2478 BEGIN
2479
2480 if (g_trace_on = 1) then log_event(' In get next package id'); END IF;
2481 SELECT wms_packaging_hist_s.nextVal into
2482 l_package_sequence FROM dual;
2483
2484 RETURN l_package_sequence;
2485
2486 END get_next_package_id;
2487
2488
2489
2490 PROCEDURE update_gross_weight(p_header_id IN NUMBER,
2491 p_organization_id IN NUMBER)
2492 IS
2493 CURSOR plpns IS
2494 SELECT
2495 wph.parent_lpn_id,
2496 Decode(wph.tare_weight_uom_code,NULL,0,Nvl(wph.tare_weight,0)) tare_weight,
2497 wph.tare_weight_uom_code
2498 FROM
2499 wms_packaging_hist wph
2500 WHERE
2501 header_id = p_header_id AND
2502 organization_id = p_organization_id AND
2503 parent_lpn_id IS NOT NULL
2504 ORDER BY parent_lpn_id;
2505
2506
2507
2508 prev_lpn NUMBER := -1;
2509 fin_wt NUMBER := 0;
2510 tr_wt NUMBER := 0;
2511 l_lpn_cur_gr_wt NUMBER := NULL;
2512 l_lpn_wt_from_db NUMBER := 0;
2513 gr_wt_uom_code VARCHAR2(3) := NULL;
2514 l_wt_uom_from_db VARCHAR2(3) := NULL;
2515
2516 l_api_return_status VARCHAR2(1);
2517 l_msg_count NUMBER;
2518 l_msg_data VARCHAR2(2000);
2519
2520 l_lpn_rec WMS_CONTAINER_PUB.lpn;
2521
2522 BEGIN
2523
2524 error_code := 'UPD_GR_WT';
2525
2526
2527
2528 FOR lpn_cur IN plpns LOOP
2529
2530 if (g_trace_on = 1) then log_event('calculating gr wt for lpn '||lpn_cur.parent_lpn_id); END IF;
2531
2532 tr_wt := 0;
2533
2537
2534 IF( lpn_cur.parent_lpn_id <> prev_lpn ) THEN
2535
2536 IF( prev_lpn <> -1) THEN
2538 if (g_trace_on = 1) then
2539 log_event('adding to gross wt '||fin_wt);
2540 log_event(' for the lpn '|| prev_lpn);
2541 END IF;
2542
2543 SELECT gross_weight
2544 , gross_weight_uom_code
2545 INTO l_lpn_wt_from_db
2546 , l_wt_uom_from_db
2547 FROM wms_license_plate_numbers
2548 WHERE lpn_id = prev_lpn;
2549
2550 l_lpn_rec.lpn_id := prev_lpn;
2551 l_lpn_rec.gross_weight := NVL(l_lpn_wt_from_db,0) + fin_wt;
2552 l_lpn_rec.gross_weight_uom_code := NVL(l_wt_uom_from_db,gr_wt_uom_code);
2553
2554 l_api_return_status := fnd_api.g_ret_sts_success;
2555 wms_container_pvt.modify_lpn
2556 ( p_api_version => 1.0
2557 , p_init_msg_list => fnd_api.g_false
2558 , p_commit => fnd_api.g_false
2559 , p_validation_level => fnd_api.g_valid_level_full
2560 , x_return_status => l_api_return_status
2561 , x_msg_count => l_msg_count
2562 , x_msg_data => l_msg_data
2563 , p_lpn => l_lpn_rec
2564 , p_caller => 'WMS_LPNMGMT'
2565 );
2566
2567 IF l_api_return_status <> fnd_api.g_ret_sts_success
2568 THEN
2569 IF g_trace_on = 1 THEN
2570 log_event('Error from wms_container_pvt.modify_lpn: ' || l_msg_data);
2571 END IF;
2572 RAISE FND_API.G_EXC_ERROR;
2573 ELSE
2574 IF g_trace_on = 1 THEN
2575 log_event('LPN gross weight updated');
2576 END IF;
2577 END IF;
2578 END IF;
2579
2580
2581 SELECT gross_weight_uom_code, gross_weight INTO
2582 gr_wt_uom_code, l_lpn_cur_gr_wt
2583 FROM wms_license_plate_numbers
2584 WHERE lpn_id = lpn_cur.parent_lpn_id;
2585
2586 prev_lpn := lpn_cur.parent_lpn_id ;
2587
2588 fin_wt := 0;
2589 END IF;
2590
2591
2592 IF ( lpn_cur.tare_weight <> 0 ) THEN
2593
2594 IF (lpn_cur.tare_weight_uom_code IS NOT NULL) THEN
2595
2596 IF gr_wt_uom_code IS NULL THEN
2597
2598 if (g_trace_on = 1) then log_event('lpn has null uom'); END IF;
2599
2600 gr_wt_uom_code := lpn_cur.tare_weight_uom_code;
2601
2602 IF l_lpn_cur_gr_wt IS NOT NULL OR l_lpn_cur_gr_wt > 0 THEN
2603 if (g_trace_on = 1) then log_event('INCONSISTENT LPN DATA - WEIGHT without UOM'); END IF;
2604 END IF;
2605
2606 tr_wt := lpn_cur.tare_weight;
2607
2608 ELSIF (lpn_cur.tare_weight_uom_code <> gr_wt_uom_code) THEN
2609
2610 tr_wt := inv_convert.inv_um_convert
2611 ( null,
2612 5,
2613 lpn_cur.tare_weight,
2614 lpn_cur.tare_weight_uom_code,
2615 gr_wt_uom_code,
2616 NULL,
2617 null
2618 );
2619
2620 IF( tr_wt < 0 ) THEN
2621 if (g_trace_on = 1) then log_event('Error converting UOM from '||lpn_cur.tare_weight_uom_code||' to '||gr_wt_uom_code||' qty '||lpn_cur.tare_weight); END IF;
2622 tr_wt := 0;
2623 END IF;
2624
2625 ELSE
2626 tr_wt := lpn_cur.tare_weight;
2627 END IF;
2628
2629 if (g_trace_on = 1) then log_event(' tare_weight - after conv '||tr_wt); END IF;
2630
2631 IF( tr_wt > 0) THEN
2632 fin_wt := fin_wt + tr_wt;
2633 END IF;
2634
2635 END IF; -- lpn_cur.tare weight uom code is not null
2636
2637 END IF; --lpn_cur.tare_weight <> 0
2638
2639 END LOOP;
2640
2641 IF( (fin_wt) > 0 AND (prev_lpn IS NOT NULL) AND (prev_lpn > 0) ) THEN
2642
2643 if (g_trace_on = 1) then
2644 log_event('adding to gross wt '||fin_wt);
2645 log_event(' for the lpn '|| prev_lpn);
2646 END IF;
2647
2648 SELECT gross_weight
2649 , gross_weight_uom_code
2650 INTO l_lpn_wt_from_db
2651 , l_wt_uom_from_db
2652 FROM wms_license_plate_numbers
2653 WHERE lpn_id = prev_lpn;
2654
2655 l_lpn_rec.lpn_id := prev_lpn;
2656 l_lpn_rec.gross_weight := NVL(l_lpn_wt_from_db,0) + fin_wt;
2657 l_lpn_rec.gross_weight_uom_code := NVL(l_wt_uom_from_db,gr_wt_uom_code);
2658
2659 l_api_return_status := fnd_api.g_ret_sts_success;
2660 wms_container_pvt.modify_lpn
2661 ( p_api_version => 1.0
2662 , p_init_msg_list => fnd_api.g_false
2663 , p_commit => fnd_api.g_false
2664 , p_validation_level => fnd_api.g_valid_level_full
2665 , x_return_status => l_api_return_status
2666 , x_msg_count => l_msg_count
2667 , x_msg_data => l_msg_data
2668 , p_lpn => l_lpn_rec
2672 IF l_api_return_status <> fnd_api.g_ret_sts_success
2669 , p_caller => 'WMS_LPNMGMT'
2670 );
2671
2673 THEN
2674 IF g_trace_on = 1 THEN
2675 log_event('Error from wms_container_pvt.modify_lpn: ' || l_msg_data);
2676 END IF;
2677 RAISE FND_API.G_EXC_ERROR;
2678 ELSE
2679 IF g_trace_on = 1 THEN
2680 log_event('LPN gross weight updated');
2681 END IF;
2682 END IF;
2683 END IF;
2684
2685 EXCEPTION
2686 WHEN OTHERS THEN
2687 if (g_trace_on = 1) then log_event('error occurred in update gross weight'); END IF;
2688 END update_gross_weight;
2689
2690
2691 -- This function can be obsoeleted if u use a connect by at the caller
2692
2693 PROCEDURE get_parent(p_child IN NUMBER,
2694 x_par_cart_id OUT NOCOPY NUMBER,
2695 x_par_cont_id OUT NOCOPY NUMBER) IS
2696 BEGIN
2697 error_code := 'GET_PAR';
2698 if (g_trace_on = 1) then log_event(' Enter get_parent for child '||p_child); END IF;
2699
2700 SELECT cartonization_id, container_item_id
2701 INTO
2702 x_par_cart_id, x_par_cont_id
2703 FROM wms_cartonization_temp
2704 WHERE
2705 content_lpn_id = p_child AND
2706 transaction_header_id < 0;
2707
2708 if (g_trace_on = 1) then
2709 log_event(' cartonization_id '||x_par_cart_id);
2710 log_event(' container_item_id'||x_par_cont_id);
2711 END IF;
2712
2713 EXCEPTION
2714 WHEN OTHERS THEN
2715 x_par_cart_id := NULL;
2716 x_par_cont_id := NULL;
2717 if (g_trace_on = 1) then
2718 log_event(' cartonization_id '||x_par_cart_id);
2719 log_event(' container_item_id'||x_par_cont_id);
2720 END IF;
2721 END get_parent;
2722
2723
2724 -- This procedure is called to generate lpns for the outermost
2725 -- packages used to pack a mmtt line
2726
2727 PROCEDURE generate_lpns( P_header_id IN NUMBER,
2728 p_organization_id IN NUMBER)
2729 IS
2730 orig_temp_id NUMBER := NULL;
2731 cart_id NUMBER := NULL;
2732 cont_id NUMBER := NULL;
2733 par_cart_id NUMBER := NULL;
2734 par_cont_id NUMBER := NULL;
2735 l_return_status VARCHAR2(1);
2736 l_msg_data varchar2(255);
2737 l_msg_count NUMBER;
2738 v_lpn_id_out NUMBER;
2739 v_process_id NUMBER;
2740 v_lpn_out VARCHAR2(30);
2741 par_lpn_id NUMBER := NULL;
2742
2743
2744 CURSOR bpack_rows IS
2745 SELECT
2746 transaction_temp_id,
2747 cartonization_id,
2748 CONTAINER_ITEM_ID
2749 FROM
2750 wms_cartonization_temp
2751 WHERE
2752 transaction_header_id = p_header_id
2753 --Bug 2864774 fix
2754 ORDER BY cartonization_id;
2755 CURSOR obound_rows IS
2756 SELECT
2757 wct.transaction_temp_id,
2758 wct.cartonization_id,
2759 wct.CONTAINER_ITEM_ID
2760 FROM
2761 wms_cartonization_temp wct,
2762 mtl_txn_request_lines mtrl
2763 WHERE
2764 wct.move_order_line_id = mtrl.line_id AND
2765 mtrl.header_id = p_header_id AND
2766 wct.transaction_header_id >= 0 -- AND
2767 -- wct.container_item_id IS NOT NULL --ER : 6682436
2768 -- Bug 3876178
2769 ORDER BY cartonization_id;
2770
2771
2772
2773 BEGIN
2774
2775 error_code := 'GEN_LPNS';
2776
2777 if (g_trace_on = 1) then log_event('In generated_LPNs '); END IF;
2778 if (g_trace_on = 1) then log_event('OUTBOUND : '||outbound); END IF;
2779
2780 IF outbound = 'N' THEN
2781 OPEN bpack_rows;
2782 ELSE
2783 OPEN obound_rows;
2784 if (g_trace_on = 1) then log_event('opening outbound rows.'); END IF;
2785 END IF;
2786
2787
2788 LOOP
2789
2790
2791 IF outbound = 'N' THEN
2792 FETCH bpack_rows INTO orig_temp_id, cart_id, cont_id;
2793 EXIT WHEN bpack_rows%notfound;
2794 ELSE
2795 FETCH obound_rows INTO orig_temp_id, cart_id, cont_id;
2796 if (g_trace_on = 1) then log_event('Fetch suceeded'); END IF;
2797 EXIT WHEN obound_rows%notfound;
2798 END IF;
2799
2800 IF cart_id IS NOT NULL THEN
2801
2802 -- can potentially use a connect by here
2803 LOOP
2804
2805 get_parent(p_child => cart_id,
2806 x_par_cart_id => par_cart_id,
2807 x_par_cont_id => par_cont_id);
2808
2809 EXIT WHEN par_cart_id IS NULL;
2810
2811 cart_id := par_cart_id;
2812 cont_id := par_cont_id;
2813
2814 END LOOP;
2815
2816
2817 par_lpn_id := NULL;
2818
2819
2820 BEGIN
2821 SELECT parent_lpn_id INTO par_lpn_id
2822 FROM wms_packaging_hist
2823 WHERE
2824 parent_package_id = cart_id AND
2825 header_id = p_header_id AND
2829 par_lpn_id := NULL;
2826 ROWNUM < 2;
2827 EXCEPTION
2828 WHEN others THEN
2830 END;
2831
2832 l_return_status := fnd_api.g_ret_sts_success;
2833
2834 IF par_lpn_id IS NULL THEN
2835
2836
2837 wms_container_pub.generate_lpn( p_api_version => 1.0,
2838 p_validation_level => fnd_api.g_valid_level_none,
2839 x_return_status => l_return_status,
2840 x_msg_count => l_msg_count,
2841 x_msg_data => l_msg_data,
2842 p_organization_id => p_organization_id,
2843 p_container_item_id => cont_id,
2844 p_lpn_id_out => v_lpn_id_out,
2845 p_lpn_out => v_lpn_out,
2846 p_process_id => v_process_id
2847 );
2848
2849 if (g_trace_on = 1) then log_event('generated LPN '||v_lpn_out); END IF;
2850
2851 ELSE
2852
2853 if (g_trace_on = 1) then log_event('lpn already generated '||par_lpn_id); END IF;
2854 v_lpn_id_out := par_lpn_id;
2855
2856 END IF;
2857
2858
2859
2860 IF( l_return_status <> fnd_api.g_ret_sts_success ) THEN
2861
2862 if (g_trace_on = 1) then log_event('ERROR generating the lpns '||l_return_status); END IF;
2863 RAISE fnd_api.g_exc_unexpected_error;
2864
2865 ELSE
2866 UPDATE wms_cartonization_temp
2867 SET
2868 cartonization_id = v_lpn_id_out,
2869 container_item_id = cont_id
2870 WHERE
2871 transaction_temp_id = orig_temp_id;
2872
2873 if (g_trace_on = 1) then log_event('updated wms_cartonization_temp for temp id '||orig_temp_id); END IF;
2874
2875
2876 UPDATE WMS_PACKAGING_HIST
2877 SET parent_lpn_id = v_lpn_id_out
2878 --parent_package_id = NULL
2879 WHERE
2880 parent_package_id = cart_id;
2881
2882 if (g_trace_on = 1) then log_event('updated WMS_PACKAGING_HIST for package_id '||cart_id); END IF;
2883
2884
2885
2886 END IF; -- l_return_status <> fnd_api.g_ret_sts_success
2887
2888 END IF;--cart_id IS NOT NULL
2889
2890 END LOOP;
2891
2892
2893 IF outbound = 'N' THEN
2894 IF( bpack_rows%isopen) then
2895 CLOSE bpack_rows;
2896 END IF;
2897
2898 ELSE
2899
2900 IF obound_rows%isopen then
2901 CLOSE obound_rows;
2902 END IF;
2903
2904 END IF;
2905
2906 if (g_trace_on = 1) then log_event('updating packaging history'); END IF;
2907
2908 UPDATE wms_packaging_hist
2909 SET parent_package_id = NULL
2910 WHERE
2911 parent_lpn_id IS NOT NULL AND
2912 parent_package_id IS NOT NULL AND
2913 header_id = p_header_id;
2914
2915 IF packaging_mode <> wms_cartnzn_pub.PR_pKG_mode THEN
2916 --need not be called in pick release mode
2917 update_gross_weight(p_header_id,p_organization_id);
2918 END IF;
2919
2920 END generate_lpns;
2921
2922
2923
2924
2925
2926
2927
2928 PROCEDURE split_lot_serials ( p_organization_id IN NUMBER)
2929 IS
2930 l_counter NUMBER := NULL;
2931 v_allocate_serial_flag VARCHAR2(1) := NULL;
2932 v_lot_control_code NUMBER := NULL;
2933 v_serial_control_code NUMBER := NULL;
2934 curr_temp_id NUMBER := NULL;
2935 api_table_index NUMBER := 0;
2936 l_temporary_temp_id NUMBER := NULL;
2937 BEGIN
2938
2939 error_code := 'SPLT_LOT_SER';
2940
2941
2942 if (g_trace_on = 1) then log_event('Entered split_lot_serial '); END IF;
2943 l_counter := 1;
2944
2945 --Bug 3528061
2946 IF outbound = 'N' THEN
2947 v_allocate_serial_flag := 'Y';
2948 ELSE
2949 v_allocate_serial_flag := g_allocate_serial_flag;
2950 END IF;
2951
2952 if (g_trace_on = 1) then log_event('size of the temp table is '||temp_id_table_index); END IF;
2953
2954 LOOP
2955 EXIT WHEN l_counter > temp_id_table_index;
2956
2957 if (g_trace_on = 1) then log_event('counter '||l_counter); END IF;
2958
2959 IF temp_id_table(l_counter).processed <> 'Y' THEN
2960
2961 --log_event(' processing '||l_counter);
2962
2963 curr_temp_id := temp_id_table(l_counter).orig_temp_id;
2964
2965 if (g_trace_on = 1) then log_event('processsing temp_id '||curr_temp_id); END IF;
2966
2967 select msi.lot_control_code, msi.serial_number_control_code
2968 INTO v_lot_control_code, v_serial_control_code
2969 from mtl_system_items msi where
2970 (msi.inventory_item_id, msi.organization_id) =
2971 (
2972 select mmtt.inventory_item_id, mmtt.organization_id from
2976 IF( (v_allocate_serial_flag IS NULL) OR
2973 wms_cartonization_temp mmtt WHERE mmtt.transaction_temp_id = curr_temp_id
2974 );
2975
2977 (v_allocate_serial_flag = 'N') ) THEN
2978 v_serial_control_code := 6;
2979 END IF;
2980
2981 api_table.delete;
2982
2983 api_table_index := 0;
2984
2985 /* Hack for sony */
2986 api_table_index := api_table_index + 1;
2987
2988 SELECT mtl_material_transactions_s.NEXTVAL INTO
2989 api_table(api_table_index).transaction_id
2990 FROM dual;
2991
2992 SELECT primary_quantity ,secondary_transaction_quantity INTO
2993 api_table(api_table_index).primary_quantity,
2994 api_table(api_table_index).secondary_quantity
2995 FROM
2996 wms_cartonization_temp
2997 WHERE
2998 transaction_temp_id = curr_temp_id;
2999
3000 l_temporary_temp_id := api_table(api_table_index).transaction_id;
3001
3002 /* Hack for sony */
3003
3004
3005 if (g_trace_on = 1) then log_event(api_table_index||'*'||api_table(api_table_index).transaction_id||'*'||api_table(api_table_index).primary_quantity); END IF;
3006
3007 FOR l_counter2 IN 1..temp_id_table.COUNT LOOP
3008
3009 IF temp_id_table(l_counter2).orig_temp_id = curr_temp_id THEN
3010
3011 api_table_index := api_table_index + 1;
3012
3013 api_table(api_table_index).transaction_id := temp_id_table(l_counter2).splt_temp_id;
3014 api_table(api_table_index).primary_quantity := temp_id_table(l_counter2).primary_quantity;
3015 api_table(api_table_index).secondary_quantity := temp_id_table(l_counter2).secondary_quantity;
3016 temp_id_table(l_counter2).processed := 'Y';
3017
3018 if (g_trace_on = 1) then log_event(api_table_index||'*'||api_table(api_table_index).transaction_id||'*'||api_table(api_table_index).primary_quantity); END IF;
3019 END IF;
3020
3021 END LOOP;
3022
3023 IF api_table_index > 0 THEN
3024 --Setting the variable to order lots by creation date
3025 inv_rcv_common_apis.g_order_lots_by := inv_rcv_common_apis.g_order_lots_by_creation_date;
3026
3027 inv_rcv_common_apis.break
3028 (p_original_tid => curr_temp_id,
3029 p_new_transactions_tb => api_table,
3030 p_lot_control_code => v_lot_control_code,
3031 p_serial_control_code => v_serial_control_code);
3032
3033 --Setting it back to default
3034 inv_rcv_common_apis.g_order_lots_by := inv_rcv_common_apis.g_order_lots_by_exp_date;
3035 END IF;
3036
3037 /* Hack for sony */
3038 UPDATE mtl_transaction_lots_temp
3039 SET
3040 transaction_temp_id = curr_temp_id
3041 WHERE
3042 transaction_temp_id = l_temporary_temp_id;
3043 /* Hack for sony */
3044
3045 END IF; --end for processed <> 'Y'
3046
3047
3048 --log_event( l_counter||'-'||temp_id_table(l_counter).orig_temp_id
3049 -- ||'-'||temp_id_table(l_counter).splt_temp_id
3050 -- );
3051 l_counter := l_counter + 1;
3052 END LOOP;
3053
3054 api_table.delete;
3055
3056 api_table_index := 0;
3057
3058 temp_id_table.DELETE;
3059
3060 temp_id_table_index := 0;
3061
3062 END split_lot_serials;
3063
3064
3065 --Bug 2478970 fix
3066
3067 FUNCTION validate_cont_item(p_item_id IN NUMBER,
3068 p_org_id IN NUMBER)
3069 RETURN VARCHAR2
3070 IS
3071 l_ret VARCHAR2(1) := 'Y';
3072 BEGIN
3073
3074 IF p_item_id IS NULL OR
3075 p_org_id IS NULL THEN
3076 RETURN 'N';
3077 END IF;
3078
3079 SELECT 'Y' INTO l_ret
3080 FROM dual WHERE exists
3081 (SELECT inventory_item_id
3082 FROM MTL_SYSTEM_ITEMS
3083 WHERE ORGANIZATION_ID = p_org_id
3084 AND INVENTORY_ITEM_ID = p_item_id
3085 AND mtl_transactions_enabled_flag = 'Y'
3086 AND enabled_flag = 'Y');
3087
3088 RETURN L_RET;
3089 EXCEPTION
3090 WHEN no_data_found THEN
3091 RETURN 'N';
3092 WHEN OTHERS THEN
3093 RETURN 'N';
3094 END validate_cont_item;
3095
3096 --**************************************
3097 -- patchset J bulk picking
3098 --
3099 -- API name : AssignTT
3100 -- Type : Private
3101 -- Function : Assign task type to records in MMTT
3102 -- Input Parameters :
3103 --
3104 -- Output Parameters:
3105 -- Version :
3106 -- Current version 1.0
3107 --
3108 -- Notes : calls AssignTT(p_task_id NUMBER)
3109 --
3110 -- This procedure loops through mtl_material_transactions_temp table, assign
3111 -- user defined task type to tasks that have not been assigned a task type
3112 -- for the given Move Order Header.
3113 -- This API is created when doing patchset J bulk picking
3117 PROCEDURE assigntts(
3114 -- ****************************************
3115
3116
3118 p_api_version IN NUMBER
3119 , p_init_msg_list IN VARCHAR2 :=fnd_api.g_false
3120 , p_commit IN VARCHAR2 :=fnd_api.g_false
3121 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
3122 , x_return_status OUT NOCOPY VARCHAR2
3123 , x_msg_count OUT NOCOPY NUMBER
3124 , x_msg_data OUT NOCOPY VARCHAR2
3125 , p_move_order_header_id IN NUMBER
3126 ) IS
3127
3128
3129 CURSOR c_tasks IS
3130 SELECT transaction_temp_id
3131 FROM wms_cartonization_temp wct
3132 WHERE
3133 parent_line_id is null or -- non bulked records
3134 parent_line_id = transaction_temp_id; -- parents only
3135
3136 Cursor c_tasks_con is
3137 Select transaction_temp_id
3138 From wms_cartonization_temp
3139 Where parent_line_id = transaction_temp_id;
3140
3141
3142 l_task_id NUMBER;
3143 l_return_status VARCHAR2(1);
3144 l_msg_count NUMBER;
3145 l_msg_data VARCHAR2(2000);
3146 l_api_name VARCHAR2(30) := 'assignTTs';
3147 BEGIN
3148 -- Initialize API return status to success
3149 x_return_status := fnd_api.g_ret_sts_success;
3150 IF p_move_order_header_id <> -1 THEN
3151 OPEN c_tasks;
3152 ELSE OPEN c_tasks_con;
3153 END IF;
3154
3155 LOOP
3156 IF p_move_order_header_id <> -1 THEN
3157 FETCH c_tasks INTO l_task_id;
3158 EXIT WHEN c_tasks%NOTFOUND;
3159 ELSE
3160 FETCH c_tasks_con INTO l_task_id;
3161 EXIT WHEN c_tasks_con%NOTFOUND;
3162 END IF;
3163 wms_rule_pvt.assigntt(
3164 p_api_version => 1.0
3165 , p_task_id => l_task_id
3166 , x_return_status => l_return_status
3167 , x_msg_count => l_msg_count
3168 , x_msg_data => l_msg_data
3169 );
3170
3171 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3172 x_return_status := fnd_api.g_ret_sts_error;
3173 END IF;
3174 END LOOP;
3175 IF p_move_order_header_id <> -1 THEN
3176 CLOSE c_tasks;
3177 ELSE
3178 CLOSE c_tasks_con;
3179 END IF;
3180 EXCEPTION
3181 WHEN OTHERS THEN
3182 x_return_status := fnd_api.g_ret_sts_unexp_error;
3183 END assigntts;
3184
3185
3186 -- Stop level
3187 -- if specified as zero - cartonizes till the levels setup
3188
3189 PROCEDURE cartonize(
3190 p_api_version IN NUMBER,
3191 p_init_msg_list IN VARCHAR2 :=fnd_api.g_false,
3192 p_commit IN VARCHAR2 :=fnd_api.g_false,
3193 p_validation_level IN NUMBER :=fnd_api.g_valid_level_full,
3194 x_return_status OUT NOCOPY VARCHAR2,
3195 x_msg_count OUT NOCOPY NUMBER,
3196 x_msg_data OUT NOCOPY VARCHAR2,
3197 p_out_bound IN VARCHAR2,
3198 p_org_id IN NUMBER,
3199 p_move_order_header_id IN NUMBER,
3200 p_disable_cartonization IN VARCHAR2,
3201 p_transaction_header_id IN NUMBER,
3202 p_stop_level IN NUMBER,
3203 p_packaging_mode IN NUMBER,
3204 p_input_for_bulk IN WMS_BULK_PICK.bulk_input_rec DEFAULT null
3205 ) IS
3206
3207 l_api_name CONSTANT VARCHAR2(30) := 'cartonize';
3208 l_api_version CONSTANT NUMBER := 1.0;
3209
3210
3211 v1 WCT_ROW_TYPE;
3212
3213 cartonization_profile VARCHAR2(1) := 'Y';
3214 v_cart_value NUMBER;
3215 v_container_item_id NUMBER:= NULL;
3216 v_qty NUMBER:= -1;
3217 v_qty_per_cont NUMBER := -1;
3218 v_tr_qty_per_cont NUMBER:= -1;
3219 v_sec_tr_qty_per_cont NUMBER:= -1; --invconv kkillams
3220 v_lpn_out VARCHAR2(30) := ' ';
3221 v_primary_uom_code VARCHAR2(3);
3222 v_loop NUMBER := 0;
3223 v_process_id NUMBER := 0;
3224 v_ttemp_id NUMBER := 0;
3225 v_lpn_id_out NUMBER := 0;
3226 v_lpn_id NUMBER := 0;
3227 ret_value NUMBER := 29;
3228 v_return_status VARCHAR2(1);
3229 v_left_prim_quant NUMBER;
3230 v_left_tr_quant NUMBER;
3231 v_sec_left_tr_quant NUMBER; --invconv kkillams
3232 v_sublvlctrl VARCHAR2(1) := '2';
3233 --Bug 2720653 fix
3234 --l_lpn_id_tbl inv_label.transaction_id_rec_type;
3238 l_progress VARCHAR2(10);
3235 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
3236 l_msg_count NUMBER;
3237 l_msg_data VARCHAR2(400);
3239 l_label_status VARCHAR2(500);
3240 l_counter NUMBER := 0;
3241 v_prev_move_order_line_id NUMBER := 0;
3242 space_avail_for NUMBER := 0;
3243 tr_space_avail_for NUMBER := 0;
3244 sec_tr_space_avail_for NUMBER := 0; --invconv kkillams
3245 curr_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE ;
3246 v_lot_control_code NUMBER := NULL;
3247 v_serial_control_code NUMBER := NULL;
3248 api_table_index NUMBER := 0;
3249 l_current_header_id NUMBER := NULL;
3250 l_stop_level NUMBER := -1;
3251 v_prev_item_id NUMBER := NULL;
3252 l_prev_package_id NUMBER := NULL;
3253 l_temp_id NUMBER := NULL;
3254 l_item_id NUMBER := NULL;
3255 l_qty NUMBER := NULL;
3256 l_tr_qty NUMBER := NULL;
3257 l_sec_tr_qty NUMBER := NULL;
3258 l_clpn_id NUMBER := NULL;
3259 l_citem_id NUMBER := NULL;
3260 l_package_id NUMBER := NULL;
3261 l_upd_qty_flag VARCHAR2(1) := NULL;
3262 l_prev_header_id NUMBER := NULL;
3263 l_header_id NUMBER := NULL;
3264 L_no_pkgs_gen VARCHAR2(1);
3265 l_prev_condition VARCHAR2(1);
3266 l_revision_code VARCHAR2(1);
3267 l_lot_code VARCHAR2(1);
3268 l_serial_code VARCHAR2(1);
3269 l_is_revision_control BOOLEAN;
3270 l_is_lot_control BOOLEAN;
3271 l_is_serial_control BOOLEAN;
3272 l_rqoh NUMBER;
3273 l_qr NUMBER;
3274 l_qs NUMBER;
3275 l_atr NUMBER;
3276 l_att NUMBER;
3277 l_qoh NUMBER;
3278 l_lpn_fully_allocated VARCHAR2(1) :='N';
3279 l_autocreate_delivery_flag VARCHAR2(1) := 'N';
3280 percent_fill_basis VARCHAR2(1) :='W';
3281 l_valid_container VARCHAR2(1) := 'Y';
3282
3283 l_cartonize_sales_orders VARCHAR2(1) :=NULL;
3284 l_cartonize_manufacturing VARCHAR2(1) :=NULL;
3285 l_move_order_type NUMBER;
3286
3287 l_rulebased_setup_exists NUMBER := 0;
3288 l_api_return_status VARCHAR2(1);
3289 l_count1 NUMBER;
3290
3291 CURSOR wct_rows IS
3292 SELECT wct.* FROM wms_cartonization_temp wct,
3293 mtl_txn_request_lines mtrl,
3294 mtl_secondary_inventories sub,
3295 mtl_parameters mtlp
3296 WHERE
3297 wct.move_order_line_id =mtrl.line_id
3298 AND mtrl.header_id = p_move_order_header_id
3299 AND wct.cartonization_id IS null
3300 AND mtlp.organization_id = wct.organization_id
3301 AND sub.organization_id = wct.organization_id
3302 -- AND wct.cartonization_id IS NULL
3303 AND wct.transfer_lpn_id IS NULL
3304 AND sub.secondary_inventory_name = wct.subinventory_code
3305 AND( (Nvl(mtlp.cartonization_flag,-1) = 1) OR
3306 (Nvl(mtlp.cartonization_flag,-1) = 3
3307 AND sub.cartonization_flag = 1))
3308 ORDER BY wct.move_order_line_id,
3309 wct.inventory_item_id, Abs(wct.transaction_temp_id);
3310
3311
3312
3313 CURSOR OB_LBPRT IS
3314 SELECT DISTINCT mmtt.cartonization_id FROM
3315 --2513907 fix
3316 wms_cartonization_temp mmtt,
3317 --mtl_material_transactions_temp mmtt,
3318 mtl_txn_request_lines mtrl WHERE
3319 mmtt.move_order_line_id = mtrl.line_id
3320 AND mtrl.header_id = p_move_order_header_id
3321 AND mmtt.cartonization_id IS NOT NULL
3322 ORDER BY mmtt.cartonization_id;
3323
3324 CURSOR IB_LBPRT IS
3325 SELECT DISTINCT mmtt.cartonization_id FROM
3326 --2513907 fix
3327 wms_cartonization_temp mmtt
3328 --mtl_material_transactions_temp mmtt
3329 WHERE
3333
3330 mmtt.transaction_header_id = p_transaction_header_id
3331 AND mmtt.cartonization_id IS NOT NULL
3332 ORDER BY mmtt.cartonization_id;
3334 /*
3335 CURSOR bpack_rows(p_hdr_id NUMBER) IS
3336 SELECT * FROM
3337 wms_cartonization_temp
3338 WHERE
3339 transaction_header_id = p_hdr_id
3340 AND cartonization_id IS NULL
3341 AND transfer_lpn_id IS NULL
3342 order by move_order_line_id,
3343 decode(content_lpn_id,null,inventory_item_id,
3344 decode(sign(p_hdr_id),
3345 -1,
3346 wms_cartnzn_pub.Get_package_ItemId(content_lpn_id),
3347 wms_cartnzn_pub.Get_LPN_ItemId(content_lpn_id)
3348 ) ); */
3349
3350
3351 CURSOR bpack_rows(p_hdr_id NUMBER) IS
3352 SELECT * FROM
3353 wms_cartonization_temp
3354 WHERE
3355 transaction_header_id = p_hdr_id
3356 AND cartonization_id IS NULL
3357 AND transfer_lpn_id IS NULL
3358 order by move_order_line_id,
3359 decode(content_lpn_id,null,inventory_item_id,
3360 decode(sign(p_hdr_id),
3361 -1,
3362 inventory_item_id,
3363 wms_cartnzn_pub.Get_LPN_ItemId(content_lpn_id)
3364 ) ),Abs(transaction_temp_id);
3365
3366
3367 CURSOR packages(p_hdr_id NUMBER) IS
3368 SELECT
3369 transaction_temp_id,
3370 inventory_item_id,
3371 primary_quantity,
3372 transaction_quantity,
3373 secondary_transaction_quantity, --invconv kkillams
3374 content_lpn_id,
3375 container_item_id,
3376 cartonization_id
3377 FROM
3378 wms_cartonization_temp
3379 WHERE
3380 transaction_header_id = p_hdr_id
3381 order by cartonization_id;
3382
3383 CURSOR opackages(p_hdr_id NUMBER) IS
3384 SELECT
3385 wct.transaction_temp_id,
3386 wct.inventory_item_id,
3387 wct.primary_quantity,
3388 wct.transaction_quantity,
3389 wct.secondary_transaction_quantity, --invconv kkillams
3390 wct.content_lpn_id,
3391 wct.container_item_id,
3392 wct.cartonization_id
3393 FROM
3394 wms_cartonization_temp wct,
3395 mtl_txn_request_lines mtrl
3396 WHERE
3397 wct.move_order_line_id = mtrl.line_id AND
3398 mtrl.header_id = p_hdr_id
3399 order by wct.cartonization_id;
3400
3401 BEGIN
3402
3403 error_code := 'CARTONIZE 10';
3404
3405 SAVEPOINT cartonize_pub;
3406 IF (NOT fnd_api.compatible_api_call ( l_api_version,
3407 p_api_version,
3408 l_api_name,
3409 g_pkg_name )) THEN
3410 RAISE fnd_api.g_exc_error;
3411 END IF;
3412
3413 IF (fnd_api.to_boolean ( p_init_msg_list )) THEN
3414 fnd_msg_pub.initialize;
3415 END IF;
3416
3417 x_return_status := fnd_api.g_ret_sts_success;
3418
3419 --setting the global variable for trace
3420 g_trace_on := fnd_profile.value('INV_DEBUG_TRACE');
3421
3422 log_event('G_CURRENT_RELEASE_LEVEL : '||G_CURRENT_RELEASE_LEVEL);
3423
3424 if (g_trace_on = 1) then
3425 log_event('Table_name is '||table_name);
3426
3427 log_event('Deleting rows in wms_cartonization_temp');
3428 END IF;
3429
3430 --making sure that we are starting with an empty table
3431 DELETE wms_cartonization_temp;
3432
3433 pkg_attr_table.DELETE;
3434 lpn_attr_table.DELETE;
3435 lpns_generated_tb.DELETE;
3436
3437 -- Setting the global variable for packaging
3438 packaging_mode := p_packaging_mode;
3439
3440 -- Setting the global variable for sequence
3441 --sequence_id := 1;
3442
3443 IF( packaging_mode = wms_cartnzn_pub.PR_pKG_mode OR
3444 packaging_mode = wms_cartnzn_pub.mfg_PR_pKG_mode) THEN
3448 wms_cartnzn_pub.prepack_pkg_mode) ) THEN
3445 outbound := 'Y';
3446 ELSIF(packaging_mode IN (wms_cartnzn_pub.int_bP_pkg_mode,
3447 wms_cartnzn_pub.mob_bP_pkg_mode ,
3449 outbound := 'N';
3450 ELSE
3451 outbound := p_out_bound;
3452 END IF;
3453
3454 IF( p_disable_cartonization = 'Y') THEN
3455 -- This is the case when the cartonization is only called
3456 -- for task type assignment, task splitting and task consolidation
3457 cartonization_profile := 'N';
3458
3459 ELSIF (outbound = 'N') THEN
3460 -- cartonization profile is always Y for non outbound
3461 cartonization_profile := 'Y';
3462
3463 ELSE
3464 BEGIN
3465
3466 SELECT Nvl(cartonization_flag,-1),
3467 Nvl(cartonize_sales_orders,'Y'),
3468 Nvl(cartonize_manufacturing,'N'),
3469 --Bug 3528061 fix
3470 Nvl(allocate_serial_flag,'N'),
3471 NVL(default_pick_op_plan_id,-1)
3472 INTO
3473 v_cart_value,
3474 l_cartonize_sales_orders,
3475 l_cartonize_manufacturing,
3476 --Bug 3528061 fix
3477 g_allocate_serial_flag,
3478 wms_cartnzn_pub.g_default_pick_op_plan_id
3479 FROM mtl_parameters
3480 WHERE organization_id = p_org_id;
3481
3482 wms_cartnzn_pub.g_org_cartonization_value := v_cart_value;
3483 wms_cartnzn_pub.g_org_cartonize_so_flag := l_cartonize_sales_orders;
3484 wms_cartnzn_pub.g_org_cartonize_mfg_flag := l_cartonize_manufacturing;
3485 wms_cartnzn_pub.g_org_allocate_serial_flag := g_allocate_serial_flag;
3486
3487 EXCEPTION
3488 WHEN OTHERS THEN
3489 v_cart_value := NULL;
3490 END;
3491
3492 IF( v_cart_value = 1) THEN
3493
3494 IF ((packaging_mode = wms_cartnzn_pub.pr_pkg_mode)
3495 AND (l_cartonize_sales_orders = 'Y'))
3496 OR
3497 ((packaging_mode = wms_cartnzn_pub.mfg_pr_pkg_mode)
3498 AND (l_cartonize_manufacturing = 'Y'))
3499 THEN
3500 -- Cartonization is enabled for the whole organization
3501 v_sublvlctrl := '1';
3502 cartonization_profile := 'Y';
3503 ELSE
3504 cartonization_profile := 'N';
3505 END IF;
3506
3507 ELSIF( v_cart_value = 3) THEN
3508
3509 IF ((packaging_mode = wms_cartnzn_pub.pr_pkg_mode)
3510 AND (l_cartonize_sales_orders = 'Y'))
3511 OR
3512 ((packaging_mode = wms_cartnzn_pub.mfg_pr_pkg_mode)
3513 AND (l_cartonize_manufacturing = 'Y'))
3514 THEN
3515 --cartonization is controlled at the subinventory level
3516 v_sublvlctrl := '3';
3517 cartonization_profile := 'Y';
3518 ELSE
3519 cartonization_profile := 'N';
3520 END IF;
3521 ELSE
3522 cartonization_profile := 'N';
3523 END IF;
3524
3525 END IF;
3526
3527 g_sublvlctrl := v_sublvlctrl ; --Bug#7168367.Store it in global variable
3528
3529 BEGIN
3530 SELECT percent_fill_basis_flag
3531 INTO percent_fill_basis
3532 FROM wsh_shipping_parameters
3533 WHERE organization_id = p_org_id AND
3534 ROWNUM = 1;
3535 wms_cartnzn_pub.g_percent_fill_basis := percent_fill_basis;
3536 EXCEPTION
3537 WHEN OTHERS THEN
3538 percent_fill_basis := 'W';
3539 wms_cartnzn_pub.g_percent_fill_basis := 'W';
3540 END;
3541
3542 IF(g_trace_on = 1) THEN
3543 log_event(' cartonization profile is '||cartonization_profile||' outbound is'||outbound || ' controlled at sub level is '||v_sublvlctrl);
3544 log_event('Percent fill basis '||percent_fill_basis);
3545 END IF;
3546
3547 IF (p_move_order_header_id <> -1) THEN
3548 BEGIN
3549 SELECT Nvl(auto_pick_confirm_flag, 'N')
3550 , Nvl(autocreate_delivery_flag, 'N')
3551 INTO l_auto_pick_confirm_flag
3552 , l_autocreate_delivery_flag
3553 FROM wsh_picking_batches
3554 WHERE batch_id =
3555 (SELECT request_number
3556 FROM mtl_txn_request_headers
3557 WHERE header_id = p_move_order_header_id
3558 AND move_order_type = inv_globals.G_MOVE_ORDER_PICK_WAVE);
3559
3560 IF l_auto_pick_confirm_flag = 'Y' THEN
3561 IF (g_trace_on = 1) THEN log_event('Auto pick confirm is ON for this batch'); END IF;
3562 END IF;
3563
3564 WMS_CARTNZN_PUB.g_autocreate_delivery_flag := l_autocreate_delivery_flag;
3565 WMS_CARTNZN_PUB.g_auto_pick_confirm_flag := l_auto_pick_confirm_flag;
3566
3567 EXCEPTION
3568 WHEN OTHERS THEN
3569 l_auto_pick_confirm_flag := 'N';
3570 WMS_CARTNZN_PUB.g_autocreate_delivery_flag := 'N';
3571 WMS_CARTNZN_PUB.g_auto_pick_confirm_flag := 'N';
3572 END;
3573 END IF;
3574
3575 ------------------------ ER : 6682436 START ---------------------------------
3576 -- Rule based cartonization will only be called for Pick Release Mode -------
3577
3578 IF(g_trace_on = 1) THEN
3582
3579 log_event('Packagin mode : '|| packaging_mode);
3580 log_event('wms_cartnzn_pub.PR_pKG_mode : '|| wms_cartnzn_pub.PR_pKG_mode);
3581 END IF;
3583 IF WMS_CONTROL.G_CURRENT_RELEASE_LEVEL >= 120001
3584 AND packaging_mode = wms_cartnzn_pub.PR_pKG_mode THEN
3585
3586 IF(g_trace_on = 1) THEN
3587 log_event('Checking the rules setup');
3588 END IF;
3589
3590 SELECT count(1)
3591 INTO l_rulebased_setup_exists
3592 FROM wms_selection_criteria_txn_v
3593 WHERE rule_type_code = 12
3594 AND enabled_flag = 1
3595 AND from_organization_id = p_org_id
3596 AND ROWNUM = 1;
3597
3598 IF l_rulebased_setup_exists > 0 THEN
3599 IF(g_trace_on = 1) THEN
3600 log_event('Rules setup exists');
3601 END IF;
3602
3603 table_name := 'wms_cartonization_temp';
3604
3605 IF wms_cartnzn_pub.g_org_cartonization_value IN (1,3) THEN
3606 log_event('Calling rulebased cartonization ');
3607 WMS_CARTNZN_PUB.rulebased_cartonization
3608 (
3609 x_return_status => l_api_return_status,
3610 x_msg_count => x_msg_count,
3611 x_msg_data => x_msg_data,
3612 p_out_bound => 'Y',
3613 p_org_id => p_org_id,
3614 p_move_order_header_id => p_move_order_header_id,
3615 p_input_for_bulk => null
3616 );
3617
3618 log_event('RETURNING FROM CARTONIZATION');
3619 RETURN; -- Bug : 6962305
3620 END IF;
3621 ELSE
3622 log_event('Rulebased setup does not exist, going to default cartonization logic');
3623 END IF; -- Rulebased cartonization
3624 END IF; -- Release level check
3625 ------------------------ ER : 6682436 END ---------------------------------
3626
3627 -- This setting ensures that all operations we do are on
3628 -- wms_cartonization_temp until its changed
3629 table_name := 'wms_cartonization_temp';
3630
3631 IF (g_trace_on = 1) THEN log_event(' Inserting mmtt rows to wct'); END IF;
3632
3633 IF ( outbound = 'Y') THEN
3634
3635 IF ( p_move_order_header_id = 0) THEN
3636 error_code := 'CARTONIZE 20';
3637 if (g_trace_on = 1) then log_event(' error move order header id '||p_move_order_header_id); END IF;
3638 RAISE fnd_api.g_exc_error;
3639 END IF;
3640
3641 -- changed for patchset J bulk picking -----------
3642 -- change for concurrent bulk picking program ------
3643
3644 IF (g_trace_on = 1) THEN log_event(' move order header id '||p_move_order_header_id); END IF;
3645 IF (p_move_order_header_id = -1 ) THEN -- this is called from concurrent program
3646 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING '); end if;
3647 l_move_order_type := INV_GLOBALS.G_MOVE_ORDER_PICK_WAVE;
3648 if (g_trace_on = 1) then log_event('This is called from concurrent program'); end if;
3649 ELSE
3650 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING '); end if;
3651 SELECT move_order_type
3652 INTO l_move_order_type
3653 FROM mtl_txn_request_headers
3654 WHERE header_id = p_move_order_header_id;
3655
3656 if (g_trace_on = 1) then log_event('Move order type:'||l_move_order_type); end if;
3657 END IF;
3658
3659 l_auto_pick_confirm_flag := 'N';
3660
3661 IF l_auto_pick_confirm_flag = 'Y' THEN
3662 IF (g_trace_on = 1) THEN log_event('Auto pick confirm is ON - Not calling task type assignment'); END IF;
3663
3664 ELSE
3665 error_code := 'CARTONIZE 30';
3666
3667 --- patchset J, bulk picking ---------------------------
3668 IF G_CURRENT_RELEASE_LEVEL < G_J_RELEASE_LEVEL OR
3669 l_move_order_type <> G_MOVE_ORDER_PICK_WAVE THEN
3670 IF (g_trace_on = 1) THEN log_event(' calling wms_rule_pvt.assigntts for task type assignment' ); END IF;
3671 wms_rule_pvt.assigntts(
3672 p_api_version => 1.0,
3673 p_move_order_header_id => p_move_order_header_id,
3674 x_return_status => l_return_status,
3675 x_msg_count => l_msg_count,
3676 x_msg_data => l_msg_data);
3677
3678 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3679 error_code := 'CARTONIZE 40';
3680 -- insert the message into the stack
3681 if (g_trace_on = 1) then log_event(' Task type assignment failed'); END IF;
3682 END IF;
3683
3684 l_return_status := fnd_api.g_ret_sts_success;
3685 END IF; -- end the in line branching
3686
3687 IF (p_move_order_header_id <> -1 ) THEN
3688 if (g_trace_on = 1) then log_event(' calling wms_rule_pvt.assign_operation_plan for OP assignment' ); END IF;
3689 wms_rule_pvt.assign_operation_plans(
3690 p_api_version => 1.0,
3691 p_move_order_header_id => p_move_order_header_id,
3692 x_return_status => l_return_status,
3696 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3693 x_msg_count => l_msg_count,
3694 x_msg_data => l_msg_data);
3695
3697 error_code := 'CARTONIZE 45';
3698 -- insert the message into the stack
3699 if (g_trace_on = 1) then log_event(' Operation plan assignment failed'); END IF;
3700 END IF;
3701 END IF;
3702
3703 END IF;
3704
3705
3706 IF (g_trace_on = 1) THEN log_event(' inserting mmtt rows of this header into wms_cartonization_temp '|| p_move_order_header_id ); END IF;
3707
3708 error_code := 'CARTONIZE 50';
3709
3710 -- Bug 2457428 fix
3711
3712 create_wct(p_move_order_header_id => p_move_order_header_id,
3713 p_transaction_header_id => NULL,
3714 p_input_for_bulk =>p_input_for_bulk);
3715
3716 --INSERT INTO wms_cartonization_temp SELECT mmtt.* FROM
3717 --mtl_material_transactions_temp mmtt, mtl_txn_request_lines
3718 --mtrl WHERE mtrl.header_id = p_move_order_header_id AND
3719 --mmtt.move_order_line_id = mtrl.line_id;
3720
3721 ELSE --outbound = 'N'
3722
3723 error_code := 'CARTONIZE 60';
3724 if (g_trace_on = 1) then log_event(' inserting mmtt rows of this header into wms_cartonization_temp '|| p_transaction_header_id ); END IF;
3725
3726 -- Bug 2457428 fix
3727
3728 create_wct(p_move_order_header_id => NULL,
3729 p_transaction_header_id => p_transaction_header_id
3730 );
3731
3732 --INSERT INTO wms_cartonization_temp
3733 --SELECT mmtt.* FROM
3734 --mtl_material_transactions_temp mmtt
3735 --WHERE
3736 --mmtt.transaction_header_id = p_transaction_header_id;
3737
3738 END IF;
3739
3740 -- Setting the stop level
3741 IF p_stop_level IS NULL THEN
3742 l_stop_level := -1;
3743 ELSE
3744 l_stop_level := p_stop_level;
3745 END IF;
3746
3747 -- Setting the current level we are packing
3748 pack_level := 0;
3749
3750
3751 IF(outbound = 'Y') THEN
3752 l_current_header_id := p_move_order_header_id;
3753 ELSE
3754 l_current_header_id := p_transaction_header_id;
3755 END IF;
3756
3757
3758 if (g_trace_on = 1) then
3759 log_event(' l_stop_level '||l_stop_level);
3760 log_event(' l_current_level '||pack_level);
3761 log_event(' l_current_header_id '||l_current_header_id);
3762 END IF;
3763
3764 IF( cartonization_profile = 'Y') THEN
3765
3766 if (g_trace_on = 1) then log_event(' cartonization_profile '||cartonization_profile); END IF;
3767
3768
3769 --- THis is the Multi level Cartonization loop
3770
3771 LOOP
3772
3773 if (g_trace_on = 1) then log_event(' cur lev '||pack_level ||' stop lev'||l_stop_level); END IF;
3774
3775 EXIT WHEN ( (pack_level >= l_stop_level) AND (l_stop_level <> -1));
3776
3777 v_prev_item_id := -1;
3778 v_prev_move_order_line_id := -1;
3779
3780
3781 --bpack_rows should select only rows with transaction_header_id = l_current_header_id
3782 if (g_trace_on = 1) then log_event(' opening cusror hdr id'||l_current_header_id); END IF;
3783
3784
3785 IF( (outbound = 'Y') AND (pack_level = 0)) THEN
3786
3787 error_code := 'CARTONIZE 70';
3788 if (g_trace_on = 1) then log_event('opening wct_rows'); END IF;
3789 OPEN wct_rows;
3790 if (g_trace_on = 1) then log_event('opened bpack rows'); END IF;
3791 ELSE
3792 error_code := 'CARTONIZE 90';
3793 if (g_trace_on = 1) then log_event('opening bpack_rows'); END IF;
3794 OPEN bpack_rows(l_current_header_id);
3795 if (g_trace_on = 1) then log_event(' Opened bpack rows'); END IF;
3796 END IF;
3797
3798 -- THis is the loop for cartonization using the container - item
3799 -- relation ship. The cursor already orders by move_order_line_id
3800 -- inventory_item_id. Here is the pseudo code logic
3801 -- 1)Fetch a line
3802 -- 2)if line has the same move_order_line_id as the previously fetched row.
3803 -- a) call the shipping api to see if any container is
3804 -- setup
3805 -- b) get the quantity per container
3806 -- ELSE
3807 -- if space is available in previous container
3808 -- pack as much of this item into that container
3809 -- and reduce the primary_quantity, space available for
3810 -- correspondingly
3811 -- end if;
3812 -- 3)if the line has primary_quantity to pack
3813 -- calculate the number of containers needed to pack from
3814 -- quantity per container, pack the line
3815 -- else
3816 -- go to the top of the loop to fetch new row
3817
3818 error_code := 'CARTONIZE 100';
3819
3820 LOOP
3821
3822 if (g_trace_on = 1) then log_event(' Fetching rows'); END IF;
3823
3824 IF( (outbound = 'Y') AND (pack_level = 0)) THEN
3825
3826 error_code := 'CARTONIZE 110';
3827 FETCH wct_rows INTO v1;
3831 revision_qty_control_code,
3828 EXIT WHEN wct_rows%notfound;
3829
3830 SELECT
3832 lot_control_code,
3833 serial_number_control_code
3834 INTO
3835 l_revision_code,
3836 l_lot_code,
3837 l_serial_code
3838 FROM mtl_system_items
3839 WHERE organization_id = v1.organization_id
3840 AND inventory_item_id = v1.inventory_item_id;
3841
3842 if l_revision_code> 1 then
3843 l_is_revision_control := TRUE;
3844 else
3845 l_is_revision_control := FALSE;
3846 end if;
3847
3848 IF l_lot_code > 1 THEN
3849 l_is_lot_control := TRUE;
3850 ELSE
3851 l_is_lot_control := FALSE;
3852 END IF;
3853
3854 IF (l_serial_code>1 AND l_serial_code<>6) then
3855 l_is_serial_control := TRUE;
3856 else
3857 l_is_serial_control := FALSE;
3858 end if;
3859
3860 IF (v1.allocated_lpn_id IS NOT NULL ) THEN
3861
3862 error_code := 'CARTONIZE 120';
3863
3864 -- Bug 3740610 No need to call qty tree,getting on-hand qty from table
3865
3866 SELECT NVL(SUM(primary_transaction_quantity),0)
3867 into l_qoh FROM mtl_onhand_quantities_detail
3868 WHERE organization_id = v1.organization_id
3869 AND subinventory_code = v1.subinventory_code
3870 AND locator_id = v1.locator_id
3871 AND lpn_id = v1.allocated_lpn_id;
3872 if (g_trace_on = 1) then log_event('lpn_id' || v1.allocated_lpn_id);
3873 log_event('l_qoh' || l_qoh);
3874 log_event('PrimaryQty'|| v1.primary_quantity);
3875 end if;
3876
3877 --Bug 3740610 Comparing on-hand qty with primary_qty of mmtt
3878
3879 IF ( l_qoh = v1.primary_quantity ) THEN
3880 l_lpn_fully_allocated := 'Y';
3881 select v1.transaction_temp_id, 'Y'
3882 into t_lpn_alloc_flag_table(v1.transaction_temp_id)
3883 from dual;
3884
3885 ELSE
3886 l_lpn_fully_allocated := 'N';
3887 select v1.transaction_temp_id, 'N'
3888 into t_lpn_alloc_flag_table(v1.transaction_temp_id)
3889 from dual;
3890 END IF;
3891 ELSE
3892 l_lpn_fully_allocated := 'Y';
3893 select v1.transaction_temp_id, 'Y'
3894 into t_lpn_alloc_flag_table(v1.transaction_temp_id)
3895 from dual;
3896 if (g_trace_on = 1) then log_event(' calling qty tree returns unsuccessfully' ); END IF;
3897 END IF ;
3898
3899 ELSE
3900 error_code := 'CARTONIZE 130';
3901 -- outbound = 'N'
3902 FETCH bpack_rows INTO v1;
3903
3904 EXIT WHEN bpack_rows%notfound;
3905
3906 -- THis setting always ensures that in non outbound
3907 -- modes, cartonization is not retricted by lpn
3908 -- allocation values
3909
3910 l_lpn_fully_allocated := 'N';
3911 END IF;
3912
3913 if (g_trace_on = 1) then log_event(' Fetch succeeded');
3914 log_event('lpn_fully_allocated:'||l_lpn_fully_allocated);
3915 log_event ('lpn_id after if:'||v1.allocated_lpn_id);
3916 end if;
3917
3918
3919 IF ( v1.allocated_lpn_id IS NOT NULL ) AND
3920 ( l_lpn_fully_allocated = 'Y' ) THEN
3921 null;
3922 ELSE
3923
3924 --populate lpn_alloc_flag with null for loose item
3925 select v1.transaction_temp_id, null
3926 into t_lpn_alloc_flag_table(v1.transaction_temp_id)
3927 from dual;
3928
3929
3930 -- If the content_lpn_id is populated on the mmtt record
3931 -- could be two cases. Either we are trying to pack an LPN
3932 -- or a package. We will have packages poulated in this
3933 -- column only by multi level cartonization and when it
3934 -- does that, the row is inserted with negative header id
3935 -- Basing on this we either get the item associated with
3936 -- the lpn, or item associated with the package
3937
3938 error_code := 'CARTONIZE 140';
3939
3940 if ( v1.content_lpn_id is not null ) then
3941
3942 if (g_trace_on = 1) then log_event(' content_lpn_id IS NOT NULL'); END IF;
3943
3944 IF v1.transaction_header_id < 0 THEN
3945 error_code := 'CARTONIZE 150';
3946 --THe content_lpn_id has a package in it ..
3950 error_code := 'CARTONIZE 160';
3947 --v1.inventory_item_id := Get_package_ItemId(v1.content_lpn_id);
3948
3949 ELSE
3951 --THe content_lpn_id has a LPN in it ..
3952 v1.inventory_item_id := Get_LPN_ItemId(v1.content_lpn_id);
3953 END IF;
3954
3955 -- When we are packaing an lpn or a package the qty is
3956 -- always 1
3957 v1.primary_quantity := 1;
3958 v1.transaction_quantity := 1;
3959
3960 end if;
3961
3962 error_code := 'CARTONIZE 170';
3963 SELECT primary_uom_code INTO v_primary_uom_code FROM mtl_system_items
3964 WHERE inventory_item_id = v1.inventory_item_id AND
3965 organization_id = v1.ORGANIZATION_ID;
3966
3967 if ( v1.content_lpn_id is not null ) THEN
3968 -- We want to set the transaction uom same as primary uom
3969 v1.transaction_uom := v_primary_uom_code;
3970 END IF;
3971
3972
3973
3974 if (g_trace_on = 1) then
3975 log_event(' inventory_item_id:'||v1.inventory_item_id);
3976 log_event(' primary_quantity:'||v1.primary_quantity);
3977 log_event(' primary_uom_code:'||v_primary_uom_code);
3978 log_event(' transaction_quantity:'||v1.transaction_quantity);
3979 log_event(' transaction_uom:'||v1.transaction_uom);
3980 log_event(' secondary_transaction_quantity:'||v1.secondary_transaction_quantity); --invconv kkillams
3981 log_event(' secondary_uom_code:'||v1.secondary_uom_code); --invconv kkillams
3982 END IF;
3983
3984
3985
3986 IF (outbound = 'Y') AND (pack_level = 0) AND
3987 (v_prev_move_order_line_id <> v1.move_order_line_id) THEN
3988 l_prev_condition := 'Y';
3989
3990 ELSIF (outbound = 'Y') AND (pack_level <> 0) AND
3991 ((v_prev_move_order_line_id <> v1.move_order_line_id) OR
3992 ( v1.inventory_item_id <> v_prev_item_id)) THEN
3993
3994 l_prev_condition := 'Y';
3995 ELSIF (outbound = 'N') AND ( v1.inventory_item_id <>
3996 v_prev_item_id) THEN
3997 l_prev_condition := 'Y';
3998 ELSE
3999 l_prev_condition := 'N';
4000 END IF;
4001
4002 -- The below condition is used when to make a
4003 -- call to the an api that returns conatiner item relation
4004 -- ship if present
4005 -- In outbound mode
4006 -- you have to call this when previous move order line id
4007 -- is different from the current one
4008 -- In the inbound mode
4009 -- We need to call if the previous item is different form
4010 -- the current item
4011
4012 IF l_prev_condition = 'Y' THEN
4013
4014
4015 if (g_trace_on = 1) then log_event(' call wms_container_pub.container_required_qty api for item id '||v1.inventory_item_id); END IF;
4016
4017
4018 v_prev_item_id := v1.inventory_item_id;
4019 v_prev_move_order_line_id := v1.move_order_line_id;
4020 v_container_item_id := NULL;
4021 v_qty_per_cont := -1;
4022 v_qty := -1;
4023 space_avail_for := 0;
4024 --Bug 2478970 fix
4025 l_valid_container := 'Y';
4026
4027 IF (outbound = 'Y') AND (pack_level = 0)
4028 AND (packaging_mode = wms_cartnzn_pub.pr_pkg_mode) THEN
4029 error_code := 'CARTONIZE 180';
4030 wsh_interface.Get_Max_Load_Qty(p_move_order_line_id => v1.move_order_line_id,
4031 x_max_load_quantity => v_qty_per_cont,
4032 x_container_item_id => v_container_item_id,
4033 x_return_status => v_return_status);
4034
4035 l_valid_container := 'Y'; --Undoing 2478970 fix
4036 --Bug 2478970 fix
4037 --l_valid_container := validate_cont_item(p_item_id =>v_container_item_id,
4038 -- p_org_id =>v1.organization_id);
4039 --log_event('validate_cont ret '|| l_valid_container);
4040 --Bug 2478970 fix
4041
4042 IF( (v_return_status = fnd_api.g_ret_sts_success) AND
4043 (v_qty_per_cont > 0) AND
4044 (v_container_item_id IS NOT NULL) AND
4045 (v_container_item_id > 0) ) THEN
4046
4047 v_qty := ceil(v1.primary_quantity/v_qty_per_cont);
4048 -- This quantity needs to be recalculated. This is
4049 -- poulated to pass the check marked by '#chk1'
4050
4051 END IF;
4052
4053
4054 IF (g_trace_on = 1) THEN
4055 log_event('wsh_interface.Get_Max_Load_Qty return status'||v_return_status);
4056 log_event('container '||v_container_item_id);
4060 v_prev_move_order_line_id := v1.move_order_line_id;
4057 log_event('Number of dum containers '||v_qty);
4058 END IF;
4059
4061
4062
4063
4064 ELSE
4065 error_code := 'CARTONIZE 190';
4066 wms_container_pub.Container_Required_Qty
4067 ( p_api_version => 1.0,
4068 x_return_status => v_return_status,
4069 x_msg_count => l_msg_count,
4070 x_msg_data => l_msg_data,
4071 p_source_item_id => v1.inventory_item_id,
4072 p_source_qty => v1.primary_quantity,
4073 p_source_qty_uom => v_primary_uom_code,
4074 p_organization_id => v1.organization_id,
4075 p_dest_cont_item_id => v_container_item_id,
4076 p_qty_required => v_qty
4077 );
4078
4079 if (g_trace_on = 1) then
4080 log_event('container_required_quantity return status'||v_return_status);
4081 log_event('container '||v_container_item_id);
4082 log_event('Number of conatiners '||v_qty);
4083 END IF;
4084
4085
4086 v_prev_item_id := v1.inventory_item_id;
4087
4088 IF( (v_return_status = fnd_api.g_ret_sts_success ) AND
4089 (v_qty IS NOT NULL) AND
4090 (v_qty > 0) AND
4091 (v_container_item_id IS NOT NULL) AND
4092 (v_container_item_id > 0) ) THEN
4093
4094 error_code := 'CARTONIZE 200';
4095
4096
4097 SELECT max_load_quantity INTO v_qty_per_cont FROM wsh_container_items
4098 WHERE load_item_id = v1.inventory_item_id AND
4099 master_organization_id = v1.organization_id AND
4100 container_item_id = v_container_item_id;
4101
4102 END IF;
4103
4104 END IF;
4105
4106
4107
4108 if (g_trace_on = 1) then log_event('qty per container is '||v_qty_per_cont); END IF;
4109
4110 --#chk1
4111
4112 IF( (v_return_status <> fnd_api.g_ret_sts_success ) OR
4113 (v_qty_per_cont IS NULL) OR
4114 (v_qty IS NULL) OR
4115 (v_container_item_id IS NULL) OR
4116 (v_qty <= 0) OR
4117 (v_container_item_id <= 0) OR
4118 (v_qty_per_cont <= 0) OR
4119 --Bug 2478970 fix
4120 l_valid_container = 'N'
4121 ) THEN
4122
4123 if (g_trace_on = 1) then log_event('improper values returned by container_required_qty '); END IF;
4124
4125
4126 ELSE
4127
4128 select msi.serial_number_control_code
4129 INTO v_serial_control_code
4130 from mtl_system_items msi
4131 where
4132 msi.inventory_item_id = v1.inventory_item_id AND
4133 msi.organization_id = v1.organization_id;
4134
4135
4136 IF( (v_serial_control_code NOT IN (1,6) ) AND
4137 (Ceil(v_qty_per_cont) > v_qty_per_cont )
4138 ) THEN
4139
4140 if (g_trace_on = 1) then
4141 log_event('cannot split serial controlled items to fractions');
4142 log_event('Please check the container item relationships');
4143 END IF;
4144
4145 v_qty_per_cont := 0;
4146 v_serial_control_code := NULL;
4147 END IF;
4148
4149 v_serial_control_code := NULL;
4150
4151 v_tr_qty_per_cont := inv_convert.inv_um_convert
4152 ( v1.inventory_item_id,
4153 5,
4154 v_qty_per_cont,
4155 v_primary_uom_code,
4156 v1.transaction_uom,
4157 NULL,
4158 null
4159 );
4160 --invconv kkillams
4161 IF v1.secondary_uom_code IS NOT NULL THEN
4162 v_sec_tr_qty_per_cont := inv_convert.inv_um_convert
4163 ( v1.inventory_item_id,
4164 5,
4165 v_qty_per_cont,
4166 v_primary_uom_code,
4167 v1.secondary_uom_code,
4168 NULL,
4169 null
4170 );
4171 END IF;
4172 if (g_trace_on = 1) then log_event(' Transaction qty per conatiner is '||v_tr_qty_per_cont); END IF;
4173 if (g_trace_on = 1) then log_event(' Secondary Transaction qty per conatiner is '||v_sec_tr_qty_per_cont); END IF;
4174 END IF;
4175
4179
4176 ELSE
4177
4178 IF (space_avail_for > 0) THEN
4180 if (g_trace_on = 1) then log_event(' Space available for '||space_avail_for); END IF;
4181
4182 IF (v1.primary_quantity <= space_avail_for) THEN
4183
4184 if (g_trace_on = 1) then log_event(' Prim qty '||v1.primary_quantity|| ' <= '||space_avail_for); END IF;
4185
4186 space_avail_for := space_avail_for - v1.primary_quantity;
4187
4188 IF( v1.content_lpn_id IS NULL) THEN
4189 l_upd_qty_flag := 'Y';
4190
4191 ELSE
4192 l_upd_qty_flag := 'N';
4193 END IF;
4194
4195
4196 update_mmtt
4197 ( p_transaction_temp_id => v1.transaction_temp_id,
4198 p_primary_quantity => v1.primary_quantity,
4199 p_transaction_quantity => v1.transaction_quantity,
4200 p_secondary_quantity => v1.secondary_transaction_quantity, --invconv kkillams
4201 --p_LPN_string => v_lpn_out,
4202 p_lpn_id => v_lpn_id,
4203 p_container_item_id => v_container_item_id,
4204 p_parent_line_id => NULL,
4205 p_upd_qty_flag => l_upd_qty_flag,
4206 x_return_status => l_return_status,
4207 x_msg_count => x_msg_count,
4208 x_msg_data => x_msg_data );
4209
4210 v1.primary_quantity := 0;
4211
4212 ELSE
4213
4214 if (g_trace_on = 1) then log_event(' Prim qty '||v1.primary_quantity|| ' > '||space_avail_for); END IF;
4215
4216 tr_space_avail_for := inv_convert.inv_um_convert
4217 ( v1.inventory_item_id,
4218 5,
4219 space_avail_for,
4220 v_primary_uom_code,
4221 v1.transaction_uom,
4222 NULL,
4223 null
4224 );
4225 --invconv kkillams
4226 sec_tr_space_avail_for := NULL;
4227 IF v1.secondary_uom_code IS NOT NULL THEN
4228 sec_tr_space_avail_for := inv_convert.inv_um_convert
4229 ( v1.inventory_item_id,
4230 5,
4231 space_avail_for,
4232 v_primary_uom_code,
4233 v1.secondary_uom_code,
4234 NULL,
4235 null
4236 );
4237 END IF;
4238 if (g_trace_on = 1) then log_event(' Tr space avail for '||tr_space_avail_for); END IF;
4239
4240 insert_mmtt
4241 ( p_transaction_temp_id => v1.transaction_temp_id,
4242 p_primary_quantity => space_avail_for,
4243 p_transaction_quantity => tr_space_avail_for,
4244 p_secondary_quantity => sec_tr_space_avail_for, --invconv kkillams
4245 --p_LPN_string => v_lpn_out,
4246 p_lpn_id => v_lpn_id,
4247 p_container_item_id => v_container_item_id,
4248 x_return_status => l_return_status,
4249 x_msg_count => x_msg_count,
4250 x_msg_data => x_msg_data );
4251
4252
4253 v1.primary_quantity := v1.primary_quantity - space_avail_for;
4254
4255 v1.transaction_quantity := inv_convert.inv_um_convert
4256 ( v1.inventory_item_id,
4257 5,
4258 v1.primary_quantity,
4259 v_primary_uom_code,
4260 v1.transaction_uom,
4261 NULL,
4262 null
4263 );
4264 --invconv kkillams
4265 IF v1.secondary_uom_code IS NOT NULL THEN
4266 v1.secondary_transaction_quantity
4267 := inv_convert.inv_um_convert
4268 ( v1.inventory_item_id,
4269 5,
4270 v1.primary_quantity,
4271 v_primary_uom_code,
4272 v1.secondary_uom_code,
4273 NULL,
4274 null
4275 );
4276 END IF;
4277
4278 space_avail_for := 0;
4279
4280 if (g_trace_on = 1) then
4284 log_event(' Space Avail for '||space_avail_for);
4281 log_event('Prim qty '||v1.primary_quantity);
4282 log_event(' Tr qty '||v1.transaction_quantity);
4283 log_event('Sec Tr qty '||v1.secondary_transaction_quantity); --invconv kkillams
4285 END IF;
4286
4287 END IF;
4288
4289
4290 END IF;
4291
4292 END IF;
4293
4294
4295 /* Condition #3 */
4296 IF ( v_return_status <> FND_API.g_ret_sts_success OR
4297 v_qty_per_cont IS NULL OR
4298 v_qty_per_cont <= 0 OR
4299 v_container_item_id IS NULL OR
4300 v_tr_qty_per_cont IS NULL OR
4301 v_tr_qty_per_cont <= 0 OR
4302 v1.primary_quantity <= 0 ) THEN
4303
4304 if (g_trace_on = 1) then log_event(' Container_Required_Qty - inc values'); END IF;
4305 /* Condition #3a */
4306 NULL;
4307 ELSE
4308 /* Condition #3b */
4309
4310 IF( v1.content_lpn_id IS NULL) THEN
4311 l_upd_qty_flag := 'Y';
4312 ELSE
4313 l_upd_qty_flag := 'N';
4314 END IF;
4315
4316 v_qty := ceil( v1.primary_quantity/v_qty_per_cont);
4317
4318 IF( MOD(v1.primary_quantity,v_qty_per_cont) = 0 ) THEN
4319 space_avail_for := 0;
4320 else
4321 space_avail_for := v_qty_per_cont - MOD(v1.primary_quantity,v_qty_per_cont);
4322 END IF;
4323
4324 if (g_trace_on = 1) then log_event('space avail for '||space_avail_for); END IF;
4325
4326
4327 /* Condition #4 */
4328 IF( (v1.primary_quantity <= v_qty_per_cont) OR ( v_qty = 1) ) THEN
4329
4330 if (g_trace_on = 1) then log_event(' primary_quantity <= qty per conatiner or'||' NUMBER OF cont = 1'); END IF;
4331
4332 v_lpn_id := get_next_package_id;
4333 if (g_trace_on = 1) then
4334 log_event(' Generated label Id '||v_lpn_id);
4335 END IF;
4336
4337 update_mmtt
4338 ( p_transaction_temp_id => v1.transaction_temp_id,
4339 p_primary_quantity => v1.primary_quantity,
4340 p_transaction_quantity => v1.transaction_quantity,
4341 p_secondary_quantity => v1.secondary_transaction_quantity, --invconv kkillams
4342 --p_LPN_string => v_lpn_out,
4343 p_lpn_id => v_lpn_id,
4344 p_container_item_id => v_container_item_id,
4345 p_parent_line_id => NULL,
4346 p_upd_qty_flag => l_upd_qty_flag ,
4347 x_return_status => l_return_status,
4348 x_msg_count => x_msg_count,
4349 x_msg_data => x_msg_data );
4350 ELSE
4351 /* Condition #4b */
4352
4353 v_loop := v_qty;
4354
4355
4356 if (g_trace_on = 1) then log_event(' NUMBER OF cont:'||v_qty); END IF;
4357 --Bug2422193 fix moved this update to above as package
4358 --ids need TO be generated IN the ORDER IN which rows
4359 --are considered for cartonization
4360 v_lpn_id := get_next_package_id;
4361 if (g_trace_on = 1) then
4362 log_event(' Generated label Id '||v_lpn_id);
4363 log_event('calling update_mmtt');
4364 END IF;
4365
4366 update_mmtt
4367 ( p_transaction_temp_id => v1.transaction_temp_id,
4368 p_primary_quantity => v_qty_per_cont,
4369 p_transaction_quantity => v_tr_qty_per_cont,
4370 p_secondary_quantity => v_sec_tr_qty_per_cont, --invconv kkillams
4371 --p_LPN_string => v_lpn_out,
4372 p_lpn_id => v_lpn_id,
4373 p_container_item_id => v_container_item_id,
4374 p_parent_line_id => NULL,
4375 p_upd_qty_flag => l_upd_qty_flag,
4376 x_return_status => l_return_status,
4377 x_msg_count => x_msg_count,
4378 x_msg_data => x_msg_data );
4379
4380
4381
4382 v_loop := v_loop - 1;
4383
4384 --Bug2422193 fix
4385
4386 LOOP
4387
4388 EXIT WHEN v_loop < 2;
4389
4390 v_lpn_id := get_next_package_id;
4391 if (g_trace_on = 1) then
4395 insert_mmtt
4392 log_event(' Generated label Id '||v_lpn_id);
4393 log_event(' calling insert mmtt');
4394 END IF;
4396 ( p_transaction_temp_id => v1.transaction_temp_id,
4397 p_primary_quantity => v_qty_per_cont,
4398 p_transaction_quantity => v_tr_qty_per_cont,
4399 p_secondary_quantity => v_sec_tr_qty_per_cont, --invconv kkillams
4400 --p_LPN_string => v_lpn_out,
4401 p_lpn_id => v_lpn_id,
4402 p_container_item_id => v_container_item_id,
4403 x_return_status => l_return_status,
4404 x_msg_count => x_msg_count,
4405 x_msg_data => x_msg_data );
4406
4407 if (g_trace_on = 1) then log_event(' called insert mmtt'); END IF;
4408 v_loop := v_loop - 1;
4409
4410
4411 END LOOP;
4412 --Bug2422193 fix
4413 --v_lpn_id := get_next_package_id;
4414 --log_event(' Generated label Id '||v_lpn_id);
4415
4416 --log_event('calling update_mmtt');
4417
4418 --update_mmtt
4419 --( p_transaction_temp_id => v1.transaction_temp_id,
4420 --p_primary_quantity => v_qty_per_cont,
4421 --p_transaction_quantity => v_tr_qty_per_cont,
4422 --p_LPN_string => v_lpn_out,
4423 --p_lpn_id => v_lpn_id,
4424 --p_container_item_id => v_container_item_id,
4425 --p_parent_line_id => NULL,
4426 --p_upd_qty_flag => l_upd_qty_flag,
4427 --x_return_status => l_return_status,
4428 --x_msg_count => x_msg_count,
4429 --x_msg_data => x_msg_data );
4430
4431
4432 --Bug2422193 fix
4433
4434 v_lpn_id := get_next_package_id;
4435 if (g_trace_on = 1) then log_event(' Generated label Id '||v_lpn_id); END IF;
4436
4437 v_left_prim_quant := MOD(v1.primary_quantity,v_qty_per_cont);
4438 v_left_tr_quant := MOD(v1.transaction_quantity,v_tr_qty_per_cont);
4439
4440 IF v1.secondary_uom_code IS NOT NULL THEN --invconv kkillams
4441 v_sec_left_tr_quant := MOD(v1.secondary_transaction_quantity,v_sec_tr_qty_per_cont);
4442 END IF;
4443
4444 IF( v_left_prim_quant = 0 OR v_left_tr_quant =0) THEN
4445 v_left_prim_quant := v_qty_per_cont;
4446 v_left_tr_quant := v_tr_qty_per_cont;
4447 IF v1.secondary_uom_code IS NOT NULL THEN --invconv kkillams
4448 v_sec_left_tr_quant := v_sec_tr_qty_per_cont;
4449 END IF;
4450 END IF;
4451
4452 if (g_trace_on = 1) then log_event('calling insert mmtt'); END IF;
4453 insert_mmtt
4454 ( p_transaction_temp_id => v1.transaction_temp_id,
4455 p_primary_quantity => v_left_prim_quant,
4456 p_transaction_quantity => v_left_tr_quant,
4457 p_secondary_quantity => v_sec_left_tr_quant, --invconv kkillams
4458 --p_LPN_string => v_lpn_out,
4459 p_lpn_id => v_lpn_id,
4460 p_container_item_id => v_container_item_id,
4461 x_return_status => l_return_status,
4462 x_msg_count => x_msg_count,
4463 x_msg_data => x_msg_data );
4464
4465
4466 NULL;
4467 -- Shipping API
4468
4469 END IF;
4470 /* Close Condition #4 */
4471 END IF;
4472 /* Close Condition #3 */
4473 END IF;
4474 /** for v1.allocated_lpn_id is not null*/
4475 END LOOP;
4476
4477 if (g_trace_on = 1) then log_event(' end working with wms_container_pub.container_required_qty api ' ); END IF;
4478
4479 error_code := 'CARTONIZE 220';
4480
4481 if (g_trace_on = 1) then log_event(' Calling item-category cartonization'); END IF;
4482
4483 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4484
4485
4486 ret_value:= do_cartonization(p_move_order_header_id,0,outbound,
4487 v_sublvlctrl,percent_fill_basis);
4488
4489
4490 ELSE
4491 if (g_trace_on = 1) then
4492 log_event('in else for cartonization');
4493 log_event('passing header id '||l_current_header_id);
4494 log_event('passing outbound '||outbound);
4498 v_sublvlctrl,percent_fill_basis);
4495 log_event('passing Sub level Control'||v_sublvlctrl);
4496 END IF;
4497 ret_value:= do_cartonization(0,l_current_header_id,outbound,
4499
4500 END IF;
4501
4502 if (g_trace_on = 1) then
4503 log_event(' cartonization returned'|| ret_value);
4504 log_event(' calling split_lot_serials ');
4505 END IF;
4506
4507 split_lot_serials(p_org_id);
4508
4509 if (g_trace_on = 1) then log_event(' Populating Packaging History Table'); END IF;
4510
4511 l_prev_package_id := -1;
4512
4513
4514 l_prev_header_id := l_current_header_id;
4515
4516 if (g_trace_on = 1) then log_event(' prev header id '||l_prev_header_id ); END IF;
4517
4518 l_current_header_id := get_next_header_id;
4519
4520 if (g_trace_on = 1) then log_event(' current_header_id '||l_current_header_id); END IF;
4521
4522 error_code := 'CARTONIZE 225';
4523 t_lpn_alloc_flag_table.delete;
4524 error_code := 'CARTONIZE 226';
4525 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4526 error_code := 'CARTONIZE 227';
4527 OPEN opackages(l_prev_header_id);
4528 ELSE
4529 error_code := 'CARTONIZE 228';
4530 OPEN packages(l_prev_header_id);
4531 END IF;
4532
4533
4534 l_no_pkgs_gen := 'Y';
4535
4536 error_code := 'CARTONIZE 230';
4537
4538 LOOP
4539
4540 if (g_trace_on = 1) then log_event('Fetching Packages cursor '); END IF;
4541
4542 error_code := 'CARTONIZE 240';
4543
4544 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4545 FETCH opackages INTO l_temp_id,l_item_id, l_qty, l_tr_qty,l_sec_tr_qty, l_clpn_id, l_citem_id, l_package_id;
4546 EXIT WHEN opackages%notfound;
4547 ELSE
4548 FETCH packages INTO l_temp_id,l_item_id, l_qty, l_tr_qty, l_sec_tr_qty, l_clpn_id, l_citem_id, l_package_id;
4549 EXIT WHEN packages%notfound;
4550 END IF;
4551
4552
4553
4554 if (g_trace_on = 1) then
4555 log_event('temp_id '||l_temp_id );
4556 log_event('item_id '||l_item_id );
4557 log_event('qty '||l_qty );
4558 log_event('tr_qty '||l_tr_qty);
4559 log_event('sec_tr_qty '||l_sec_tr_qty);
4560 log_event('clpn_id '||l_clpn_id);
4561 log_event('citem_id '||l_citem_id);
4562 log_event('package_id '||l_package_id);
4563 END IF;
4564 if( l_package_id is not null ) THEN
4565
4566 l_no_pkgs_gen := 'N';
4567 if( l_package_id <> l_prev_package_id ) then
4568
4569 l_prev_package_id := l_package_id;
4570
4571 if (g_trace_on = 1) then log_event(' Inserting a new row for package '||l_package_id); END IF;
4572
4573
4574 insert_mmtt
4575 ( p_transaction_temp_id => l_temp_id,
4576 p_primary_quantity => l_qty,
4577 p_transaction_quantity => l_tr_qty,
4578 p_secondary_quantity => l_sec_tr_qty, --invconv kkillams
4579 p_new_txn_hdr_id => l_current_header_id,
4580 p_new_txn_tmp_id => get_next_temp_id,
4581 p_clpn_id => l_package_id,
4582 p_item_id => l_citem_id,
4583 x_return_status => l_return_status,
4584 x_msg_count => x_msg_count,
4585 x_msg_data => x_msg_data );
4586
4587
4588
4589 end if;
4590
4591 if (g_trace_on = 1) then log_event(' Calling InsertPH for temp_id'||l_temp_id); END IF;
4592 IF( outbound = 'Y' ) then
4593 Insert_PH(p_move_order_header_id, l_temp_id);
4594 ELSE
4595 Insert_PH(p_transaction_header_id, l_temp_id);
4596 END IF;
4597 END IF;
4598
4599
4600 END LOOP;
4601
4602 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4603 IF opackages%isopen THEN
4604 CLOSE opackages;
4605 END IF;
4606 ELSE
4607 IF packages%isopen THEN
4608 CLOSE packages;
4609 END IF;
4610 END IF;
4611
4612
4613 IF( l_no_pkgs_gen = 'Y' ) THEN
4614 if (g_trace_on = 1) then log_event('no labels generated in the previous level-EXITING'); END IF;
4615
4616 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4617
4618 IF( wct_rows%isopen) then
4619 CLOSE wct_rows;
4620 END IF;
4621
4622
4623 ELSE
4624
4625 IF(bpack_rows%isopen) then
4626 CLOSE bpack_rows;
4627 END IF;
4628
4629
4630 END IF;
4631
4632 EXIT;
4633 END IF;
4634
4638 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
4635
4636
4637
4639 IF wct_rows%isopen THEN
4640 CLOSE wct_rows;
4641 END IF;
4642
4643 ELSE
4644 IF(bpack_rows%isopen) then
4645 CLOSE bpack_rows;
4646 END IF;
4647
4648 END IF;
4649
4650
4651 pack_level := pack_level + 1;
4652 if (g_trace_on = 1) then
4653 log_event(' Incremented the current level');
4654 log_event(' going back to the multi-cart loop');
4655 END IF;
4656
4657 END LOOP; -- Ends the loop for multi level cartonization
4658
4659
4660 IF ( outbound = 'Y') THEN
4661 l_header_id := p_move_order_header_id;
4662 ELSE
4663 l_header_id := p_transaction_header_id;
4664 END IF;
4665
4666 -- We have to update the end labels to LPNS and update the
4667 -- packaging history and mmtt correspondingly
4668
4669 if (g_trace_on = 1) then log_event(' calling Generate_LPNs for header id '||l_header_id); END IF;
4670
4671 BEGIN
4672 error_code := 'CARTONIZE 250';
4673
4674 generate_lpns(p_header_id => l_header_id,
4675 p_organization_id => p_org_id);
4676 EXCEPTION
4677 WHEN OTHERS THEN
4678 IF( packaging_mode IN (wms_cartnzn_pub.int_bp_pkg_mode,
4679 wms_cartnzn_pub.mob_bP_pkg_mode ,
4680 wms_cartnzn_pub.prepack_pkg_mode) ) THEN
4681 if (g_trace_on = 1) then log_event('erroring out since the mode is bulk pack '); END IF;
4682 RAISE fnd_api.g_exc_unexpected_error;
4683 ELSE
4684 if (g_trace_on = 1) then log_event('not erroring out since the mode is Pick release '); END IF;
4685 RAISE fnd_api.g_exc_error;
4686 END IF;
4687 END ;
4688
4689
4690 DELETE wms_cartonization_temp
4691 WHERE
4692 transaction_header_id < 0;
4693
4694 ELSE
4695 -- Cartonization profile = 'N'
4696 null;
4697 END IF;
4698
4699 IF( outbound = 'Y') THEN
4700
4701 IF l_auto_pick_confirm_flag = 'Y' THEN
4702 if (g_trace_on = 1) then log_event('Auto pick confirm is ON - Not calling task consolidation - splitting'); END IF;
4703
4704 ELSE
4705
4706 if (g_trace_on = 1) then log_event(' calling consolidation' ); END IF;
4707
4708 -- patchset J bulk picking -----------------------------------
4709 if G_CURRENT_RELEASE_LEVEL >= G_J_RELEASE_LEVEL
4710 AND l_move_order_type = g_move_order_pick_wave THEN
4711 if (g_trace_on = 1) then -- log_event('PATCHSET J-- BULK PICKING --START');
4712 log_event('Calling consolidate_bulk_tasks_for_so....');
4713 log_event('move order header id '||p_move_order_header_id); end if;
4714 wms_task_dispatch_engine.consolidate_bulk_tasks_for_so
4715 (p_api_version => 1.0,
4716 x_return_status => l_return_status,
4717 x_msg_count => x_msg_count,
4718 x_msg_data => x_msg_data,
4719 p_move_order_header_id => p_move_order_header_id);
4720 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
4721 -- we don't want to exit if there is any error here, for example data error or something
4722 if (g_trace_on = 1) then log_event(' consolidate_bulk_tasks_for_so returns '||l_return_status); END IF;
4723 END IF;
4724 if (g_trace_on = 1) then log_event(' calling ins_wct_rows_into_mmtt after consolidation'); END IF;
4725
4726 ins_wct_rows_into_mmtt( p_m_o_h_id => p_move_order_header_id,
4727 p_outbound => 'Y',
4728 x_return_status => l_return_status,
4729 x_msg_count => x_msg_count,
4730 x_msg_data => x_msg_data);
4731 -- since the return value is not set up inside above procedure, so no need to check it
4732 -- but above procedure will throw unexpected error in case of errors, so this API will capture the
4733 -- error.
4734
4735 WMS_CARTNZN_PUB.assigntts(
4736 p_api_version => 1.0,
4737 p_move_order_header_id => p_move_order_header_id,
4738 x_return_status => l_return_status,
4739 x_msg_count => l_msg_count,
4740 x_msg_data => l_msg_data);
4741
4742 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4743 error_code := 'CARTONIZE 40.1';
4744 if (g_trace_on = 1) then log_event(' Task type assignment failed'); END IF;
4745 END IF;
4749 wms_task_dispatch_engine.consolidate_bulk_tasks
4746 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING --END'); end if;
4747 ELSE
4748 if (g_trace_on = 1) then log_event('Calling consolidate_bulk_tasks...'); end if;
4750 (p_api_version => 1.0,
4751 x_return_status => l_return_status,
4752 x_msg_count => x_msg_count,
4753 x_msg_data => x_msg_data,
4754 p_move_order_header_id => p_move_order_header_id);
4755 END IF;
4756 ----- end of changed for patchset J bulk picking -----------
4757
4758
4759 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
4760 --Push the message into the stack
4761 if (g_trace_on = 1) then log_event(' consolidate_bulk_tasks returns '||l_return_status); END IF;
4762 END IF;
4763
4764 if (g_trace_on = 1) then log_event(' calling task splitting' ); END IF;
4765 wms_task_dispatch_engine.split_tasks
4766 (p_api_version => 1.0,
4767 x_return_status => l_return_status,
4768 x_msg_count => x_msg_count,
4769 x_msg_data => x_msg_data,
4770 p_move_order_header_id => p_move_order_header_id);
4771
4772 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
4773 --Push the message into the stack
4774 if (g_trace_on = 1) then log_event(' split_tasks returns '||l_return_status); END IF;
4775 END IF;
4776
4777 -- patchset J bulk picking -------------------
4778 IF (G_CURRENT_RELEASE_LEVEL >= G_J_RELEASE_LEVEL
4779 AND l_move_order_type =g_move_order_pick_wave AND
4780 p_move_order_header_id = -1 ) THEN -- calling from concurrent program
4781 if (g_trace_on = 1) then -- log_event('PATCHSET J-- BULK PICKING --START');
4782 log_event('calling assign pick slip number...'); end if;
4783 INV_Pick_Release_PUB.assign_pick_slip_number(
4784 x_return_status => l_return_status,
4785 x_msg_count => x_msg_count,
4786 x_msg_data => x_msg_data,
4787 p_move_order_header_id => p_move_order_header_id,
4788 p_ps_mode => null,
4789 p_grouping_rule_id => null,
4790 p_allow_partial_pick => null);
4791 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
4792 --Push the message into the stack
4793 if (g_trace_on = 1) then log_event(' assign_pick_slip_number returns '||l_return_status); END IF;
4794 END IF;
4795 END IF;
4796
4797 END IF;
4798
4799 END IF;
4800
4801
4802
4803 if (g_trace_on = 1) then log_event(' calling ins_wct_rows_into_mmtt'); END IF;
4804
4805
4806 -- patchset J bulk picking -------------------
4807 IF( outbound= 'Y' ) then
4808 if (G_CURRENT_RELEASE_LEVEL < G_J_RELEASE_LEVEL) or
4809 (G_CURRENT_RELEASE_LEVEL >= G_J_RELEASE_LEVEL
4810 AND l_move_order_type <>g_move_order_pick_wave ) THEN
4811 ins_wct_rows_into_mmtt( p_m_o_h_id => p_move_order_header_id,
4812 p_outbound => 'Y',
4813 x_return_status => l_return_status,
4814 x_msg_count => x_msg_count,
4815 x_msg_data => x_msg_data);
4816 end if;
4817
4818 ELSE
4819 ins_wct_rows_into_mmtt( p_m_o_h_id => p_transaction_header_id,
4820 p_outbound => 'N',
4821 x_return_status => l_return_status,
4822 x_msg_count => x_msg_count,
4823 x_msg_data => x_msg_data);
4824 END IF;
4825
4826
4827 error_code := 'CARTONIZE 260';
4828 if (g_trace_on = 1) then log_event(' calling print label' ); END IF;
4829 l_counter := 1;
4830
4831
4832
4833 IF( outbound = 'Y') THEN
4834
4835 OPEN OB_LBPRT;
4836 loop
4837 FETCH OB_LBPRT INTO lpns_generated_tb(l_counter);
4838 EXIT WHEN OB_LBPRT%notfound;
4839
4840 if (g_trace_on = 1) then log_event(' print label for lpn '|| lpns_generated_tb(l_counter)); END IF;
4841 l_counter := l_counter + 1;
4842 END LOOP;
4843 IF OB_LBPRT%ISOPEN THEN
4844 CLOSE OB_LBPRT;
4845 END IF;
4846
4847 ELSE
4848 OPEN IB_LBPRT;
4849 LOOP
4850 FETCH IB_LBPRT INTO lpns_generated_tb(l_counter);
4851 EXIT WHEN IB_LBPRT%notfound;
4852
4853 if (g_trace_on = 1) then log_event(' print label for lpn '|| lpns_generated_tb(l_counter)); END IF;
4854 l_counter := l_counter + 1;
4855 END LOOP;
4856 IF IB_LBPRT%ISOPEN THEN
4857 CLOSE IB_LBPRT;
4858 END IF;
4859 END IF;
4860
4861
4865 IF( packaging_mode = wms_cartnzn_pub.PR_pKG_mode OR
4862 IF --(l_lpn_id_tbl IS NOT NULL) AND bug 2720653 fix
4863 (lpns_generated_tb.count > 0) THEN
4864
4866 packaging_mode = wms_cartnzn_pub.mfg_PR_pKG_mode) THEN
4867 if (g_trace_on = 1) then log_event('wms_cartnzn_pub before inv_label.print_label '); END IF;
4868
4869 l_return_status := fnd_api.g_ret_sts_success;
4870
4871 inv_label.print_label
4872 (x_return_status => l_return_status
4873 , x_msg_count => l_msg_count
4874 , x_msg_data => l_msg_data
4875 , x_label_status => l_label_status
4876 , p_api_version => 1.0
4877 , p_print_mode => 1
4878 , p_business_flow_code => 22
4879 , p_transaction_id => lpns_generated_tb
4880 );
4881 if (g_trace_on = 1) then log_event('wms_cartnzn_pub after inv_label.print_label '); END IF;
4882
4883 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4884 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL'); -- MSGTBD
4885 FND_MSG_PUB.ADD;
4886
4887 --IF( packaging_mode IN (2,3,4) ) THEN
4888 --x_return_status := l_return_status;
4889 --x_msg_data := l_msg_data;
4890 --x_msg_count := l_msg_count;
4891 --END IF;
4892
4893 if (g_trace_on = 1) then log_event('wms_cartnzn_pub inv_label.print_label FAILED;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS')); END IF;
4894 END IF;
4895 END IF; -- end packaging_mode in 1
4896
4897 ELSE
4898 if (g_trace_on = 1) then log_event('could not cartonize any of the lines'); END IF;
4899
4900 IF( packaging_mode IN (wms_cartnzn_pub.int_bp_pkg_mode,
4901 wms_cartnzn_pub.mob_bP_pkg_mode ,
4902 wms_cartnzn_pub.prepack_pkg_mode)) THEN
4903 if (g_trace_on = 1) then log_event('erroring out since the mode is bulk pack '); END IF;
4904 x_return_status := fnd_api.g_ret_sts_error;
4905 END IF;
4906
4907 END IF;
4908
4909 if (g_trace_on = 1) then log_event('return status is '||x_return_status); END IF;
4910
4911 IF wct_rows%isopen THEN
4912 CLOSE wct_rows;
4913 END IF;
4914
4915
4916 EXCEPTION
4917
4918 WHEN fnd_api.g_exc_error THEN
4919 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
4920 ROLLBACK TO cartonize_pub;
4921 x_return_status := fnd_api.g_ret_sts_success;
4922
4923 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
4924 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
4925 FND_MSG_PUB.ADD;
4926
4927 if (g_trace_on = 1) then log_event('EXCEPTION occurred from ERROR_CODE:'||error_code); END IF;
4928
4929 fnd_msg_pub.count_and_get
4930 (
4931 p_count => x_msg_count,
4932 p_data => x_msg_data
4933 );
4934
4935 -- IF (x_msg_count = 0) THEN
4936 -- dbms_output.put_line('Successful');
4937 -- ELSIF (x_msg_count = 1) THEN
4938 -- dbms_output.put_line ('Not Successful');
4939 -- dbms_output.put_line (replace(x_msg_data,chr(0),' '));
4940 -- ELSE
4941 -- dbms_output.put_line ('Not Successful2');
4942 -- For I in 1..x_msg_count LOOP
4943 -- x_msg_data := fnd_msg_pub.get(I,'F');
4944 -- dbms_output.put_line(replace(x_msg_data,chr(0),' '));
4945 -- END LOOP;
4946 -- END IF;
4947
4948 IF wct_rows%isopen THEN
4949 CLOSE wct_rows;
4950 END IF;
4951
4952 WHEN fnd_api.g_exc_unexpected_error THEN
4953 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
4954 ROLLBACK TO cartonize_pub;
4955 x_return_status := fnd_api.g_ret_sts_unexp_error;
4956
4957 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
4958 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
4959 FND_MSG_PUB.ADD;
4960 if (g_trace_on = 1) then log_event('Exception occurred from ERROR_CODE:'||error_code); END IF;
4961 fnd_msg_pub.count_and_get
4962 (
4963 p_count => x_msg_count,
4964 p_data => x_msg_data
4965 );
4966
4967 IF wct_rows%isopen THEN
4968 CLOSE wct_rows;
4969 END IF;
4970
4971 WHEN OTHERS THEN
4972 ROLLBACK TO cartonize_pub;
4973 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
4974 x_return_status := fnd_api.g_ret_sts_unexp_error;
4975
4976 ERROR_MSG := Sqlerrm;
4977
4978 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
4979 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
4980 FND_MSG_PUB.ADD;
4981
4982 if (g_trace_on = 1) then log_event('Exception occurred from ERROR_CODE:'||error_code); END IF;
4983
4984 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error ) THEN
4985
4986 fnd_msg_pub.add_exc_msg
4987 ( g_pkg_name,
4988 l_api_name,
4989 ERROR_MSG
4990 );
4991 END IF;
4992
4993 fnd_msg_pub.count_and_get
4994 (
4995 p_count => x_msg_count,
4999 IF wct_rows%isopen THEN
4996 p_data => x_msg_data
4997 );
4998
5000 CLOSE wct_rows;
5001 END IF;
5002
5003 END cartonize;
5004
5005
5006 PROCEDURE UPDATE_MMTT(
5007 p_transaction_temp_id IN NUMBER,
5008 p_primary_quantity IN NUMBER,
5009 p_transaction_quantity IN NUMBER,
5010 p_secondary_quantity IN NUMBER, --invconv kkillams
5011 p_LPN_string IN VARCHAR2,
5012 p_lpn_id IN NUMBER,
5013 p_container_item_id IN NUMBER,
5014 p_parent_line_id IN NUMBER,
5015 p_upd_qty_flag IN VARCHAR2,
5016 x_return_status OUT NOCOPY VARCHAR2,
5017 x_msg_count OUT NOCOPY NUMBER,
5018 x_msg_data OUT NOCOPY VARCHAR2)
5019 IS
5020
5021 l_lpn NUMBER := 0;
5022 par_line_id NUMBER := NULL;
5023
5024 BEGIN
5025
5026 error_code := 'UPD_MMTT';
5027
5028 if (g_trace_on = 1) then log_event(' In update mmtt '||p_upd_qty_flag ); END IF;
5029
5030 IF p_lpn_id IS NOT NULL THEN
5031
5032 l_lpn := p_lpn_id;
5033
5034 elsIF p_lpn_string IS NOT NULL then
5035
5036 SELECT lpn_id INTO l_lpn FROM wms_license_plate_numbers WHERE
5037 license_plate_number = p_lpn_string;
5038 ELSE
5039
5040 l_lpn := NULL;
5041 END IF;
5042
5043
5044 if (g_trace_on = 1) then log_event('l_lpn '||l_lpn); END IF;
5045
5046
5047
5048 IF p_primary_quantity IS NULL THEN
5049 NULL;
5050 --GET PRIMARY QUANTITY
5051 END IF;
5052
5053
5054 IF table_name = 'mtl_material_transactions_temp' THEN
5055
5056 if (g_trace_on = 1) then log_event(' table_name = mtl_material_transactions_temp'); END IF;
5057
5058
5059 IF p_parent_line_id = -99999 THEN
5060 SELECT parent_line_id INTO par_line_id FROM
5061 mtl_material_transactions_temp WHERE transaction_temp_id =
5062 p_transaction_temp_id;
5063 ELSE
5064 par_line_id := p_parent_line_id;
5065 END IF;
5066
5067
5068 if (g_trace_on = 1) then log_event(' upd qty flag is '||p_upd_qty_flag ); END IF;
5069
5070 IF( p_upd_qty_flag = 'Y') THEN
5071
5072
5073 UPDATE mtl_material_transactions_temp SET
5074 primary_quantity = p_primary_quantity,
5075 transaction_quantity = p_transaction_quantity,
5076 secondary_transaction_quantity = p_secondary_quantity, --invconv kkillams
5077 cartonization_id = l_LPN,
5078 container_item_id = p_container_item_id,
5079 parent_line_id = par_line_id,
5080 last_update_date = Sysdate,
5081 last_updated_by = fnd_global.user_id
5082 WHERE
5083 transaction_temp_id = p_transaction_temp_id;
5084 ELSE
5085 UPDATE mtl_material_transactions_temp SET
5086 cartonization_id = l_LPN,
5087 container_item_id = p_container_item_id,
5088 parent_line_id = par_line_id,
5089 last_update_date = Sysdate,
5090 last_updated_by = fnd_global.user_id
5091 WHERE
5092 transaction_temp_id = p_transaction_temp_id;
5093 END IF;
5094
5095
5096 ELSE
5097
5098 if (g_trace_on = 1) then log_event(' table_name = wms_cartonization_temp'); END IF;
5099
5100 IF p_parent_line_id = -99999 THEN
5101
5102 SELECT parent_line_id INTO par_line_id FROM
5103 wms_cartonization_temp WHERE transaction_temp_id =
5104 p_transaction_temp_id;
5105 ELSE
5106 par_line_id := p_parent_line_id;
5107 END IF;
5108
5109 if (g_trace_on = 1) then log_event(' upd qty flag is '||p_upd_qty_flag ); END IF;
5110
5111 IF( p_upd_qty_flag = 'Y') THEN
5112
5113 UPDATE wms_cartonization_temp SET
5114 primary_quantity = p_primary_quantity,
5115 transaction_quantity = p_transaction_quantity,
5116 secondary_transaction_quantity = p_secondary_quantity, --invconv kkillams
5117 cartonization_id = l_LPN,
5118 parent_line_id = par_line_id,
5119 container_item_id = p_container_item_id,
5120 last_update_date = Sysdate,
5121 last_updated_by = fnd_global.user_id
5122 WHERE
5123 transaction_temp_id = p_transaction_temp_id;
5124 ELSE
5125 UPDATE wms_cartonization_temp SET
5126 cartonization_id = l_LPN,
5127 parent_line_id = par_line_id,
5128 container_item_id = p_container_item_id,
5129 last_update_date = Sysdate,
5130 last_updated_by = fnd_global.user_id
5131 WHERE
5132 transaction_temp_id = p_transaction_temp_id;
5133 END IF;
5134
5135
5136
5137 END IF;
5138
5139
5140
5141 END update_mmtt;
5142
5143
5144
5145 PROCEDURE INSERT_MMTT(
5149 p_secondary_quantity IN NUMBER , --invconv kkillams
5146 p_transaction_temp_id IN NUMBER,
5147 p_primary_quantity IN NUMBER,
5148 p_transaction_quantity IN NUMBER,
5150 p_LPN_string IN VARCHAR2,
5151 p_lpn_id IN NUMBER,
5152 p_container_item_id IN NUMBER,
5153 p_new_txn_hdr_id IN NUMBER,
5154 p_new_txn_tmp_id IN NUMBER,
5155 p_clpn_id IN NUMBER,
5156 p_item_id IN NUMBER,
5157 x_return_status OUT NOCOPY VARCHAR2,
5158 x_msg_count OUT NOCOPY NUMBER,
5159 x_msg_data OUT NOCOPY VARCHAR2 )
5160 IS
5161
5162 v1 WCT_ROW_TYPE;
5163 cnt NUMBER;
5164
5165 l_lpn NUMBER;
5166 BEGIN
5167 error_code := 'INS_MMTT';
5168 if (g_trace_on = 1) then log_event(' In insert mmtt with temp_id '||p_transaction_temp_id ); END IF;
5169
5170 IF p_lpn_id IS NOT NULL THEN
5171 l_lpn := p_lpn_id;
5172
5173 elsIF p_lpn_string IS NOT NULL THEN
5174
5175 SELECT lpn_id INTO L_lpn FROM wms_license_plate_numbers WHERE
5176 license_plate_number = p_lpn_string;
5177
5178 ELSE
5179
5180 l_lpn := NULL;
5181
5182 END IF;
5183
5184 if (g_trace_on = 1) then
5185 log_event(' lpn id IS '||l_lpn);
5186 log_event(' table name is '||table_name);
5187 END IF;
5188
5189 IF( table_name = 'wms_cartonization_temp' ) THEN
5190
5191
5192 SELECT * INTO v1 FROM wms_cartonization_temp WHERE
5193 transaction_temp_id = p_transaction_temp_id AND ROWNUM < 2;
5194
5195 ELSE
5196 --Bug 3296177 code should never come here
5197 if (g_trace_on = 1) THEN log_event('ERROR:INS_MMTT with mtl_material_transactions_temp'); end if;
5198 RAISE fnd_api.g_exc_error;
5199 --SELECT * INTO v1 FROM mtl_material_transactions_temp WHERE
5200 --transaction_temp_id = p_transaction_temp_id;
5201
5202 END IF;
5203
5204 if (g_trace_on = 1) then log_event(' v1.inventory_item_id is '||v1.inventory_item_id); END IF;
5205
5206 v1.primary_quantity := p_primary_quantity;
5207 v1.transaction_quantity := p_transaction_quantity;
5208 v1.secondary_transaction_quantity := p_secondary_quantity; --invconv kkillams
5209 v1.cartonization_id := l_LPN;
5210 v1.container_item_id := p_container_item_id;
5211 v1.last_update_date := Sysdate;
5212 v1.last_updated_by := fnd_global.user_id;
5213 v1.creation_date := Sysdate;
5214 v1.created_by := fnd_global.user_id;
5215
5216
5217 IF p_new_txn_hdr_id IS NOT NULL THEN
5218 v1.transaction_header_id := p_new_txn_hdr_id;
5219 END IF;
5220
5221 IF ( p_new_txn_tmp_id IS NULL AND p_transaction_temp_id > 0 ) THEN
5222
5223 SELECT mtl_material_transactions_s.NEXTVAL
5224 INTO v1.transaction_temp_id
5225 FROM dual;
5226
5227 ELSE
5228
5229 v1.transaction_temp_id := p_new_txn_tmp_id;
5230
5231 END IF;
5232
5233 IF( p_clpn_id IS NOT NULL) THEN
5234 v1.content_lpn_id := p_clpn_id;
5235 END IF;
5236
5237
5238 IF ( p_transaction_temp_id > 0 AND v1.transaction_temp_id > 0 ) then
5239 temp_id_table_index := temp_id_table_index + 1;
5240 temp_id_table(temp_id_table_index).orig_temp_id := p_transaction_temp_id;
5241 temp_id_table(temp_id_table_index).splt_temp_id := v1.transaction_temp_id;
5242 temp_id_table(temp_id_table_index).primary_quantity := v1.primary_quantity;
5243 temp_id_table(temp_id_table_index).secondary_quantity := v1.secondary_transaction_quantity;
5244 END IF;
5245
5246
5247 IF p_item_id IS NOT NULL THEN
5248 v1.inventory_item_id := p_item_id;
5249 END IF;
5250
5251
5252 IF (table_name = 'mtl_material_transactions_temp') THEN
5253
5254 RAISE fnd_api.g_exc_error;
5255 --wms_task_dispatch_engine.insert_mmtt
5256 --(l_mmtt_rec => v1);
5257
5258 ELSE
5259
5260 wms_task_dispatch_engine.insert_wct
5261 (l_wct_rec => v1);
5262
5263 END IF;
5264
5265
5266
5267
5268
5269 END insert_mmtt;
5270
5271
5272
5273
5274
5275
5276
5277 PROCEDURE log_event(
5278 p_message VARCHAR2)
5279 IS
5280
5281 l_module VARCHAR2(255);
5282 l_mesg VARCHAR2(255);
5283 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5284 BEGIN
5285
5286 l_module := 'wms.plsql.' || 'wms_cartnzn_pub' || '.' || 'cartonization';
5287
5288 --inv_pick_wave_pick_confirm_pub.TraceLog(err_msg => p_message,
5289 -- module => 'WMS_CARTNZN_PUB'
5290 -- );
5291
5292
5293 l_mesg := to_char(sysdate, 'YYYY-MM-DD HH:DD:SS') || p_message;
5294
5295 IF (l_debug = 1) THEN
5299
5296 -- dbms_output.put_line(l_mesg);
5297 inv_trx_util_pub.trace(l_mesg, 'WMS_CARTNZN_PUB');
5298 END IF;
5300
5301 END log_event;
5302
5303
5304
5305
5306
5307 PROCEDURE test IS
5308
5309 x_return_status VARCHAR2(100);
5310 x_msg_count NUMBER;
5311 x_msg_data VARCHAR2(300);
5312 mlid NUMBER;
5313 v_qty_per_cont NUMBER;
5314 v_container_item_id NUMBER;
5315 v_return_status VARCHAR2(300);
5316 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5317 BEGIN
5318 /*mlid := 1;
5319 table_name := 'WMS_CARTONIZATION_TEMP';
5320 mlid := do_cartonization(mohdrid =>5388, trxhdrid =>3243813, outbound => 'N', sublvlctrl =>'1');
5321
5322 dbms_output.put_line(mlid);*/
5323
5324
5325 cartonize( p_api_version => 1.0,
5326 p_commit =>fnd_api.g_false,
5327 p_out_bound => 'N',
5328 p_org_id => 1884,
5329 x_return_status => x_return_status,
5330 x_msg_count => x_msg_count,
5331 x_msg_data => x_msg_data,
5332 --p_move_order_header_id => 5388,
5333 p_transaction_header_id => 3243813,
5334 --p_stop_level => 2,
5335 p_packaging_mode => 3
5336 );
5337
5338 /*
5339 ins_wct_rows_into_mmtt(
5340 p_m_o_h_id => 40262,
5341 x_return_status=> x_return_status,
5342 x_msg_count => x_msg_count,
5343 x_msg_data => x_msg_data );
5344
5345 SELECT line_id INTO mlid FROM mtl_txn_request_lines WHERE header_id = 40262
5346 AND roWnum < 2;
5347
5348 wsh_interface.Get_Max_Load_Qty(p_move_order_line_id => mlid,
5349 x_max_load_quantity => v_qty_per_cont,
5350 x_container_item_id => v_container_item_id,
5351 x_return_status => v_return_status);
5352
5353 --dbms_output.put_line(v_qty_per_cont);
5354 --dbms_output.put_line(v_container_item_id);
5355 -- dbms_output.put_line( v_return_status);
5356 */
5357
5358 END test;
5359
5360
5361
5362
5363
5364 FUNCTION do_cartonization( mohdrid NUMBER, trxhdrid NUMBER, outbound VARCHAR2, sublvlctrl VARCHAR2, per_fill VARCHAR2) RETURN NUMBER IS
5365 language java name
5366 'oracle.apps.wms.cartonization.server.Cartonization.start(java.lang.Long, java.lang.Long, java.lang.String, java.lang.String, java.lang.String) return java.lang.Long';
5367
5368
5369 --This procedure inserts records into wms_device_requests table for further
5370 -- processing by device integration code.This procedure is called from
5371 -- WMSCRTNB.pls and WMSTSKUB.pls
5372
5373 PROCEDURE insert_device_request_rec(p_mmtt_row IN mmtt_row)
5374 IS
5375
5376 CURSOR lot_ser_cursor(p_transaction_temp_id NUMBER) IS
5377 SELECT
5378 mtlt.lot_number lot_num,
5379 mtlt.transaction_quantity lot_qty,
5380 msnt.fm_serial_number ser_num
5381 FROM mtl_material_transactions_temp mmtt,
5382 mtl_transaction_lots_temp mtlt,
5383 mtl_serial_numbers_temp msnt
5384 WHERE
5385 mmtt.transaction_temp_id = p_transaction_temp_id
5386 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id(+)
5387 AND mmtt.transaction_temp_id = msnt.transaction_temp_id(+)
5388 AND ((mmtt.transaction_temp_id=msnt.transaction_temp_id
5389 AND mtlt.serial_transaction_temp_id=msnt.transaction_temp_id)
5390 OR 1=1);
5391
5392 l_serial_code NUMBER;
5393 l_lot_code NUMBER;
5394 wdrData wdr_row;
5395 l_device_id NUMBER;
5396 l_qty NUMBER;
5397 l_count NUMBER;
5398 l_bus_event_id NUMBER;
5399
5400 BEGIN
5401
5402
5403 IF wms_device_integration_pvt.wms_call_device_request = 1 THEN
5404 --set in INVPPICB.pls through call to is_device_set_up()
5405
5406 l_bus_event_id :=
5407 WMS_Device_Integration_PVT.wms_be_pick_release;
5408
5409 ELSIF wms_device_integration_pvt.wms_call_device_request = 2 THEN
5410 --set in INVUTILB.pls/WMSTSKUB.pls through call to is_device_set_up()
5411
5412 l_bus_event_id :=
5413 WMS_Device_Integration_PVT.wms_be_mo_task_alloc;
5414 END IF;
5415
5416
5417 IF wms_device_integration_pvt.wms_call_device_request IS NOT NULL THEN
5418 --insert line for load operation
5419 INSERT INTO wms_device_requests (request_id,
5420 task_id,
5421 task_summary,
5422 task_type_id,
5423 business_event_id,
5424 organization_id,
5425 subinventory_code,
5426 locator_id,
5427 transfer_org_id,
5428 transfer_sub_code,
5429 transfer_loc_id,
5430 inventory_item_id,
5434 xfer_lpn_id,--4472870
5431 revision,
5432 uom,
5433 lpn_id,
5435 transaction_quantity,
5436 last_update_date,
5437 last_updated_by) VALUES
5438
5439 ( WMS_Device_Integration_PVT.wms_pkRel_dev_req_id, --global var so that for all lines in a pick release, it remains same
5440 p_mmtt_row.transaction_temp_id,
5441 'Y',
5442 1, --"LOAD"
5443 l_bus_event_id,
5444 p_mmtt_row.organization_id , --use you local variables for these values
5445 p_mmtt_row.subinventory_code,
5446 p_mmtt_row.locator_id ,
5447 p_mmtt_row.transfer_organization,
5448 NULL,
5449 NULL,
5450 p_mmtt_row.inventory_item_id,
5451 p_mmtt_row.revision,
5452 p_mmtt_row.transaction_uom,
5453 p_mmtt_row.allocated_lpn_id,
5454 p_mmtt_row.cartonization_id,
5455 p_mmtt_row.transaction_quantity,
5456 Sysdate,
5457 FND_GLOBAL.USER_ID);
5458
5459
5460 --insert another line for drop
5461 INSERT INTO wms_device_requests (request_id,
5462 task_id,
5463 task_summary,
5464 task_type_id,
5465 business_event_id,
5466 organization_id,
5467 subinventory_code,
5468 locator_id,
5469 transfer_org_id,
5470 transfer_sub_code,
5471 transfer_loc_id,
5472 inventory_item_id,
5473 revision,
5474 uom,
5475 lpn_id,
5476 xfer_lpn_id, --4472870
5477 transaction_quantity,
5478 last_update_date,
5479 last_updated_by) VALUES
5480
5481 ( WMS_Device_Integration_PVT.wms_pkRel_dev_req_id, --global var so that for all lines in a pick release, it remains same
5482 p_mmtt_row.transaction_temp_id,
5483 'Y',
5484 2, --"DROP"
5485 l_bus_event_id,
5486 p_mmtt_row.organization_id ,
5487 NULL,
5488 NULL,
5489 p_mmtt_row.transfer_organization,
5490 p_mmtt_row.transfer_subinventory ,
5491 p_mmtt_row.transfer_to_location ,
5492 p_mmtt_row.inventory_item_id,
5493 p_mmtt_row.revision,
5494 p_mmtt_row.transaction_uom,
5495 p_mmtt_row.allocated_lpn_id,
5496 p_mmtt_row.cartonization_id,
5497 p_mmtt_row.transaction_quantity,
5498 Sysdate,
5499 FND_GLOBAL.USER_ID);
5500
5501 wdrdata.request_id := WMS_Device_Integration_PVT.wms_pkrel_dev_req_id;
5502 wdrData.organization_id := p_mmtt_row.organization_id;
5503 wdrData.subinventory_code := p_mmtt_row.subinventory_code ;
5504 wdrData.business_event_id := l_bus_event_id;
5505 wdrData.locator_id := p_mmtt_row.locator_id;
5506 wdrData.task_id := p_mmtt_row.transaction_temp_id ;
5507 wdrData.task_summary := 'Y';
5508 wdrData.transfer_org_id := p_mmtt_row.transfer_organization;
5509 wdrData.transfer_sub_code := p_mmtt_row.transfer_subinventory;
5510 wdrData.transfer_loc_id := p_mmtt_row.transfer_to_location;
5511
5512
5513 --Call an api to get the device, this API also updates above
5514 --inserted records WITH found matching device id
5515 l_device_id := WMS_Device_Integration_PVT.SELECT_DEVICE(wdrData,'Y',NULL);
5516
5517
5518
5519 IF l_device_id <> 0 THEN --process further only if device IS found
5520
5521 --CHECK whether it is a lot/Serial controlled item
5522 SELECT
5523 msi.serial_number_control_code,
5524 msi.lot_control_code
5525 INTO
5526 l_serial_code,
5527 l_lot_code
5528 FROM mtl_system_items msi
5529 WHERE msi.inventory_item_id = p_mmtt_row.inventory_item_id
5530 AND msi.organization_id = p_mmtt_row.organization_id;
5531
5532
5533 IF (l_lot_code >1 OR l_serial_code >1) THEN --LOT OR/AND SERIAL ITEMS
5534
5535 --check to see whether need to insert lot/ser record
5536 IF wms_device_integration_pvt.wms_insert_lotSer_rec_WDR = 1 THEN
5537
5538 FOR l_rec IN lot_ser_cursor(p_mmtt_row.transaction_temp_id) LOOP
5539 IF (l_rec.lot_num IS NOT NULL OR l_rec.ser_num IS NOT NULL) THEN
5540 IF (l_rec.ser_num IS NOT NULL) THEN
5541 l_qty := 1;
5542 ELSE
5543 l_qty := l_rec.lot_qty;
5544 END IF;
5545 l_count := l_count + 1;
5546 INSERT INTO wms_device_requests
5550 sequence_id,
5547 (request_id,
5548 task_id,
5549 relation_id,
5551 task_summary,
5552 task_type_id,
5553 business_event_id,
5554 organization_id,
5555 subinventory_code,
5556 locator_id,
5557 transfer_org_id,
5558 transfer_sub_code,
5559 transfer_loc_id,
5560 inventory_item_id,
5561 revision,
5562 uom,
5563 lot_number,
5564 lot_qty,
5565 serial_number,
5566 lpn_id,
5567 xfer_lpn_id,
5568 transaction_quantity,
5569 device_id,
5570 status_code,
5571 last_update_date,
5572 last_updated_by,
5573 last_update_login)
5574 VALUES
5575 (WMS_Device_Integration_PVT.wms_pkRel_dev_req_id,
5576 p_mmtt_row.transaction_temp_id,
5577 NULL,
5578 NULL,
5579 'N',
5580 NULL,
5581 l_bus_event_id,
5582 p_mmtt_row.organization_id,
5583 p_mmtt_row.subinventory_code,
5584 p_mmtt_row.locator_id,
5585 p_mmtt_row.transfer_organization,
5586 p_mmtt_row.transfer_subinventory,
5587 p_mmtt_row.transfer_to_location,
5588 p_mmtt_row.inventory_item_id,
5589 p_mmtt_row.revision,
5590 p_mmtt_row.TRANSACTION_uom,
5591 l_rec.lot_num,
5592 l_rec.lot_qty,
5593 l_rec.ser_num,
5594 p_mmtt_row.allocated_lpn_id,
5595 p_mmtt_row.cartonization_id,
5596 l_qty,
5597 l_device_id,
5598 'S',
5599 p_mmtt_row.last_update_date,
5600 p_mmtt_row.last_updated_by,
5601 p_mmtt_row.last_update_login);
5602 END IF;
5603 END LOOP;
5604
5605 IF(l_count = 0) THEN
5606 if (g_trace_on = 1) then
5607 log_event('Error in inserting lot serial details in WDR,no data');
5608 END IF;
5609
5610 END IF;
5611
5612 END IF;--Lot/serial enabled check
5613
5614 END IF;--lot/serial item check
5615
5616 END IF; -- device IS found
5617
5618 END IF;--p_mmtt_row.transaction_temp_id > 0
5619
5620
5621 END insert_device_request_rec;
5622
5623
5624 PROCEDURE ins_wct_rows_into_mmtt(
5625 p_m_o_h_id IN NUMBER,
5626 p_outbound IN VARCHAR2,
5627 x_return_status OUT NOCOPY VARCHAR2,
5628 x_msg_count OUT NOCOPY NUMBER,
5629 x_msg_data OUT NOCOPY VARCHAR2)
5630 is
5631 CURSOR wct_rows IS
5632 SELECT wct.* FROM wms_cartonization_temp wct,
5633 mtl_txn_request_lines mtrl WHERE wct.move_order_line_id =
5634 mtrl.line_id AND mtrl.header_id = p_m_o_h_id;
5635
5636 -- patchset J bulk picking ---
5637 -- following cursor will be used for calling from concurrent program --
5638 -- also after patchset J, this cursor will replace wct_row since no need to
5639 -- query by move order header and also to query parent lines ---------------------
5640 CURSOR wct_rows_bulk IS
5641 SELECT wct.* FROM wms_cartonization_temp wct;
5642
5643 -- end of patchset J bulk picking --------------
5644
5645 CURSOR bpack_rows IS
5646 SELECT * FROM wms_cartonization_temp
5647 WHERE
5648 transaction_header_id = p_m_o_h_id;
5649
5650 CURSOR lot_ser_cursor(p_transaction_temp_id NUMBER) IS
5651 SELECT
5652 mtlt.lot_number lot_num,
5653 mtlt.transaction_quantity lot_qty,
5654 msnt.fm_serial_number ser_num
5655 FROM mtl_material_transactions_temp mmtt,
5656 mtl_transaction_lots_temp mtlt,
5657 mtl_serial_numbers_temp msnt
5658 WHERE
5659 mmtt.transaction_temp_id = p_transaction_temp_id
5660 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id(+)
5661 AND mmtt.transaction_temp_id = msnt.transaction_temp_id(+)
5662 AND ((mmtt.transaction_temp_id=msnt.transaction_temp_id
5663 AND mtlt.serial_transaction_temp_id=msnt.transaction_temp_id)
5664 OR 1=1);
5665
5666 v2 WCT_ROW_TYPE;
5667 v1 MMTT_ROW_TYPE;
5668 v_lpn VARCHAR2(255);
5669 v_exist VARCHAR2(1);
5670 l_msg VARCHAR2(255);
5671
5672 l_serial_code NUMBER;
5673 l_lot_code NUMBER;
5674 wdrData wdr_row;
5675 l_device_id NUMBER;
5676 l_qty NUMBER;
5677 l_count NUMBER;
5678 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5679 BEGIN
5680 error_code := 'INS_WCT_ROWS_TO_MMTT';
5681 if (g_trace_on = 1) then log_event(' Entered insert wct rows to mmtt'||p_m_o_h_id); END IF;
5685 IF( p_outbound IS NOT NULL AND p_outbound = 'N') THEN
5682 -- Initialize API return status to success
5683 x_return_status := fnd_api.g_ret_sts_success;
5684
5686 if (g_trace_on = 1) then log_event(' open bpack_rows'); END IF;
5687 OPEN bpack_rows;
5688 ELSE
5689 IF G_CURRENT_RELEASE_LEVEL < G_J_RELEASE_LEVEL THEN -- bulk picking patchset J ---
5690 if (g_trace_on = 1) then log_event(' open wct_rows'); END IF;
5691 OPEN wct_rows;
5692 ELSE
5693 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING --START'); end if;
5694 OPEN wct_rows_bulk;
5695 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING --END'); end if;
5696 END IF;
5697 END IF;
5698
5699 LOOP
5700
5701 IF( p_outbound IS NOT NULL AND p_outbound = 'N') THEN
5702 if (g_trace_on = 1) then log_event(' fetching a bpack row '); END IF;
5703 FETCH bpack_rows INTO v2;
5704 EXIT WHEN bpack_rows%notfound;
5705 if (g_trace_on = 1) then log_event(' fetched a row '); END IF;
5706 ELSE
5707 IF G_CURRENT_RELEASE_LEVEL < G_J_RELEASE_LEVEL THEN -- bulk picking patchset J ---
5708 if (g_trace_on = 1) then log_event(' fetching a wct row '); END IF;
5709 FETCH wct_rows INTO v2;
5710 EXIT WHEN wct_rows%notfound;
5711 if (g_trace_on = 1) then log_event(' fetched a row '); END IF;
5712 ELSE
5713 if (g_trace_on = 1) then -- log_event('PATCHSET J-- BULK PICKING --START');
5714 log_event(' fetching a wct row '); END IF;
5715 FETCH wct_rows_bulk INTO v2;
5716 EXIT WHEN wct_rows_bulk%notfound;
5717 if (g_trace_on = 1) then log_event(' fetched a row '); END IF;
5718 -- if (g_trace_on = 1) then log_event('PATCHSET J-- BULK PICKING --END'); end if;
5719 END IF;
5720
5721 END IF;
5722
5723 v1 := to_mmtt(v2);
5724
5725 IF packaging_mode IN (wms_cartnzn_pub.int_bp_pkg_mode,
5726 wms_cartnzn_pub.mob_bp_pkg_mode ) THEN
5727
5728 v1.transfer_lpn_id := v1.cartonization_id;
5729
5730 END IF;
5731
5732
5733
5734 IF( v1.transaction_temp_id > 0 ) then
5735
5736 --INSERT RECORDS INTO WMS_DEVICE_REQUESTS TABLE
5737 insert_device_request_rec(v1);
5738 --/////////////////
5739
5740 if (g_trace_on = 1) then log_event(' temp_id > 0'); END IF;
5741
5742 v_exist := 'N';
5743
5744 BEGIN
5745 SELECT 'Y' INTO v_exist FROM dual
5746 WHERE
5747 exists ( SELECT transaction_temp_id FROM mtl_material_transactions_temp
5748 WHERE transaction_temp_id = v1.transaction_temp_id);
5749 EXCEPTION
5750 WHEN no_data_found THEN
5751 v_exist := 'N';
5752 END;
5753
5754
5755 if (g_trace_on = 1) then log_event(' row_exist '||v_exist); END IF;
5756
5757 IF v1.cartonization_id IS NOT NULL THEN
5758 IF (g_trace_on = 1) then log_event(' Cartonization id '||v1.cartonization_id); END IF;
5759 SELECT license_plate_number INTO v_lpn FROM wms_license_plate_numbers WHERE
5760 lpn_id = v1.cartonization_id;
5761 ELSE
5762 v_lpn := NULL;
5763 --2513907 fix
5764 IF v1.container_item_id IS NULL THEN
5765 v1.container_item_id := -1;
5766 END IF;
5767 --2513907 fix
5768 END IF;
5769
5770 if (g_trace_on = 1) then log_event(' After the cartonization id condition '); END IF;
5771
5772 table_name := 'mtl_material_transactions_temp';
5773
5774
5775 IF v_exist = 'Y' THEN
5776
5777 if (g_trace_on = 1) then
5778 log_event('calling update mmtt for tempid:'||v1.transaction_temp_id);
5779 log_event(' primary quantity:'||v1.primary_quantity);
5780 log_event(' transaction_quantity:'|| v1.transaction_quantity);
5781 log_event(' secondary transaction_quantity:'|| v1.secondary_transaction_quantity); --invconv kkillams
5782 END IF;
5783
5784 UPDATE_MMTT(
5785 p_transaction_temp_id => v1.transaction_temp_id,
5786 p_primary_quantity => v1.primary_quantity,
5787 p_transaction_quantity => v1.transaction_quantity,
5788 p_secondary_quantity => v1.secondary_transaction_quantity, --invconv kkillams
5789 --p_LPN_string => v_lpn,
5790 p_lpn_id => v1.cartonization_id,
5791 p_container_item_id => v1.container_item_id,
5792 p_parent_line_id => v1.parent_line_id,
5793 x_return_status => x_return_status,
5794 x_msg_count => x_msg_count,
5795 x_msg_data => x_msg_data );
5796
5797 ELSIF v_EXIST = 'N' THEN
5801 ELSE
5798
5799 if (g_trace_on = 1) then log_event(' inserting row into mmtt for temp id :'||v1.transaction_temp_id); END IF;
5800 wms_task_dispatch_engine.insert_mmtt(l_mmtt_rec => v1);
5802 RAISE fnd_api.g_exc_unexpected_error;
5803
5804 END IF;
5805 END IF;
5806
5807 END LOOP;
5808
5809 IF( p_outbound IS NOT NULL AND p_outbound = 'N') THEN
5810 IF( bpack_rows%isopen) then
5811 close bpack_rows;
5812 END IF;
5813
5814 ELSE
5815
5816 IF( wct_rows%isopen ) then
5817 close wct_rows;
5818 END IF;
5819
5820 END IF;
5821
5822
5823
5824 EXCEPTION
5825 WHEN OTHERS THEN
5826 IF( wct_rows%isopen ) then
5827 CLOSE wct_rows;
5828 END IF;
5829 --l_msg := Sqlerrm;
5830 if (g_trace_on = 1) then log_event('SQL Error Message ' || SQLERRM); END IF;
5831 if (g_trace_on = 1) then log_event('SQL Error Code ' || SQLCODE); END IF;
5832 if (g_trace_on = 1) then log_event('error OCCURRED IN INSERTING WCT ROWS BACK TO MMTT'); END IF;
5833 RAISE fnd_api.g_exc_unexpected_error;
5834
5835
5836 END ins_wct_rows_into_mmtt;
5837
5838 FUNCTION get_log_flag RETURN VARCHAR2 IS
5839
5840 log_flag VARCHAR2(1) := 'Y';
5841 --Bug 3319754 changes. Also made change so that get_log_flag
5842 --returns 'Y' irrespective of level
5843 g_trace_on number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5844 --l_dbg_lvl NUMBER := 0;
5845
5846 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5847 BEGIN
5848 error_code := 'GET_LOG_FLAG';
5849
5850 -- select fnd_profile.value('INV_DEBUG_TRACE')
5851 -- into g_trace_on
5852 -- from dual;
5853
5854 -- if( g_trace_on = 1 ) then
5855 -- select fnd_profile.value('INV_DEBUG_LEVEL')
5856 -- into l_dbg_lvl
5857 -- from dual;
5858 -- END IF;
5859
5860 if(g_trace_on = 1) THEN --AND l_dbg_lvl > 5 then
5861 log_flag := 'Y';
5862 ELSE
5863 log_flag := 'N';
5864 END IF;
5865
5866 RETURN log_flag;
5867
5868
5869 EXCEPTION
5870 when others then
5871 null;
5872 END get_log_flag;
5873
5874 PROCEDURE cartonize_single_item (
5875 x_return_status OUT NOCOPY VARCHAR2,
5876 x_msg_count OUT NOCOPY NUMBER,
5877 x_msg_data OUT NOCOPY VARCHAR2,
5878 p_out_bound IN VARCHAR2,
5879 p_org_id IN NUMBER,
5880 p_move_order_header_id IN NUMBER,
5881 p_subinventory_name IN VARCHAR2 DEFAULT NULL
5882 )
5883 IS
5884 l_api_name CONSTANT VARCHAR2(30) := 'cartonize_single_item';
5885 l_api_version CONSTANT NUMBER := 1.0;
5886 v1 WCT_ROW_TYPE;
5887 cartonization_profile VARCHAR2(1) := 'Y';
5888 v_cart_value NUMBER;
5889 v_container_item_id NUMBER:= NULL;
5890 v_qty NUMBER:= -1;
5891 v_qty_per_cont NUMBER := -1;
5892 v_tr_qty_per_cont NUMBER:= -1;
5893 v_sec_tr_qty_per_cont NUMBER:= -1;
5894 v_lpn_out VARCHAR2(30) := ' ';
5895 v_primary_uom_code VARCHAR2(3);
5896 v_loop NUMBER := 0;
5897 v_process_id NUMBER := 0;
5898 v_ttemp_id NUMBER := 0;
5899 v_lpn_id_out NUMBER := 0;
5900 v_lpn_id NUMBER := 0;
5901 ret_value NUMBER := 29;
5902 v_return_status VARCHAR2(1);
5903 v_left_prim_quant NUMBER;
5904 v_left_tr_quant NUMBER;
5905 v_sec_left_tr_quant NUMBER;
5906 v_sublvlctrl VARCHAR2(1) := '2';
5907 --Bug 2720653 fix
5908 --l_lpn_id_tbl inv_label.transaction_id_rec_type;
5909 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
5910 l_msg_count NUMBER;
5911 l_msg_data VARCHAR2(400);
5912 l_progress VARCHAR2(10);
5913 l_label_status VARCHAR2(500);
5914 l_counter NUMBER := 0;
5915 v_prev_move_order_line_id NUMBER := -999;
5916 space_avail_for NUMBER := 0;
5917 tr_space_avail_for NUMBER := 0;
5918 sec_tr_space_avail_for NUMBER := 0; --invconv kkillams
5919 curr_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE ;
5920 v_lot_control_code NUMBER := NULL;
5921 v_serial_control_code NUMBER := NULL;
5922 api_table_index NUMBER := 0;
5923 l_current_header_id NUMBER := NULL;
5924 l_stop_level NUMBER := -1;
5925 v_prev_item_id NUMBER := -999;
5926 l_prev_package_id NUMBER := NULL;
5927 l_temp_id NUMBER := NULL;
5928 l_item_id NUMBER := NULL;
5929 l_qty NUMBER := NULL;
5930 l_tr_qty NUMBER := NULL;
5931 l_sec_tr_qty NUMBER := NULL;
5932 l_clpn_id NUMBER := NULL;
5933 l_citem_id NUMBER := NULL;
5934 l_package_id NUMBER := NULL;
5935 l_upd_qty_flag VARCHAR2(1) := NULL;
5936 l_prev_header_id NUMBER := NULL;
5937 l_header_id NUMBER := NULL;
5938 L_no_pkgs_gen VARCHAR2(1);
5939 l_prev_condition VARCHAR2(1);
5940 l_revision_code VARCHAR2(1);
5944 l_is_lot_control BOOLEAN;
5941 l_lot_code VARCHAR2(1);
5942 l_serial_code VARCHAR2(1);
5943 l_is_revision_control BOOLEAN;
5945 l_is_serial_control BOOLEAN;
5946 l_rqoh NUMBER;
5947 l_qr NUMBER;
5948 l_qs NUMBER;
5949 l_atr NUMBER;
5950 l_att NUMBER;
5951 l_qoh NUMBER;
5952 l_lpn_fully_allocated VARCHAR2(1) :='N';
5953 percent_fill_basis VARCHAR2(1) :='W';
5954 l_valid_container VARCHAR2(1) := 'Y';
5955
5956 l_cartonize_sales_orders VARCHAR2(1) :=NULL;
5957 l_cartonize_manufacturing VARCHAR2(1) :=NULL;
5958 l_move_order_type NUMBER;
5959 l_pack_level number := 0;
5960
5961 l_uom_rate number;
5962
5963 CURSOR wct_rows IS
5964 SELECT wct.* FROM wms_cartonization_temp wct,
5965 mtl_txn_request_lines mtrl,
5966 mtl_secondary_inventories sub,
5967 mtl_parameters mtlp
5968 WHERE
5969 wct.move_order_line_id =mtrl.line_id
5970 AND mtrl.header_id = p_move_order_header_id
5971 AND wct.cartonization_id IS null
5972 AND mtlp.organization_id = wct.organization_id
5973 AND sub.organization_id = wct.organization_id
5974 AND wct.transfer_lpn_id IS NULL
5975 AND sub.secondary_inventory_name = wct.subinventory_code
5976 AND((Nvl(mtlp.cartonization_flag,-1) = 1) OR
5977 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
5978 ORDER BY wct.inventory_item_id,
5979 wct.move_order_line_id,
5980 Abs(wct.transaction_temp_id);
5981
5982 CURSOR wct_sub_rows IS
5983 SELECT wct.* FROM wms_cartonization_temp wct,
5984 mtl_txn_request_lines mtrl,
5985 mtl_secondary_inventories sub,
5986 mtl_parameters mtlp
5987 WHERE
5988 wct.move_order_line_id =mtrl.line_id
5989 AND mtrl.header_id = p_move_order_header_id
5990 AND wct.cartonization_id IS null
5991 AND mtlp.organization_id = wct.organization_id
5992 AND sub.organization_id = wct.organization_id
5993 AND wct.transfer_lpn_id IS NULL
5994 AND sub.secondary_inventory_name = wct.subinventory_code
5995 AND wct.subinventory_code = p_subinventory_name
5996 AND((Nvl(mtlp.cartonization_flag,-1) = 1) OR
5997 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
5998 ORDER BY wct.inventory_item_id,
5999 wct.move_order_line_id,
6000 Abs(wct.transaction_temp_id);
6001
6002 CURSOR OB_LBPRT IS
6003 SELECT DISTINCT mmtt.cartonization_id FROM
6004 --2513907 fix
6005 wms_cartonization_temp mmtt,
6006 --mtl_material_transactions_temp mmtt,
6007 mtl_txn_request_lines mtrl WHERE
6008 mmtt.move_order_line_id = mtrl.line_id
6009 AND mtrl.header_id = p_move_order_header_id
6010 AND mmtt.cartonization_id IS NOT NULL
6011 ORDER BY mmtt.cartonization_id;
6012
6013 CURSOR bpack_rows(p_hdr_id NUMBER) IS
6014 SELECT * FROM
6015 wms_cartonization_temp
6016 WHERE
6017 transaction_header_id = p_hdr_id
6018 AND cartonization_id IS NULL
6019 AND transfer_lpn_id IS NULL
6020 order by move_order_line_id,
6021 decode(content_lpn_id,null,inventory_item_id,
6022 decode(sign(p_hdr_id),
6023 -1,
6024 inventory_item_id,
6025 wms_cartnzn_pub.Get_LPN_ItemId(content_lpn_id)
6026 ) ),Abs(transaction_temp_id);
6027
6028 CURSOR packages(p_hdr_id NUMBER) IS
6029 SELECT
6030 transaction_temp_id,
6031 inventory_item_id,
6032 primary_quantity,
6033 transaction_quantity,
6034 secondary_transaction_quantity, --invconv kkillams
6035 content_lpn_id,
6036 container_item_id,
6037 cartonization_id
6038 FROM
6039 wms_cartonization_temp
6040 WHERE
6041 transaction_header_id = p_hdr_id
6042 order by cartonization_id;
6043
6044 CURSOR opackages(p_hdr_id NUMBER) IS
6045 SELECT
6046 wct.transaction_temp_id,
6047 wct.inventory_item_id,
6048 wct.primary_quantity,
6049 wct.transaction_quantity,
6050 wct.secondary_transaction_quantity, --invconv kkillams
6051 wct.content_lpn_id,
6052 wct.container_item_id,
6053 wct.cartonization_id
6054 FROM
6055 wms_cartonization_temp wct,
6056 mtl_txn_request_lines mtrl
6057 WHERE
6058 wct.move_order_line_id = mtrl.line_id AND
6059 mtrl.header_id = p_hdr_id
6060 order by wct.cartonization_id;
6061
6062
6063
6064 BEGIN
6065
6066 IF (g_trace_on = 1) THEN
6067 log_event(' Inside CARTONIZE_SINGLE_ITEM()');
6068 END IF;
6069
6070 outbound := 'Y';
6071 error_code := 'CARTONIZE 100';
6072
6073 IF (g_trace_on = 1) THEN
6074 log_event(' outbound = '|| outbound || ' pack level ' || pack_level);
6075 log_event(' restrcited subinventory = '|| p_subinventory_name);
6076 END IF;
6077
6078 IF p_subinventory_name IS NOT NULL THEN
6079 IF (g_trace_on = 1) THEN
6080 log_event(' Opening cursor wct_sub_row ');
6081 END IF;
6082 OPEN wct_sub_rows;
6086 END IF;
6083 ELSE
6084 IF (g_trace_on = 1) THEN
6085 log_event(' Opening cursor wct_row ');
6087 OPEN wct_rows;
6088 END IF;
6089
6090 -- OPEN wct_rows;
6091
6092 LOOP
6093 IF( (outbound = 'Y') AND (pack_level = 0)) THEN
6094
6095 IF p_subinventory_name IS NOT NULL THEN
6096 FETCH wct_sub_rows INTO v1;
6097 IF (g_trace_on = 1) THEN
6098 log_event('wct_sub_rows Fetch success');
6099 END IF;
6100 EXIT WHEN wct_sub_rows%NOTFOUND;
6101 ELSE
6102 FETCH wct_rows INTO v1;
6103 IF (g_trace_on = 1) THEN
6104 log_event('wct_rows Fetch success');
6105 END IF;
6106 EXIT WHEN wct_rows%NOTFOUND;
6107 END IF;
6108
6109 IF NOT INV_CACHE.set_item_rec(v1.organization_id, v1.inventory_item_id) THEN
6110 IF (g_trace_on = 1) THEN
6111 log_event('Inventory Cache Set Item Rec Failed');
6112 END IF;
6113 RAISE fnd_api.g_exc_unexpected_error;
6114 END IF;
6115
6116 l_revision_code := inv_cache.item_rec.revision_qty_control_code;
6117 l_lot_code := inv_cache.item_rec.lot_control_code;
6118 l_serial_code := inv_cache.item_rec.serial_number_control_code;
6119
6120 IF (g_trace_on = 1) THEN
6121 log_event('revision code : '|| l_revision_code);
6122 log_event('lot code : '|| l_lot_code);
6123 log_event('serial code : '|| l_serial_code);
6124 END IF;
6125
6126 IF l_revision_code> 1 THEN
6127 l_is_revision_control := TRUE;
6128 ELSE
6129 l_is_revision_control := FALSE;
6130 END IF;
6131
6132 IF l_lot_code > 1 THEN
6133 l_is_lot_control := TRUE;
6134 ELSE
6135 l_is_lot_control := FALSE;
6136 END IF;
6137
6138 IF (l_serial_code>1 AND l_serial_code<>6) THEN
6139 l_is_serial_control := TRUE;
6140 ELSE
6141 l_is_serial_control := FALSE;
6142 END IF;
6143
6144 IF (v1.allocated_lpn_id IS NOT NULL ) THEN
6145 -- Bug 3740610 No need to call qty tree,getting on-hand qty from table
6146 SELECT NVL(SUM(primary_transaction_quantity),0)
6147 into l_qoh FROM mtl_onhand_quantities_detail
6148 WHERE organization_id = v1.organization_id
6149 AND subinventory_code = v1.subinventory_code
6150 AND locator_id = v1.locator_id
6151 AND lpn_id = v1.allocated_lpn_id;
6152
6153 IF (g_trace_on = 1) THEN log_event('lpn_id' || v1.allocated_lpn_id);
6154 log_event('l_qoh' || l_qoh);
6155 log_event('PrimaryQty'|| v1.primary_quantity);
6156 END IF;
6157
6158 --Bug 3740610 Comparing on-hand qty with primary_qty of mmtt
6159
6160 IF (l_qoh = v1.primary_quantity) THEN
6161 l_lpn_fully_allocated := 'Y';
6162 t_lpn_alloc_flag_table(v1.transaction_temp_id).transaction_temp_id := v1.transaction_temp_id;
6163 t_lpn_alloc_flag_table(v1.transaction_temp_id).lpn_alloc_flag := 'Y';
6164
6165 ELSE
6166 l_lpn_fully_allocated := 'N';
6167 t_lpn_alloc_flag_table(v1.transaction_temp_id).transaction_temp_id := v1.transaction_temp_id;
6168 t_lpn_alloc_flag_table(v1.transaction_temp_id).lpn_alloc_flag := 'N';
6169
6170 END IF;
6171 ELSE
6172 l_lpn_fully_allocated := 'Y';
6173 t_lpn_alloc_flag_table(v1.transaction_temp_id).transaction_temp_id := v1.transaction_temp_id;
6174 t_lpn_alloc_flag_table(v1.transaction_temp_id).lpn_alloc_flag := 'Y';
6175
6176 END IF ;
6177
6178 END IF;
6179
6180 IF (g_trace_on = 1) THEN
6181 log_event(' Fetch succeeded');
6182 log_event('lpn_fully_allocated:'||l_lpn_fully_allocated);
6183 log_event('lpn_id after if:'||v1.allocated_lpn_id);
6184 END IF;
6185
6186 IF (v1.allocated_lpn_id IS NOT NULL)
6187 AND (l_lpn_fully_allocated = 'Y') THEN
6188 null;
6189 ELSE
6190 IF (g_trace_on = 1) THEN
6191 log_event('v1.transaction_temp_id : ' || v1.transaction_temp_id);
6192 END IF;
6193
6194 --populate lpn_alloc_flag with null for loose item
6195 t_lpn_alloc_flag_table(v1.transaction_temp_id).transaction_temp_id := v1.transaction_temp_id;
6196 t_lpn_alloc_flag_table(v1.transaction_temp_id).lpn_alloc_flag := NULL;
6197
6198 -- SELECT v1.transaction_temp_id, null
6199 -- INTO t_lpn_alloc_flag_table(v1.transaction_temp_id)
6200 -- FROM dual;
6201
6202 -- If the content_lpn_id is populated on the mmtt record
6203 -- could be two cases. Either we are trying to pack an LPN
6204 -- or a package. We will have packages poulated in this
6205 -- column only by multi level cartonization and when it
6209
6206 -- does that, the row is inserted with negative header id
6207 -- Basing on this we either get the item associated with
6208 -- the lpn, or item associated with the package
6210 IF ( v1.content_lpn_id IS NOT NULL ) THEN
6211 IF (g_trace_on = 1) THEN log_event(' content_lpn_id IS NOT NULL'); END IF;
6212 IF v1.transaction_header_id < 0 THEN
6213 error_code := 'CARTONIZE 150';
6214 --THe content_lpn_id has a package in it ..
6215 --v1.inventory_item_id := Get_package_ItemId(v1.content_lpn_id);
6216 ELSE
6217 error_code := 'CARTONIZE 160';
6218 --THe content_lpn_id has a LPN in it ..
6219 v1.inventory_item_id := Get_LPN_ItemId(v1.content_lpn_id);
6220 END IF;
6221 -- When we are packaing an lpn or a package the qty is
6222 -- always 1
6223 v1.primary_quantity := 1;
6224 v1.transaction_quantity := 1;
6225 END IF;
6226
6227 error_code := 'CARTONIZE 170';
6228
6229 v_primary_uom_code := inv_cache.item_rec.primary_uom_code;
6230
6231 IF ( v1.content_lpn_id IS NOT NULL ) THEN
6232 -- We want to set the transaction uom same as primary uom
6233 v1.transaction_uom := v_primary_uom_code;
6234 END IF;
6235
6236 IF (g_trace_on = 1) THEN
6237 log_event(' inventory_item_id:'||v1.inventory_item_id);
6238 log_event(' primary_quantity:'||v1.primary_quantity);
6239 log_event(' primary_uom_code:'||v_primary_uom_code);
6240 log_event(' transaction_quantity:'||v1.transaction_quantity);
6241 log_event(' transaction_uom:'||v1.transaction_uom);
6242 log_event(' secondary_transaction_quantity:'||v1.secondary_transaction_quantity); --invconv kkillams
6243 log_event(' secondary_uom_code:'||v1.secondary_uom_code); --invconv kkillams
6244 END IF;
6245
6246 IF (outbound = 'Y')
6247 AND (pack_level = 0)
6248 AND (v1.inventory_item_id <> v_prev_item_id) THEN
6249 l_prev_condition := 'Y';
6250 ELSIF (outbound = 'Y')
6251 AND (pack_level <> 0)
6252 AND ((v_prev_move_order_line_id <> v1.move_order_line_id)
6253 OR (v1.inventory_item_id <> v_prev_item_id) ) THEN
6254 l_prev_condition := 'Y';
6255 ELSIF (outbound = 'N') AND ( v1.inventory_item_id <> v_prev_item_id) THEN
6256 l_prev_condition := 'Y';
6257 ELSE
6258 l_prev_condition := 'N';
6259 END IF;
6260
6261 IF (g_trace_on = 1) then log_event(' l_prev_condition '||l_prev_condition); END IF;
6262 -- The below condition is used when to make a
6263 -- call to the an api that returns conatiner item relation
6264 -- ship if present
6265 -- In outbound mode
6266 -- you have to call this when previous move order line id
6267 -- is different from the current one
6268 -- In the inbound mode
6269 -- We need to call if the previous item is different form
6270 -- the current item
6271
6272 IF l_prev_condition = 'Y' THEN
6273 IF (g_trace_on = 1) then log_event(' call wms_container_pub.container_required_qty api for item id '||v1.inventory_item_id); END IF;
6274
6275 v_prev_item_id := v1.inventory_item_id;
6276 v_prev_move_order_line_id := v1.move_order_line_id;
6277 v_container_item_id := NULL;
6278 v_qty_per_cont := -1;
6279 v_qty := -1;
6280 space_avail_for := 0;
6281 --Bug 2478970 fix
6282 l_valid_container := 'Y';
6283
6284 IF (outbound = 'Y') AND (pack_level = 0)
6285 AND (packaging_mode = wms_cartnzn_pub.pr_pkg_mode) THEN
6286 error_code := 'CARTONIZE 180';
6287 wsh_interface.Get_Max_Load_Qty(p_move_order_line_id => v1.move_order_line_id,
6288 x_max_load_quantity => v_qty_per_cont,
6289 x_container_item_id => v_container_item_id,
6290 x_return_status => v_return_status);
6291
6292 l_valid_container := 'Y'; --Undoing 2478970 fix
6293
6294 IF( (v_return_status = fnd_api.g_ret_sts_success) AND
6295 (v_qty_per_cont > 0) AND
6296 (v_container_item_id IS NOT NULL) AND
6297 (v_container_item_id > 0) ) THEN
6298
6299 v_qty := ceil(v1.primary_quantity/v_qty_per_cont);
6300 -- This quantity needs to be recalculated. This is
6301 -- poulated to pass the check marked by '#chk1'
6302 END IF;
6303
6304 IF (g_trace_on = 1) THEN
6308 END IF;
6305 log_event('wsh_interface.Get_Max_Load_Qty return status'||v_return_status);
6306 log_event('container '||v_container_item_id);
6307 log_event('Number of dum containers '||v_qty);
6309
6310 v_prev_move_order_line_id := v1.move_order_line_id;
6311
6312 ELSE
6313 error_code := 'CARTONIZE 190';
6314 wms_container_pub.Container_Required_Qty
6315 ( p_api_version => 1.0,
6316 x_return_status => v_return_status,
6317 x_msg_count => l_msg_count,
6318 x_msg_data => l_msg_data,
6319 p_source_item_id => v1.inventory_item_id,
6320 p_source_qty => v1.primary_quantity,
6321 p_source_qty_uom => v_primary_uom_code,
6322 p_organization_id => v1.organization_id,
6323 p_dest_cont_item_id => v_container_item_id,
6324 p_qty_required => v_qty
6325 );
6326
6327 IF (g_trace_on = 1) THEN
6328 log_event('container_required_quantity return status'||v_return_status);
6329 log_event('container '||v_container_item_id);
6330 log_event('Number of conatiners '||v_qty);
6331 END IF;
6332
6333 v_prev_item_id := v1.inventory_item_id;
6334
6335 IF( (v_return_status = fnd_api.g_ret_sts_success ) AND
6336 (v_qty IS NOT NULL) AND
6337 (v_qty > 0) AND
6338 (v_container_item_id IS NOT NULL) AND
6339 (v_container_item_id > 0) ) THEN
6340
6341 error_code := 'CARTONIZE 200';
6342
6343 SELECT max_load_quantity
6344 INTO v_qty_per_cont
6345 FROM wsh_container_items
6346 WHERE load_item_id = v1.inventory_item_id
6347 AND master_organization_id = v1.organization_id
6348 AND container_item_id = v_container_item_id;
6349
6350 END IF;
6351
6352 END IF;
6353
6354 IF (g_trace_on = 1) THEN
6355 log_event('qty per container is '||v_qty_per_cont);
6356 END IF;
6357 --#chk1
6358
6359 IF( (v_return_status <> fnd_api.g_ret_sts_success ) OR
6360 (v_qty_per_cont IS NULL) OR
6361 (v_qty IS NULL) OR
6362 (v_container_item_id IS NULL) OR
6363 (v_qty <= 0) OR
6364 (v_container_item_id <= 0) OR
6365 (v_qty_per_cont <= 0) OR
6366 --Bug 2478970 fix
6367 l_valid_container = 'N'
6368 ) THEN
6369
6370 IF (g_trace_on = 1) THEN
6371 log_event('improper values returned by container_required_qty ');
6372 END IF;
6373 ELSE
6374 v_serial_control_code := inv_cache.item_rec.serial_number_control_code;
6375
6376 IF( (v_serial_control_code NOT IN (1,6) )
6377 AND (Ceil(v_qty_per_cont) > v_qty_per_cont )) THEN
6378 IF (g_trace_on = 1) THEN
6379 log_event('cannot split serial controlled items to fractions');
6380 log_event('Please check the container item relationships');
6381 END IF;
6382
6383 v_qty_per_cont := 0;
6384 v_serial_control_code := NULL;
6385 END IF;
6386
6387 v_serial_control_code := NULL;
6388
6389 v_tr_qty_per_cont := ROUND((v_qty_per_cont * inv_convert.inv_um_convert(
6390 p_item_id => v1.inventory_item_id,
6391 p_from_uom_code => v_primary_uom_code,
6392 p_to_uom_code => v1.transaction_uom
6393 )),
6394 5);
6395
6396 --invconv kkillams
6397 IF v1.secondary_uom_code IS NOT NULL THEN
6398
6399 v_sec_tr_qty_per_cont := ROUND((v_qty_per_cont * inv_convert.inv_um_convert(
6400 p_item_id => v1.inventory_item_id,
6401 p_from_uom_code => v_primary_uom_code,
6402 p_to_uom_code => v1.secondary_uom_code
6403 )),
6404 5);
6405
6406 END IF;
6407
6408 if (g_trace_on = 1) then log_event(' Transaction qty per conatiner is '||v_tr_qty_per_cont); END IF;
6409 if (g_trace_on = 1) then log_event(' Secondary Transaction qty per conatiner is '||v_sec_tr_qty_per_cont); END IF;
6410 END IF;
6414 IF (v1.primary_quantity <= space_avail_for) THEN
6411 ELSE
6412 IF (space_avail_for > 0) THEN
6413 if (g_trace_on = 1) then log_event(' Space available for '||space_avail_for); END IF;
6415 if (g_trace_on = 1) then log_event(' Prim qty '||v1.primary_quantity|| ' <= '||space_avail_for); END IF;
6416 space_avail_for := space_avail_for - v1.primary_quantity;
6417
6418 IF( v1.content_lpn_id IS NULL) THEN
6419 l_upd_qty_flag := 'Y';
6420 ELSE
6421 l_upd_qty_flag := 'N';
6422 END IF;
6423 update_mmtt
6424 (p_transaction_temp_id => v1.transaction_temp_id,
6425 p_primary_quantity => v1.primary_quantity,
6426 p_transaction_quantity => v1.transaction_quantity,
6427 p_secondary_quantity => v1.secondary_transaction_quantity, --invconv kkillams
6428 --p_LPN_string => v_lpn_out,
6429 p_lpn_id => v_lpn_id,
6430 p_container_item_id => v_container_item_id,
6431 p_parent_line_id => NULL,
6432 p_upd_qty_flag => l_upd_qty_flag,
6433 x_return_status => l_return_status,
6434 x_msg_count => x_msg_count,
6435 x_msg_data => x_msg_data
6436 );
6437
6438 v1.primary_quantity := 0;
6439 ELSE
6440 if (g_trace_on = 1) then log_event(' Prim qty '||v1.primary_quantity|| ' > '||space_avail_for); END IF;
6441
6442 tr_space_avail_for := ROUND((space_avail_for * inv_convert.inv_um_convert(
6443 p_item_id => v1.inventory_item_id,
6444 p_from_uom_code => v_primary_uom_code,
6445 p_to_uom_code => v1.transaction_uom
6446 )),
6447 5);
6448
6449 sec_tr_space_avail_for := NULL;
6450
6451 IF v1.secondary_uom_code IS NOT NULL THEN
6452
6453 sec_tr_space_avail_for := ROUND((space_avail_for * inv_convert.inv_um_convert(
6454 p_item_id => v1.inventory_item_id,
6455 p_from_uom_code => v_primary_uom_code,
6456 p_to_uom_code => v1.secondary_uom_code
6457 )),
6458 5);
6459
6460 END IF;
6461 if (g_trace_on = 1) then log_event(' Tr space avail for '||tr_space_avail_for); END IF;
6462
6463 insert_mmtt
6464 (p_transaction_temp_id => v1.transaction_temp_id,
6465 p_primary_quantity => space_avail_for,
6466 p_transaction_quantity => tr_space_avail_for,
6467 p_secondary_quantity => sec_tr_space_avail_for, --invconv kkillams
6468 --p_LPN_string => v_lpn_out,
6469 p_lpn_id => v_lpn_id,
6470 p_container_item_id => v_container_item_id,
6471 x_return_status => l_return_status,
6472 x_msg_count => x_msg_count,
6473 x_msg_data => x_msg_data
6474 );
6475
6476 v1.primary_quantity := v1.primary_quantity - space_avail_for;
6477
6478 v1.transaction_quantity := ROUND((v1.primary_quantity * inv_convert.inv_um_convert(
6479 p_item_id => v1.inventory_item_id,
6480 p_from_uom_code => v_primary_uom_code,
6481 p_to_uom_code => v1.transaction_uom
6482 )),
6483 5);
6484
6485 IF v1.secondary_uom_code IS NOT NULL THEN
6486
6487 v1.secondary_transaction_quantity := ROUND((v1.primary_quantity * inv_convert.inv_um_convert(
6488 p_item_id => v1.inventory_item_id,
6489 p_from_uom_code => v_primary_uom_code,
6490 p_to_uom_code => v1.secondary_uom_code
6491 )),
6492 5);
6493
6494 END IF;
6495
6496 space_avail_for := 0;
6497
6498 IF (g_trace_on = 1) THEN
6499 log_event('Prim qty '||v1.primary_quantity);
6500 log_event('Tr qty '||v1.transaction_quantity);
6504 END IF;
6501 log_event('Sec Tr qty '||v1.secondary_transaction_quantity); --invconv kkillams
6502 log_event('Space Avail for '||space_avail_for);
6503 END IF;
6505 END IF;
6506 END IF;
6507
6508 -- Condition #
6509 IF (v_return_status <> FND_API.g_ret_sts_success OR
6510 v_qty_per_cont IS NULL OR
6511 v_qty_per_cont <= 0 OR
6512 v_container_item_id IS NULL OR
6513 v_tr_qty_per_cont IS NULL OR
6514 v_tr_qty_per_cont <= 0 OR
6515 v1.primary_quantity <= 0 ) THEN
6516
6517 if (g_trace_on = 1) then log_event(' Container_Required_Qty - inc values'); END IF;
6518 -- Condition #3a
6519 NULL;
6520 ELSE
6521 -- Condition #3b
6522 IF( v1.content_lpn_id IS NULL) THEN
6523 l_upd_qty_flag := 'Y';
6524 ELSE
6525 l_upd_qty_flag := 'N';
6526 END IF;
6527
6528 v_qty := ceil( v1.primary_quantity/v_qty_per_cont);
6529
6530 IF( MOD(v1.primary_quantity,v_qty_per_cont) = 0 ) THEN
6531 space_avail_for := 0;
6532 ELSE
6533 space_avail_for := v_qty_per_cont - MOD(v1.primary_quantity,v_qty_per_cont);
6534 END IF;
6535
6536 IF (g_trace_on = 1) THEN log_event('space avail for '||space_avail_for); END IF;
6537 /* Condition #4 */
6538 IF( (v1.primary_quantity <= v_qty_per_cont) OR ( v_qty = 1) ) THEN
6539 IF (g_trace_on = 1) THEN log_event(' primary_quantity <= qty per conatiner or'||' NUMBER OF cont = 1'); END IF;
6540 v_lpn_id := get_next_package_id;
6541 IF (g_trace_on = 1) THEN
6542 log_event(' Generated label Id '||v_lpn_id);
6543 END IF;
6544
6545 update_mmtt
6546 ( p_transaction_temp_id => v1.transaction_temp_id,
6547 p_primary_quantity => v1.primary_quantity,
6548 p_transaction_quantity => v1.transaction_quantity,
6549 p_secondary_quantity => v1.secondary_transaction_quantity, --invconv kkillams
6550 --p_LPN_string => v_lpn_out,
6551 p_lpn_id => v_lpn_id,
6552 p_container_item_id => v_container_item_id,
6553 p_parent_line_id => NULL,
6554 p_upd_qty_flag => l_upd_qty_flag ,
6555 x_return_status => l_return_status,
6556 x_msg_count => x_msg_count,
6557 x_msg_data => x_msg_data );
6558 ELSE
6559 /* Condition #4b */
6560
6561 v_loop := v_qty;
6562 IF (g_trace_on = 1) THEN log_event(' NUMBER OF cont:'||v_qty); END IF;
6563 --Bug2422193 fix moved this update to above as package
6564 --ids need TO be generated IN the ORDER IN which rows
6565 --are considered for cartonization
6566 v_lpn_id := get_next_package_id;
6567 IF (g_trace_on = 1) THEN
6568 log_event('Generated label Id '||v_lpn_id);
6569 log_event('calling update_mmtt');
6570 END IF;
6571
6572 update_mmtt
6573 ( p_transaction_temp_id => v1.transaction_temp_id,
6574 p_primary_quantity => v_qty_per_cont,
6575 p_transaction_quantity => v_tr_qty_per_cont,
6576 p_secondary_quantity => v_sec_tr_qty_per_cont, --invconv kkillams
6577 --p_LPN_string => v_lpn_out,
6578 p_lpn_id => v_lpn_id,
6579 p_container_item_id => v_container_item_id,
6580 p_parent_line_id => NULL,
6581 p_upd_qty_flag => l_upd_qty_flag,
6582 x_return_status => l_return_status,
6583 x_msg_count => x_msg_count,
6584 x_msg_data => x_msg_data );
6585
6586 v_loop := v_loop - 1;
6587
6588 -- Bug 2422193 fix
6589
6590 LOOP
6591 EXIT WHEN v_loop < 2;
6592 v_lpn_id := get_next_package_id;
6593 IF (g_trace_on = 1) THEN
6594 log_event(' Generated label Id '||v_lpn_id);
6595 log_event(' calling insert mmtt');
6596 END IF;
6597 insert_mmtt
6598 ( p_transaction_temp_id => v1.transaction_temp_id,
6599 p_primary_quantity => v_qty_per_cont,
6600 p_transaction_quantity => v_tr_qty_per_cont,
6601 p_secondary_quantity => v_sec_tr_qty_per_cont, --invconv kkillams
6605 x_return_status => l_return_status,
6602 --p_LPN_string => v_lpn_out,
6603 p_lpn_id => v_lpn_id,
6604 p_container_item_id => v_container_item_id,
6606 x_msg_count => x_msg_count,
6607 x_msg_data => x_msg_data );
6608
6609 IF (g_trace_on = 1) THEN
6610 log_event(' called insert mmtt');
6611 END IF;
6612 v_loop := v_loop - 1;
6613 END LOOP;
6614
6615 v_lpn_id := get_next_package_id;
6616 IF (g_trace_on = 1) THEN
6617 log_event(' Generated label Id '||v_lpn_id);
6618 END IF;
6619
6620 v_left_prim_quant := MOD(v1.primary_quantity,v_qty_per_cont);
6621 v_left_tr_quant := MOD(v1.transaction_quantity,v_tr_qty_per_cont);
6622
6623 IF v1.secondary_uom_code IS NOT NULL THEN --invconv kkillams
6624 v_sec_left_tr_quant := MOD(v1.secondary_transaction_quantity,v_sec_tr_qty_per_cont);
6625 END IF;
6626
6627 IF( v_left_prim_quant = 0 OR v_left_tr_quant =0) THEN
6628 v_left_prim_quant := v_qty_per_cont;
6629 v_left_tr_quant := v_tr_qty_per_cont;
6630 IF v1.secondary_uom_code IS NOT NULL THEN --invconv kkillams
6631 v_sec_left_tr_quant := v_sec_tr_qty_per_cont;
6632 END IF;
6633 END IF;
6634
6635 if (g_trace_on = 1) then log_event('calling insert mmtt'); END IF;
6636 insert_mmtt
6637 ( p_transaction_temp_id => v1.transaction_temp_id,
6638 p_primary_quantity => v_left_prim_quant,
6639 p_transaction_quantity => v_left_tr_quant,
6640 p_secondary_quantity => v_sec_left_tr_quant, --invconv kkillams
6641 --p_LPN_string => v_lpn_out,
6642 p_lpn_id => v_lpn_id,
6643 p_container_item_id => v_container_item_id,
6644 x_return_status => l_return_status,
6645 x_msg_count => x_msg_count,
6646 x_msg_data => x_msg_data
6647 );
6648
6649 NULL;
6650 -- Shipping API
6651 END IF;
6652 -- Close Condition #4
6653 END IF;
6654 -- Close Condition #3
6655 END IF;
6656 -- for v1.allocated_lpn_id is not null
6657 END LOOP;
6658
6659 IF wct_rows%isopen THEN
6660 CLOSE wct_rows;
6661 END IF;
6662
6663 IF wct_sub_rows%isopen THEN
6664 CLOSE wct_sub_rows;
6665 END IF;
6666
6667 IF (g_trace_on = 1) THEN
6668 log_event('out of the loops :)');
6669 END IF;
6670
6671 x_return_status := fnd_api.g_ret_sts_success;
6672 EXCEPTION
6673 WHEN OTHERS THEN
6674 log_event('SQLERRM : '|| SQLERRM);
6675 log_event('SQLCODE : '|| SQLCODE);
6676 END cartonize_single_item;
6677
6678 PROCEDURE rulebased_cartonization
6679 (
6680 x_return_status OUT NOCOPY VARCHAR2,
6681 x_msg_count OUT NOCOPY NUMBER,
6682 x_msg_data OUT NOCOPY VARCHAR2,
6683 p_out_bound IN VARCHAR2,
6684 p_org_id IN NUMBER,
6685 p_move_order_header_id IN NUMBER,
6686 p_input_for_bulk IN WMS_BULK_PICK.bulk_input_rec DEFAULT NULL
6687 )
6688 IS
6689 v_cartonization_value NUMBER;
6690 l_cartonize_sales_orders VARCHAR2(1) :=NULL;
6691 l_cartonize_manufacturing VARCHAR2(1) :=NULL;
6692 l_auto_pick_confirm_flag VARCHAR2(1) := 'N';
6693 l_return_status VARCHAR2(1) := 'E';
6694 l_msg_count NUMBER;
6695 l_move_order_type NUMBER;
6696 l_msg_data VARCHAR2(2000);
6697 wct_row WCT_ROW_TYPE;
6698 l_api_return_status VARCHAR2(1);
6699 l_count1 NUMBER;
6700 l_label_status VARCHAR2(500);
6701 l_header_id NUMBER;
6702 L_PREV_PACKAGE_ID number;
6703 L_PREV_HEADER_ID number;
6704 L_CURRENT_HEADER_ID number := p_move_order_header_id;
6705 l_qty NUMBER := NULL;
6706 l_tr_qty NUMBER := NULL;
6707 l_sec_tr_qty NUMBER := NULL;
6708 l_clpn_id NUMBER := NULL;
6709 l_citem_id NUMBER := NULL;
6710 l_package_id NUMBER := NULL;
6711 l_upd_qty_flag VARCHAR2(1) := NULL;
6712 L_no_pkgs_gen VARCHAR2(1);
6713 l_temp_id number;
6714 l_item_id number;
6715 l_packaging_return_status VARCHAR2(1);
6716
6717 TYPE rules_table_type IS TABLE OF wms_selection_criteria_txn%rowtype;
6718 rules_table rules_table_type;
6719
6720 CURSOR wct_rows IS
6721 SELECT wct.* FROM wms_cartonization_temp wct,
6722 mtl_txn_request_lines mtrl,
6726 wct.move_order_line_id =mtrl.line_id
6723 mtl_secondary_inventories sub,
6724 mtl_parameters mtlp
6725 WHERE
6727 AND mtrl.header_id = p_move_order_header_id
6728 AND wct.cartonization_id IS null
6729 AND mtlp.organization_id = wct.organization_id
6730 AND sub.organization_id = wct.organization_id
6731 AND wct.cartonization_id IS NULL
6732 AND wct.transfer_lpn_id IS NULL
6733 AND sub.secondary_inventory_name = wct.subinventory_code
6734 AND( (Nvl(mtlp.cartonization_flag,-1) = 1) OR
6735 (Nvl(mtlp.cartonization_flag,-1) = 3
6736 AND sub.cartonization_flag = 1))
6737 ORDER BY wct.move_order_line_id,
6738 wct.subinventory_code,
6739 wct.inventory_item_id, Abs(wct.transaction_temp_id);
6740
6741 CURSOR OB_LBPRT IS
6742 SELECT DISTINCT mmtt.cartonization_id FROM
6743 --2513907 fix
6744 wms_cartonization_temp mmtt,
6745 --mtl_material_transactions_temp mmtt,
6746 mtl_txn_request_lines mtrl WHERE
6747 mmtt.move_order_line_id = mtrl.line_id
6748 AND mtrl.header_id = p_move_order_header_id
6749 AND mmtt.cartonization_id IS NOT NULL
6750 ORDER BY mmtt.cartonization_id;
6751
6752
6753 CURSOR packages(p_hdr_id NUMBER) IS
6754 SELECT
6755 transaction_temp_id,
6756 inventory_item_id,
6757 primary_quantity,
6758 transaction_quantity,
6759 secondary_transaction_quantity, --invconv kkillams
6760 content_lpn_id,
6761 container_item_id,
6762 cartonization_id
6763 FROM
6764 wms_cartonization_temp
6765 WHERE
6766 transaction_header_id = p_hdr_id
6767 order by cartonization_id;
6768
6769 CURSOR opackages(p_hdr_id NUMBER) IS
6770 SELECT
6771 wct.transaction_temp_id,
6772 wct.inventory_item_id,
6773 wct.primary_quantity,
6774 wct.transaction_quantity,
6775 wct.secondary_transaction_quantity, --invconv kkillams
6776 wct.content_lpn_id,
6777 wct.container_item_id,
6778 wct.cartonization_id
6779 FROM
6780 wms_cartonization_temp wct,
6781 mtl_txn_request_lines mtrl
6782 WHERE
6783 wct.move_order_line_id = mtrl.line_id AND
6784 mtrl.header_id = p_hdr_id
6785 order by wct.cartonization_id;
6786
6787 l_count number;
6788 l_counter number := 1;
6789 l_return_type_id number;
6790
6791 BEGIN
6792
6793 IF (g_trace_on = 1) THEN
6794 log_event('In RULEBASED_CARTONIZATION()');
6795 log_event('Populating wms_cartonization_temp from MMTT rows');
6796 END IF;
6797 g_cartonize_pick_slip := 'N';
6798
6799 IF (g_trace_on = 1) THEN
6800 log_event('Auto Pick Confirm Flag is : '|| WMS_CARTNZN_PUB.g_auto_pick_confirm_flag);
6801 END IF;
6802
6803 IF WMS_CARTNZN_PUB.g_auto_pick_confirm_flag = 'N' THEN
6804
6805 IF (g_trace_on = 1) THEN
6806 log_event(' move order header id '||p_move_order_header_id);
6807 END IF;
6808
6809 IF (g_trace_on = 1) THEN
6810 log_event('Calling wms_rule_pvt.assigntts for task type assignment');
6811 END IF;
6812
6813 wms_rule_pvt.assigntts(
6814 p_api_version => 1.0
6815 , p_move_order_header_id => p_move_order_header_id
6816 , x_return_status => l_return_status
6817 , x_msg_count => l_msg_count
6818 , x_msg_data => l_msg_data
6819 );
6820
6821 IF (g_trace_on = 1) THEN
6822 log_event(' Task type assignment returned with status :' ||l_return_status);
6823 END IF;
6824
6825 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6826 log_event(' Task type assignment failed');
6827 END IF;
6828
6829 l_return_status := fnd_api.g_ret_sts_success;
6830
6831 IF (p_move_order_header_id <> -1 ) THEN
6832
6833 log_event('Calling wms_rule_pvt.assign_operation_plan for Operation Plan assignment' );
6834
6835 wms_rule_pvt.assign_operation_plans(
6836 p_api_version => 1.0
6837 , p_move_order_header_id => p_move_order_header_id
6838 , x_return_status => l_return_status
6839 , x_msg_count => l_msg_count
6840 , x_msg_data => l_msg_data);
6841
6842 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6843 error_code := 'CARTONIZE 45';
6844 -- insert the message into the stack
6845 log_event(' Operation plan assignment failed');
6846 ELSE
6847 log_event(' Operation plan assignment returned success');
6848 END IF;
6849 END IF;
6850
6851 IF (g_trace_on = 1) THEN
6852 log_event('Calling INV_PICK_RELEASE_PUB.assign_pick_slip_number ');
6853 END IF;
6854
6855 INV_PICK_RELEASE_PUB.assign_pick_slip_number(
6859 , p_move_order_header_id => p_move_order_header_id
6856 x_return_status => l_return_status
6857 , x_msg_count => x_msg_count
6858 , x_msg_data => x_msg_data
6860 , p_ps_mode => null
6861 , p_grouping_rule_id => null
6862 , p_allow_partial_pick => null
6863 );
6864 IF (g_trace_on = 1) THEN
6865 log_event('assign_pick_slip_number returns'||l_return_status);
6866 END IF;
6867
6868 END IF; -- l_auto_pick_confirm_flag = 'N'
6869
6870 IF (g_trace_on = 1) THEN
6871 log_event('Populating wms_cartonization_temp from MMTT rows');
6872 END IF;
6873
6874 create_wct(
6875 p_move_order_header_id => p_move_order_header_id
6876 , p_transaction_header_id => NULL
6877 , p_input_for_bulk =>p_input_for_bulk
6878 );
6879
6880 IF (g_trace_on = 1) THEN
6881 SELECT count(*)
6882 INTO l_count
6883 FROM wms_cartonization_temp;
6884 log_event('NUMBER OF ROWS INSERTED IN WCT : '|| l_count);
6885 END IF;
6886
6887 IF (g_trace_on = 1) THEN
6888 log_event('Goint to cartonize');
6889 END IF;
6890
6891 SELECT * BULK COLLECT
6892 INTO rules_table
6893 FROM wms_selection_criteria_txn
6894 WHERE rule_type_code = 12
6895 AND from_organization_id = p_org_id -- Bug : 6962305
6896 AND enabled_flag = 1
6897 ORDER BY sequence_number;
6898
6899 FOR i in rules_table.FIRST .. rules_table.LAST LOOP
6900
6901 IF rules_table(i).return_type_id = 1 THEN
6902
6903 cartonize_single_item
6904 (
6905 x_return_status => l_api_return_status,
6906 x_msg_count => x_msg_count,
6907 x_msg_data => x_msg_data,
6908 p_out_bound => 'Y',
6909 p_org_id => rules_table(i).from_organization_id,
6910 p_move_order_header_id => p_move_order_header_id,
6911 p_subinventory_name => rules_table(i).from_subinventory_name
6912 );
6913
6914 ELSIF rules_table(i).return_type_id = 2 THEN
6915
6916 cartonize_mixed_item
6917 (
6918 x_return_status => l_api_return_status,
6919 x_msg_count => x_msg_count,
6920 x_msg_data => x_msg_data,
6921 p_out_bound => 'Y',
6922 p_org_id => rules_table(i).from_organization_id,
6923 p_move_order_header_id => p_move_order_header_id,
6924 p_transaction_header_id => NULL,
6925 p_subinventory_name => rules_table(i).from_subinventory_name,
6926 p_pack_level => 0,
6927 p_stop_level => 0
6928 );
6929
6930 pack_level := 0;
6931
6932 ELSIF rules_table(i).return_type_id = 3 THEN
6933
6934 g_cartonize_pick_slip := 'Y';
6935 cartonize_pick_slip
6936 (
6937 p_org_id => rules_table(i).from_organization_id,
6938 p_move_order_header_id => p_move_order_header_id,
6939 p_subinventory_name => rules_table(i).from_subinventory_name,
6940 x_return_status => l_return_status
6941 );
6942
6943 ELSIF rules_table(i).return_type_id = 4 THEN
6944
6945 cartonize_customer_logic
6946 (
6947 p_org_id => rules_table(i).from_organization_id,
6948 p_move_order_header_id => p_move_order_header_id,
6949 p_subinventory_name => rules_table(i).from_subinventory_name,
6950 x_return_status => l_return_status
6951 );
6952
6953 END IF;
6954
6955 -- Do not consider WCT rows used for multi-level packaging history
6956 SELECT count(1)
6957 INTO l_count
6958 FROM wms_cartonization_temp
6959 WHERE cartonization_id IS NULL
6960 AND transaction_header_id >= 0;
6961
6962 IF l_count = 0 THEN
6963 EXIT;
6964 END IF;
6965
6966 END LOOP;
6967
6968 -- If there are any more rows left for cartonization for first level, cartonize through default logic
6969 IF l_count > 0 THEN
6970
6971 cartonize_default_logic
6972 (
6973 p_org_id => p_org_id,
6974 p_move_order_header_id => p_move_order_header_id,
6975 p_out_bound => 'Y',
6976 x_return_status => x_return_status,
6977 x_msg_count => x_msg_count,
6978 x_msg_data => x_msg_data
6979 );
6980
6981 END IF;
6982
6983 IF (g_trace_on = 1) THEN
6987 pack_level := 0;
6984 log_event('Done with FIRST LEVEL OF CARTONIZATION, inserting packaging history');
6985 END IF;
6986
6988
6989 insert_ph
6990 (
6991 p_move_order_header_id => p_move_order_header_id,
6992 p_current_header_id => p_move_order_header_id,
6993 x_return_status => l_packaging_return_status
6994 );
6995
6996 IF (g_trace_on = 1) THEN
6997 log_event('After Insert_Ph');
6998 END IF;
6999
7000 IF (g_trace_on = 1) THEN
7001 log_event('Done with FIRST LEVEL OF CARTONIZATION');
7002 log_event('Calling CARTONIZE_MIXED_ITEM for doing MULTI-LEVEL CARTONIZATION');
7003 END IF;
7004
7005 cartonize_mixed_item
7006 (
7007 x_return_status => l_api_return_status,
7008 x_msg_count => x_msg_count,
7009 x_msg_data => x_msg_data,
7010 p_out_bound => 'Y',
7011 p_org_id => p_org_id,
7012 p_move_order_header_id => p_move_order_header_id,
7013 p_transaction_header_id => NULL,
7014 p_pack_level => 1
7015 );
7016
7017 l_header_id := p_move_order_header_id;
7018
7019 IF (g_trace_on = 1) THEN
7020 log_event('Calling Generate_LPNs for header id ** '||l_header_id);
7021 END IF;
7022
7023 BEGIN
7024 generate_lpns(p_header_id => l_header_id,
7025 p_organization_id => p_org_id);
7026 EXCEPTION
7027 WHEN OTHERS THEN
7028 IF (g_trace_on = 1) THEN
7029 log_event('not erroring out since the mode is Pick release ');
7030 END IF;
7031 RAISE fnd_api.g_exc_error;
7032 END;
7033
7034 DELETE wms_cartonization_temp
7035 WHERE transaction_header_id < 0;
7036
7037 log_event('Out of cartonization logic going to print labels');
7038
7039 IF( outbound = 'Y') THEN
7040 OPEN OB_LBPRT;
7041 LOOP
7042 FETCH OB_LBPRT INTO lpns_generated_tb(l_counter);
7043 EXIT WHEN OB_LBPRT%notfound;
7044
7045 IF (g_trace_on = 1) THEN
7046 log_event(' print label for lpn '|| lpns_generated_tb(l_counter));
7047 END IF;
7048 l_counter := l_counter + 1;
7049 END LOOP;
7050 IF OB_LBPRT%ISOPEN THEN
7051 CLOSE OB_LBPRT;
7052 END IF;
7053 END IF;
7054
7055 IF (g_trace_on = 1) THEN
7056 log_event('lpns_generated_tb.count : '|| lpns_generated_tb.count);
7057 END IF;
7058
7059 IF (g_trace_on = 1) THEN log_event('Auto pick confirm flag : '|| l_auto_pick_confirm_flag); END IF;
7060
7061 IF l_auto_pick_confirm_flag = 'Y' THEN
7062 if (g_trace_on = 1) then log_event('Auto pick confirm is ON - Not calling task consolidation - splitting'); END IF;
7063 ELSE
7064
7065 IF (g_trace_on = 1) then -- log_event('PATCHSET J-- BULK PICKING --START');
7066 log_event('Calling consolidate_bulk_tasks_for_so....');
7067 log_event('move order header id '||p_move_order_header_id);
7068 END IF;
7069
7070 wms_task_dispatch_engine.consolidate_bulk_tasks_for_so
7071 (p_api_version => 1.0,
7072 x_return_status => l_return_status,
7073 x_msg_count => x_msg_count,
7074 x_msg_data => x_msg_data,
7075 p_move_order_header_id => p_move_order_header_id);
7076
7077 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
7078 -- we don't want to exit if there is any error here, for example data error or something
7079 IF (g_trace_on = 1) THEN log_event(' consolidate_bulk_tasks_for_so returns '||l_return_status); END IF;
7080 END IF;
7081 IF (g_trace_on = 1) THEN log_event(' calling ins_wct_rows_into_mmtt after consolidation'); END IF;
7082
7083 ins_wct_rows_into_mmtt( p_m_o_h_id => p_move_order_header_id,
7084 p_outbound => 'Y',
7085 x_return_status => l_return_status,
7086 x_msg_count => x_msg_count,
7087 x_msg_data => x_msg_data);
7088
7089 -- since the return value is not set up inside above procedure, so no need to check it
7090 -- but above procedure will throw unexpected error in case of errors, so this API will capture the
7091 -- error.
7092
7093 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
7094 --Push the message into the stack
7095 IF (g_trace_on = 1) THEN log_event(' consolidate_bulk_tasks returns '||l_return_status); END IF;
7096 END IF;
7097
7098 IF (g_trace_on = 1) THEN log_event(' calling task splitting' ); END IF;
7099
7100 wms_task_dispatch_engine.split_tasks
7101 (
7102 p_api_version => 1.0,
7103 x_return_status => l_return_status,
7104 x_msg_count => x_msg_count,
7105 x_msg_data => x_msg_data,
7106 p_move_order_header_id => p_move_order_header_id
7107 );
7108
7109 IF(l_return_status <> fnd_api.g_ret_sts_success ) THEN
7110 --Push the message into the stack
7114
7111 IF (g_trace_on = 1) THEN log_event(' split_tasks returns '||l_return_status); END IF;
7112 END IF;
7113 END IF;
7115 --Bug 6873966
7116 --moved the label printing call after stamping the cartonization_id on the mmtt
7117 IF (lpns_generated_tb.COUNT > 0) THEN
7118
7119 IF packaging_mode = wms_cartnzn_pub.PR_pKG_mode THEN
7120 IF (g_trace_on = 1) THEN
7121 log_event('wms_cartnzn_pub before inv_label.print_label ');
7122 END IF;
7123 l_return_status := fnd_api.g_ret_sts_success;
7124
7125 inv_label.print_label
7126 (
7127 x_return_status => l_return_status
7128 , x_msg_count => l_msg_count
7129 , x_msg_data => l_msg_data
7130 , x_label_status => l_label_status
7131 , p_api_version => 1.0
7132 , p_print_mode => 1
7133 , p_business_flow_code => 22
7134 , p_transaction_id => lpns_generated_tb
7135 );
7136
7137 IF (g_trace_on = 1) THEN
7138 log_event('wms_cartnzn_pub after inv_label.print_label ');
7139 END IF;
7140
7141 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7142 FND_MESSAGE.SET_NAME('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL'); -- MSGTBD
7143 FND_MSG_PUB.ADD;
7144 IF (g_trace_on = 1) THEN
7145 log_event('wms_cartnzn_pub inv_label.print_label FAILED;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'));
7146 END IF;
7147 END IF;
7148 END IF; -- end packaging_mode in 1
7149 ELSE
7150 IF (g_trace_on = 1) THEN
7151 log_event('COULD NOT CARTONIZE ANY OF THE LINES');
7152 END IF;
7153 END IF;
7154
7155 EXCEPTION
7156 WHEN OTHERS THEN
7157 log_event('Exception in rulebased cartonization');
7158 log_event('SQL Error Message :' || SQLERRM);
7159 log_event('SQL Error Code :' || SQLCODE);
7160 -- v_cart_value := NULL;
7161 END rulebased_cartonization;
7162
7163 PROCEDURE cartonize_mixed_item (
7164 x_return_status OUT NOCOPY VARCHAR2,
7165 x_msg_count OUT NOCOPY NUMBER,
7166 x_msg_data OUT NOCOPY VARCHAR2,
7167 p_out_bound IN VARCHAR2,
7168 p_org_id IN NUMBER,
7169 p_move_order_header_id IN NUMBER,
7170 p_transaction_header_id IN NUMBER,
7171 p_disable_cartonization IN VARCHAR2 DEFAULT 'N',
7172 p_subinventory_name IN VARCHAR2 DEFAULT NULL,
7173 p_stop_level IN NUMBER DEFAULT NULL,
7174 p_pack_level IN NUMBER
7175 )
7176 IS
7177 l_api_name CONSTANT VARCHAR2(30) := 'cartonize_mixed_item';
7178 l_api_version CONSTANT NUMBER := 1.0;
7179 v1 WCT_ROW_TYPE;
7180 cartonization_profile VARCHAR2(1) := 'Y';
7181 v_cart_value NUMBER;
7182 v_container_item_id NUMBER:= NULL;
7183 v_qty NUMBER:= -1;
7184 v_qty_per_cont NUMBER := -1;
7185 v_tr_qty_per_cont NUMBER:= -1;
7186 v_sec_tr_qty_per_cont NUMBER:= -1;
7187 v_lpn_out VARCHAR2(30) := ' ';
7188 v_primary_uom_code VARCHAR2(3);
7189 v_loop NUMBER := 0;
7190 v_process_id NUMBER := 0;
7191 v_ttemp_id NUMBER := 0;
7192 v_lpn_id_out NUMBER := 0;
7193 v_lpn_id NUMBER := 0;
7194 ret_value NUMBER := 29;
7195 v_return_status VARCHAR2(1);
7196 v_left_prim_quant NUMBER;
7197 v_left_tr_quant NUMBER;
7198 v_sec_left_tr_quant NUMBER;
7199 v_sublvlctrl VARCHAR2(1) := g_sublvlctrl; --Bug#7168367.Get form global variable.
7200 l_header_id NUMBER := NULL;
7201 --Bug 2720653 fix
7202 --l_lpn_id_tbl inv_label.transaction_id_rec_type;
7203 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
7204 l_msg_count NUMBER;
7205 l_msg_data VARCHAR2(400);
7206 l_progress VARCHAR2(10);
7207 l_label_status VARCHAR2(500);
7208 l_counter NUMBER := 0;
7209 v_prev_move_order_line_id NUMBER := 0;
7210 space_avail_for NUMBER := 0;
7211 tr_space_avail_for NUMBER := 0;
7212 sec_tr_space_avail_for NUMBER := 0; --invconv kkillams
7213 curr_temp_id mtl_material_transactions_temp.transaction_temp_id%TYPE ;
7214 v_lot_control_code NUMBER := NULL;
7215 v_serial_control_code NUMBER := NULL;
7216 api_table_index NUMBER := 0;
7217 l_current_header_id NUMBER := NULL;
7218 l_stop_level NUMBER := -1;
7219 v_prev_item_id NUMBER := NULL;
7220 l_prev_package_id NUMBER := NULL;
7221 l_temp_id NUMBER := NULL;
7222 l_item_id NUMBER := NULL;
7223
7224 l_qty NUMBER := NULL;
7225 l_tr_qty NUMBER := NULL;
7226 l_sec_tr_qty NUMBER := NULL;
7227 l_clpn_id NUMBER := NULL;
7228 l_citem_id NUMBER := NULL;
7229 l_package_id NUMBER := NULL;
7230 l_upd_qty_flag VARCHAR2(1) := NULL;
7231 l_prev_header_id NUMBER := NULL;
7232 L_no_pkgs_gen VARCHAR2(1);
7236 l_serial_code VARCHAR2(1);
7233 l_prev_condition VARCHAR2(1);
7234 l_revision_code VARCHAR2(1);
7235 l_lot_code VARCHAR2(1);
7237 l_is_revision_control BOOLEAN;
7238 l_is_lot_control BOOLEAN;
7239 l_is_serial_control BOOLEAN;
7240 l_rqoh NUMBER;
7241 l_qr NUMBER;
7242 l_qs NUMBER;
7243 l_atr NUMBER;
7244 l_att NUMBER;
7245 l_qoh NUMBER;
7246 l_lpn_fully_allocated VARCHAR2(1) :='N';
7247 percent_fill_basis VARCHAR2(1) :='W';
7248 l_valid_container VARCHAR2(1) := 'Y';
7249
7250 l_cartonize_sales_orders VARCHAR2(1) :=NULL;
7251 l_cartonize_manufacturing VARCHAR2(1) :=NULL;
7252 l_move_order_type NUMBER;
7253 l_pack_level NUMBER := 0;
7254
7255 CURSOR wct_rows IS
7256 SELECT wct.* FROM wms_cartonization_temp wct,
7257 mtl_txn_request_lines mtrl,
7258 mtl_secondary_inventories sub,
7259 mtl_parameters mtlp
7260 WHERE
7261 wct.move_order_line_id =mtrl.line_id
7262 AND mtrl.header_id = p_move_order_header_id
7263 AND wct.cartonization_id IS null
7264 AND mtlp.organization_id = wct.organization_id
7265 AND sub.organization_id = wct.organization_id
7266 AND wct.cartonization_id IS NULL
7267 AND wct.transfer_lpn_id IS NULL
7268 AND sub.secondary_inventory_name = wct.subinventory_code
7269 AND wct.subinventory_code = NVL(p_subinventory_name,wct.subinventory_code)
7270 AND((Nvl(mtlp.cartonization_flag,-1) = 1) OR
7271 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
7272 ORDER BY wct.move_order_line_id,
7273 wct.inventory_item_id,
7274 Abs(wct.transaction_temp_id);
7275
7276 CURSOR OB_LBPRT IS
7277 SELECT DISTINCT mmtt.cartonization_id FROM
7278 --2513907 fix
7279 wms_cartonization_temp mmtt,
7280 --mtl_material_transactions_temp mmtt,
7281 mtl_txn_request_lines mtrl WHERE
7282 mmtt.move_order_line_id = mtrl.line_id
7283 AND mtrl.header_id = p_move_order_header_id
7284 AND mmtt.cartonization_id IS NOT NULL
7285 ORDER BY mmtt.cartonization_id;
7286
7287 CURSOR bpack_rows(p_hdr_id NUMBER) IS
7288 SELECT * FROM
7289 wms_cartonization_temp
7290 WHERE
7291 transaction_header_id = p_hdr_id
7292 AND cartonization_id IS NULL
7293 AND transfer_lpn_id IS NULL
7294 order by move_order_line_id,
7295 decode(content_lpn_id,null,inventory_item_id,
7296 decode(sign(p_hdr_id),
7297 -1,
7298 inventory_item_id,
7299 wms_cartnzn_pub.Get_LPN_ItemId(content_lpn_id)
7300 ) ),Abs(transaction_temp_id);
7301
7302
7303 CURSOR packages(p_hdr_id NUMBER) IS
7304 SELECT
7305 transaction_temp_id,
7306 inventory_item_id,
7307 primary_quantity,
7308 transaction_quantity,
7309 secondary_transaction_quantity, --invconv kkillams
7310 content_lpn_id,
7311 container_item_id,
7312 cartonization_id
7313 FROM
7314 wms_cartonization_temp
7315 WHERE
7316 transaction_header_id = p_hdr_id
7317 order by cartonization_id;
7318
7319 CURSOR opackages(p_hdr_id NUMBER) IS
7320 SELECT
7321 wct.transaction_temp_id,
7322 wct.inventory_item_id,
7323 wct.primary_quantity,
7324 wct.transaction_quantity,
7325 wct.secondary_transaction_quantity, --invconv kkillams
7326 wct.content_lpn_id,
7327 wct.container_item_id,
7328 wct.cartonization_id
7329 FROM
7330 wms_cartonization_temp wct,
7331 mtl_txn_request_lines mtrl
7332 WHERE
7333 wct.move_order_line_id = mtrl.line_id AND
7334 mtrl.header_id = p_hdr_id
7335 order by wct.cartonization_id;
7336
7337 l_cartonization_profile VARCHAR2(1) := 'Y';
7338 BEGIN
7339
7340 --setting the global variable for trace
7341 g_trace_on := fnd_profile.value('INV_DEBUG_TRACE');
7342 -- Setting the global variable for packaging
7343 -- packaging_mode := p_packaging_mode;
7344 -- Setting the global variable for sequence
7345 --sequence_id := 1;
7346
7347 -- l_current_header_id := p_move_order_header_id;
7348
7349 -- For subinventory restriction in Rules Workbench
7350
7351 IF (g_trace_on = 1) THEN log_event(' In CARTONIZE_MIXED_ITEM()'); END IF;
7352
7353 IF p_subinventory_name IS NOT NULL THEN
7354
7355 IF (g_trace_on = 1) THEN log_event(' Updating wct with dummy cartonization id for sub other than : ' || p_subinventory_name); END IF;
7356
7357 UPDATE wms_cartonization_temp
7358 SET cartonization_id = -99999
7359 , container_item_id = -99999
7360 WHERE subinventory_code <> p_subinventory_name
7364 END IF;
7361 AND organization_id = p_org_id
7362 AND cartonization_id IS NULL;
7363
7365
7366 IF p_pack_level = 0 THEN
7367 curr_header_id_for_mixed := p_move_order_header_id;
7368 END IF;
7369
7370 outbound := 'Y';
7371 cartonization_profile := 'Y';
7372
7373 IF( cartonization_profile = 'Y') THEN
7374
7375 pack_level := p_pack_level;
7376
7377 LOOP
7378
7379 IF (g_trace_on = 1) THEN log_event(' pack_level '||pack_level ||' l_stop_level'||l_stop_level); END IF;
7380
7381 EXIT WHEN ( (pack_level >= l_stop_level) AND (l_stop_level <> -1));
7382
7383 IF p_stop_level IS NOT NULL THEN
7384 l_stop_level := p_stop_level;
7385 IF (g_trace_on = 1) THEN
7386 log_event('This procedure called for FIRST LEVEL cartonization only');
7387 END IF;
7388 ELSE
7389 IF (g_trace_on = 1) THEN
7390 log_event('This procedure called for MULTI LEVEL cartonization');
7391 END IF;
7392 END IF;
7393
7394 v_prev_item_id := -1;
7395 v_prev_move_order_line_id := -1;
7396
7397 --bpack_rows should select only rows with transaction_header_id = l_current_header_id
7398 if (g_trace_on = 1) then log_event(' opening cusror hdr id'||l_current_header_id); END IF;
7399
7400
7401 IF( (outbound = 'Y') AND (pack_level = 0)) THEN
7402 error_code := 'CARTONIZE 70';
7403 if (g_trace_on = 1) then log_event('opening wct_rows'); END IF;
7404 OPEN wct_rows;
7405 if (g_trace_on = 1) then log_event('opened bpack rows'); END IF;
7406 ELSE
7407 error_code := 'CARTONIZE 90';
7408 if (g_trace_on = 1) then log_event('opening bpack_rows'); END IF;
7409 OPEN bpack_rows(l_current_header_id);
7410 if (g_trace_on = 1) then log_event(' Opened bpack rows'); END IF;
7411 END IF;
7412
7413 IF (g_trace_on = 1) THEN
7414 log_event(' l_stop_level '||l_stop_level);
7415 log_event(' l_current_level '||pack_level);
7416 log_event(' l_current_header_id '||l_current_header_id);
7417 END IF;
7418
7419 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
7420 ret_value:= do_cartonization(p_move_order_header_id,0,outbound,
7421 v_sublvlctrl,WMS_CARTNZN_PUB.g_percent_fill_basis);
7422
7423 ELSE
7424 IF (g_trace_on = 1) THEN
7425 log_event('in else for cartonization');
7426 log_event('passing header id '||l_current_header_id);
7427 log_event('passing outbound '||outbound);
7428 log_event('passing Sub level Control'||v_sublvlctrl);
7429 END IF;
7430 ret_value:= do_cartonization(0,curr_header_id_for_mixed,outbound,
7431 v_sublvlctrl,WMS_CARTNZN_PUB.g_percent_fill_basis);
7432
7433 END IF;
7434
7435 IF (g_trace_on = 1) THEN
7436 log_event(' cartonization returned'|| ret_value);
7437 log_event(' calling split_lot_serials ');
7438 END IF;
7439
7440 split_lot_serials(p_org_id);
7441
7442 IF (g_trace_on = 1) then log_event(' pack level'); END IF;
7443
7444 IF pack_level <> 0 THEN
7445
7446 IF (g_trace_on = 1) then log_event(' Populating Packaging History Table'); END IF;
7447
7448 l_prev_package_id := -1;
7449
7450 -- l_prev_header_id := l_current_header_id;
7451
7452 prev_header_id_for_mixed := curr_header_id_for_mixed;
7453
7454 l_prev_header_id := prev_header_id_for_mixed;
7455
7456 IF (g_trace_on = 1) then log_event(' prev header id '||l_prev_header_id ); END IF;
7457 -- l_current_header_id := get_next_header_id;
7458 curr_header_id_for_mixed := get_next_header_id;
7459 l_current_header_id := curr_header_id_for_mixed;
7460 IF (g_trace_on = 1) then log_event(' current_header_id '||curr_header_id_for_mixed); END IF;
7461
7462 error_code := 'CARTONIZE 225';
7463 t_lpn_alloc_flag_table.delete;
7464 error_code := 'CARTONIZE 226';
7465
7466 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
7467 error_code := 'CARTONIZE 227';
7468 if (g_trace_on = 1) then log_event('Opening OPACKAGES cursor for l_prev_header_id'||l_prev_header_id); END IF;
7469 OPEN opackages(l_prev_header_id);
7470 ELSE
7471 if (g_trace_on = 1) then log_event('Opening PACKAGES cursor for l_prev_header_id'||l_prev_header_id); END IF;
7472 error_code := 'CARTONIZE 228';
7473 OPEN packages(l_prev_header_id);
7474 END IF;
7475
7476 l_no_pkgs_gen := 'Y';
7477 error_code := 'CARTONIZE 230';
7478
7479 LOOP
7480
7481 if (g_trace_on = 1) then log_event('Fetching Packages cursor '); END IF;
7482 error_code := 'CARTONIZE 240';
7483
7484 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
7485 if (g_trace_on = 1) then log_event('OPACKAGES'); END IF;
7489 if (g_trace_on = 1) then log_event('PACKAGES'); END IF;
7486 FETCH opackages INTO l_temp_id,l_item_id, l_qty, l_tr_qty,l_sec_tr_qty, l_clpn_id, l_citem_id, l_package_id;
7487 EXIT WHEN opackages%notfound;
7488 ELSE
7490 FETCH packages INTO l_temp_id,l_item_id, l_qty, l_tr_qty, l_sec_tr_qty, l_clpn_id, l_citem_id, l_package_id;
7491 EXIT WHEN packages%notfound;
7492 END IF;
7493
7494 IF (g_trace_on = 1) THEN
7495 log_event('temp_id '||l_temp_id );
7496 log_event('item_id '||l_item_id );
7497 log_event('qty '||l_qty );
7498 log_event('tr_qty '||l_tr_qty);
7499 log_event('sec_tr_qty '||l_sec_tr_qty);
7500 log_event('clpn_id '||l_clpn_id);
7501 log_event('citem_id '||l_citem_id);
7502 log_event('package_id '||l_package_id);
7503 END IF;
7504
7505 IF( l_package_id IS NOT NULL ) THEN
7506
7507 l_no_pkgs_gen := 'N';
7508 IF( l_package_id <> l_prev_package_id ) THEN
7509 l_prev_package_id := l_package_id;
7510 IF (g_trace_on = 1) then log_event(' Inserting a new row for package '||l_package_id); END IF;
7511 insert_mmtt
7512 (p_transaction_temp_id => l_temp_id,
7513 p_primary_quantity => l_qty,
7514 p_transaction_quantity => l_tr_qty,
7515 p_secondary_quantity => l_sec_tr_qty, --invconv kkillams
7516 p_new_txn_hdr_id => l_current_header_id,
7517 p_new_txn_tmp_id => get_next_temp_id,
7518 p_clpn_id => l_package_id,
7519 p_item_id => l_citem_id,
7520 x_return_status => l_return_status,
7521 x_msg_count => x_msg_count,
7522 x_msg_data => x_msg_data );
7523 END IF;
7524 IF (g_trace_on = 1) THEN log_event(' Calling InsertPH for temp_id'||l_temp_id); END IF;
7525 IF( outbound = 'Y' ) THEN
7526 Insert_PH(p_move_order_header_id, l_temp_id);
7527 ELSE
7528 Insert_PH(p_transaction_header_id, l_temp_id);
7529 END IF;
7530 END IF;
7531 END LOOP;
7532
7533 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
7534 IF opackages%isopen THEN
7535 CLOSE opackages;
7536 END IF;
7537 ELSE
7538 IF packages%isopen THEN
7539 CLOSE packages;
7540 END IF;
7541 END IF;
7542 END IF; -- pack level <> 0
7543
7544 IF( l_no_pkgs_gen = 'Y' ) THEN
7545 if (g_trace_on = 1) then log_event('no labels generated in the previous level-EXITING'); END IF;
7546 IF ( (outbound = 'Y') AND (pack_level = 0) ) THEN
7547 IF( wct_rows%isopen) then
7548 CLOSE wct_rows;
7549 END IF;
7550 ELSE
7551 IF(bpack_rows%isopen) then
7552 CLOSE bpack_rows;
7553 END IF;
7554 END IF;
7555 EXIT;
7556 END IF;
7557
7558 IF ((outbound = 'Y') AND (pack_level = 0)) THEN
7559 IF wct_rows%isopen THEN
7560 CLOSE wct_rows;
7561 END IF;
7562 ELSE
7563 IF(bpack_rows%isopen) then
7564 CLOSE bpack_rows;
7565 END IF;
7566 END IF;
7567
7568 pack_level := pack_level + 1;
7569
7570 IF (g_trace_on = 1) THEN
7571 log_event(' Incremented the current level');
7572 log_event(' going back to the multi-cart loop');
7573 END IF;
7574 END LOOP; -- Ends the loop for multi level cartonization
7575
7576 l_header_id := p_move_order_header_id;
7577
7578 ELSE
7579 -- Cartonization profile = 'N'
7580 NULL;
7581 END IF;
7582
7583 IF (g_trace_on = 1) THEN log_event('return status is '||x_return_status); END IF;
7584
7585 IF wct_rows%isopen THEN
7586 CLOSE wct_rows;
7587 END IF;
7588
7589 IF p_subinventory_name IS NOT NULL THEN
7590 IF (g_trace_on = 1) THEN log_event(' Updating wct with back to null where the dummy cartonization id was populated for sub restrictions : '); END IF;
7591
7592 UPDATE wms_cartonization_temp
7593 SET cartonization_id = NULL
7594 , container_item_id = NULL
7595 WHERE subinventory_code <> p_subinventory_name
7596 AND organization_id = p_org_id
7597 AND cartonization_id = -99999
7598 AND container_item_id = -99999;
7599 END IF;
7600
7601 EXCEPTION
7602 WHEN fnd_api.g_exc_error THEN
7603 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
7604 ROLLBACK TO cartonize_pub;
7605 x_return_status := fnd_api.g_ret_sts_success;
7609 IF (g_trace_on = 1) THEN log_event('EXCEPTION occurred from ERROR_CODE:'||error_code); END IF;
7606 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
7607 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
7608 FND_MSG_PUB.ADD;
7610 fnd_msg_pub.count_and_get
7611 (
7612 p_count => x_msg_count,
7613 p_data => x_msg_data
7614 );
7615
7616 IF wct_rows%isopen THEN
7617 CLOSE wct_rows;
7618 END IF;
7619
7620 WHEN fnd_api.g_exc_unexpected_error THEN
7621 if (g_trace_on = 1) then log_event('Exception occurred from SQLERRM:'||SQLERRM); END IF;
7622 if (g_trace_on = 1) then log_event('Exception occurred from SQLCODE:'||SQLCODE); END IF;
7623 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
7624 ROLLBACK TO cartonize_pub;
7625 x_return_status := fnd_api.g_ret_sts_unexp_error;
7626
7627 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
7628 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
7629 FND_MSG_PUB.ADD;
7630 if (g_trace_on = 1) then log_event('Exception occurred from ERROR_CODE:'||error_code); END IF;
7631 fnd_msg_pub.count_and_get
7632 (
7633 p_count => x_msg_count,
7634 p_data => x_msg_data
7635 );
7636
7637 IF wct_rows%isopen THEN
7638 CLOSE wct_rows;
7639 END IF;
7640 WHEN OTHERS THEN
7641 ROLLBACK TO cartonize_pub;
7642 if (g_trace_on = 1) then log_event('Rolling back to savepoint cartonize_pub'); END IF;
7643 if (g_trace_on = 1) then log_event('Exception occurred from SQLERRM:'||SQLERRM); END IF;
7644 if (g_trace_on = 1) then log_event('Exception occurred from SQLCODE:'||SQLCODE); END IF;
7645 x_return_status := fnd_api.g_ret_sts_unexp_error;
7646 ERROR_MSG := Sqlerrm;
7647 FND_MESSAGE.SET_NAME('WMS', 'WMS_CARTONIZATION_ERROR');
7648 FND_MESSAGE.SET_TOKEN('ERROR_CODE', ERROR_CODE);
7649 FND_MSG_PUB.ADD;
7650 IF (g_trace_on = 1) THEN log_event('Exception occurred from ERROR_CODE:'||error_code); END IF;
7651
7652 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error ) THEN
7653 fnd_msg_pub.add_exc_msg
7654 ( g_pkg_name,
7655 l_api_name,
7656 ERROR_MSG
7657 );
7658 END IF;
7659
7660 fnd_msg_pub.count_and_get
7661 (
7662 p_count => x_msg_count,
7663 p_data => x_msg_data
7664 );
7665
7666 IF wct_rows%isopen THEN
7667 CLOSE wct_rows;
7668 END IF;
7669
7670 END cartonize_mixed_item;
7671
7672 PROCEDURE cartonize_pick_slip
7673 (
7674 p_org_id IN NUMBER,
7675 p_move_order_header_id IN NUMBER,
7676 p_subinventory_name IN VARCHAR2,
7677 x_return_status OUT NOCOPY VARCHAR2 )
7678 IS
7679 CURSOR Pick_slip_cur
7680 IS
7681 SELECT DISTINCT wct.pick_slip_number
7682 FROM wms_cartonization_temp wct,
7683 mtl_txn_request_lines mtrl,
7684 mtl_parameters mtlp,
7685 mtl_secondary_inventories sub
7686 WHERE mtrl.header_id = p_move_order_header_id
7687 AND mtrl.organization_id = p_org_id
7688 AND wct.move_order_line_id = mtrl.line_id
7689 AND wct.organization_id = mtrl.organization_id
7690 AND mtlp.organization_id = wct.organization_id
7691 AND sub.organization_id = wct.organization_id
7692 AND sub.secondary_inventory_name = wct.subinventory_code
7693 AND wct.cartonization_id IS NULL
7694 AND ((Nvl(mtlp.cartonization_flag,-1) = 1) OR
7695 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
7696 ORDER BY 1 ;
7697
7698 CURSOR Pick_slip_sub_cur
7699 IS
7700 SELECT DISTINCT wct.pick_slip_number
7701 FROM wms_cartonization_temp wct,
7702 mtl_txn_request_lines mtrl,
7703 mtl_parameters mtlp,
7704 mtl_secondary_inventories sub
7705 WHERE mtrl.header_id = p_move_order_header_id
7706 AND mtrl.organization_id = p_org_id
7707 AND wct.move_order_line_id = mtrl.line_id
7708 AND wct.organization_id = mtrl.organization_id
7709 AND wct.subinventory_code = p_subinventory_name
7710 AND mtlp.organization_id = wct.organization_id
7711 AND sub.organization_id = wct.organization_id
7712 AND sub.secondary_inventory_name = wct.subinventory_code
7713 AND wct.cartonization_id IS NULL
7714 AND ((Nvl(mtlp.cartonization_flag,-1) = 1) OR
7715 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
7716 ORDER BY 1 ;
7717
7718 CURSOR Delivery_cur (p_pick_slip_number NUMBER)
7719 IS
7720 SELECT DISTINCT wda.delivery_id
7721 FROM mtl_txn_request_lines mtrl,
7722 wms_cartonization_temp wct,
7723 wsh_delivery_details wdd ,
7727 AND wct.move_order_line_id = mtrl.line_id
7724 wsh_delivery_assignments wda
7725 WHERE mtrl.organization_id = p_org_id
7726 AND mtrl.header_id = p_move_order_header_id
7728 AND wct.organization_id = mtrl.organization_id
7729 AND wct.pick_slip_number = p_pick_slip_number
7730 AND wct.cartonization_id IS NULL
7731 AND wct.demand_source_line = wdd.source_line_id
7732 AND wdd.move_order_line_id = mtrl.line_id
7733 AND wda.delivery_detail_id = wdd.delivery_detail_id
7734 AND wda.delivery_id IS NOT NULL
7735 ORDER BY 1 ;
7736
7737 CURSOR Delivery_sub_cur (p_pick_slip_number NUMBER)
7738 IS
7739 SELECT DISTINCT wda.delivery_id
7740 FROM mtl_txn_request_lines mtrl,
7741 wms_cartonization_temp wct,
7742 wsh_delivery_details wdd ,
7743 wsh_delivery_assignments wda
7744 WHERE mtrl.organization_id = p_org_id
7745 AND mtrl.header_id = p_move_order_header_id
7746 AND wct.move_order_line_id = mtrl.line_id
7747 AND wct.organization_id = mtrl.organization_id
7748 AND wct.subinventory_code = p_subinventory_name
7749 AND wct.pick_slip_number = p_pick_slip_number
7750 AND wct.cartonization_id IS NULL
7751 AND wct.demand_source_line = wdd.source_line_id
7752 AND wdd.move_order_line_id = mtrl.line_id
7753 AND wda.delivery_detail_id = wdd.delivery_detail_id
7754 AND wda.delivery_id IS NOT NULL
7755 ORDER BY 1 ;
7756
7757 l_pick_slip NUMBER;
7758 l_carton_lpn_id NUMBER ;
7759 l_curr_deliv NUMBER;
7760 l_del_det_id_tab WSH_UTIL_CORE.id_tab_type;
7761 l_grouping_rows WSH_UTIL_CORE.id_tab_type;
7762 l_return_status VARCHAR2(100);
7763 l_msg_count NUMBER;
7764 l_msg_data VARCHAR2(10000);
7765 l_index NUMBER;
7766
7767 TYPE l_grp_rec
7768 IS
7769 RECORD
7770 (
7771 grouping_id NUMBER ,
7772 carton_lpn_id NUMBER
7773 );
7774
7775 TYPE l_grp_tb
7776 IS
7777 TABLE OF l_grp_rec INDEX BY BINARY_INTEGER;
7778
7779 l_grp_table l_grp_tb;
7780 BEGIN
7781 IF (g_trace_on = 1) THEN
7782 log_event('In CARTONIZE_PICK_SLIP() with following parameters ');
7783 log_event('p_org_id =>'|| p_org_id );
7784 log_event('p_move_order_header_id =>'|| p_move_order_header_id );
7785 log_event('p_subinventory_name =>'|| p_subinventory_name );
7786 END IF;
7787
7788 IF p_subinventory_name IS NULL THEN
7789 OPEN Pick_slip_cur ;
7790 ELSE
7791 OPEN Pick_slip_sub_cur ;
7792 END IF;
7793
7794 LOOP
7795 IF p_subinventory_name IS NULL THEN
7796 FETCH Pick_slip_cur
7797 INTO l_pick_slip ;
7798 EXIT WHEN Pick_slip_cur%NOTFOUND;
7799 ELSE
7800 FETCH Pick_slip_sub_cur
7801 INTO l_pick_slip ;
7802 EXIT WHEN Pick_slip_sub_cur%NOTFOUND;
7803 END IF;
7804
7805 IF (g_trace_on = 1) THEN
7806 log_event('current Pick slip number : '|| l_pick_slip );
7807 END IF;
7808
7809 IF p_subinventory_name IS NULL THEN
7810 OPEN Delivery_cur (l_pick_slip);
7811 ELSE
7812 OPEN Delivery_sub_cur (l_pick_slip);
7813 END IF;
7814
7815 LOOP
7816 IF p_subinventory_name IS NULL THEN
7817 FETCH Delivery_cur
7818 INTO l_curr_deliv ;
7819 EXIT WHEN Delivery_cur%NOTFOUND;
7820 ELSE
7821 FETCH Delivery_sub_cur
7822 INTO l_curr_deliv ;
7823 EXIT WHEN Delivery_sub_cur%NOTFOUND;
7824 END IF;
7825
7826 IF (g_trace_on = 1) THEN
7827 log_event('Generating lpn for delivery id : '|| l_curr_deliv );
7828 END IF;
7829
7830 l_carton_lpn_id := get_next_package_id;
7831
7832 UPDATE wms_cartonization_temp
7833 SET cartonization_id = l_carton_lpn_id
7834 WHERE transaction_temp_id IN
7835 (SELECT wct.transaction_temp_id
7836 FROM wsh_delivery_details wdd ,
7837 wms_cartonization_temp wct ,
7838 wsh_delivery_assignments wda,
7839 mtl_txn_request_lines mtrl
7840 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
7841 AND wdd.source_line_id = wct.demand_source_line
7845 AND wct.pick_slip_number = l_pick_slip
7842 AND wct.move_order_line_id = mtrl.line_id
7843 AND wct.cartonization_id IS NULL
7844 AND wda.delivery_id = l_curr_deliv
7846 AND wdd.move_order_line_id = mtrl.line_id
7847 AND mtrl.header_id = p_move_order_header_id
7848 AND mtrl.organization_id = p_org_id
7849 ) ;
7850 IF (g_trace_on = 1) THEN
7851 log_event('Updated carton LPN :'|| l_carton_lpn_id ||' for delivery:'||l_curr_deliv );
7852 END IF;
7853 END LOOP ; --Delivery cursor.
7854
7855 IF Delivery_cur%ISOPEN THEN
7856 CLOSE Delivery_cur ;
7857 ELSIF Delivery_sub_cur%ISOPEN THEN
7858 CLOSE Delivery_sub_cur ;
7859 END IF;
7860
7861 IF (g_trace_on = 1) THEN
7862 log_event('Done with all deliveries for this pick slip number, now checking non-delivery WDDs ' );
7863 END IF;
7864 BEGIN --- WDDs which does not have delivery created yet.
7865 l_index := 1 ;
7866
7867 IF p_subinventory_name IS NULL THEN
7868 SELECT wdd.delivery_detail_id BULK COLLECT
7869 INTO l_del_det_id_tab
7870 FROM mtl_txn_request_lines mtrl,
7871 wms_cartonization_temp wct,
7872 wsh_delivery_details wdd ,
7873 wsh_delivery_assignments wda
7874 WHERE mtrl.organization_id = p_org_id
7875 AND mtrl.header_id = p_move_order_header_id
7876 AND wct.move_order_line_id = mtrl.line_id
7877 AND wct.organization_id = mtrl.organization_id
7878 AND wct.pick_slip_number = l_pick_slip
7879 AND wct.cartonization_id IS NULL
7880 AND wct.demand_source_line = wdd.source_line_id
7881 AND wdd.move_order_line_id = mtrl.line_id
7882 AND wda.delivery_detail_id = wdd.delivery_detail_id
7883 AND wda.delivery_id IS NULL;
7884 ELSE
7885 SELECT wdd.delivery_detail_id BULK COLLECT
7886 INTO l_del_det_id_tab
7887 FROM mtl_txn_request_lines mtrl,
7888 wms_cartonization_temp wct,
7889 wsh_delivery_details wdd ,
7890 wsh_delivery_assignments wda
7891 WHERE mtrl.organization_id = p_org_id
7892 AND mtrl.header_id = p_move_order_header_id
7893 AND wct.move_order_line_id = mtrl.line_id
7894 AND wct.organization_id = mtrl.organization_id
7895 AND wct.subinventory_code = p_subinventory_name
7896 AND wct.pick_slip_number = l_pick_slip
7897 AND wct.cartonization_id IS NULL
7898 AND wct.demand_source_line = wdd.source_line_id
7899 AND wdd.move_order_line_id = mtrl.line_id
7900 AND wda.delivery_detail_id = wdd.delivery_detail_id
7901 AND wda.delivery_id IS NULL;
7902 END IF;
7903
7904 IF (g_trace_on = 1) THEN
7905 log_event('There are '||l_del_det_id_tab.COUNT ||' non-delivery WDDs ' );
7906 END IF;
7907
7908 IF (l_del_det_id_tab.COUNT > 0 ) THEN
7909 IF (g_trace_on = 1) THEN
7910 log_event('calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping' );
7911 END IF;
7912 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping( p_line_rows => l_del_det_id_tab,
7913 x_grouping_rows => l_grouping_rows,
7914 x_return_status => l_return_status);
7915 IF l_return_status = 'E' THEN
7916 IF (g_trace_on = 1) THEN
7917 log_event('API WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping returned Error' );
7918 END IF;
7919 x_return_status := fnd_api.g_ret_sts_unexp_error ;
7920 RETURN;
7921 END IF;
7922
7923 FOR i IN l_del_det_id_tab.FIRST .. l_del_det_id_tab.LAST
7924 LOOP
7925 l_carton_lpn_id := NULL ;
7926 FOR j IN 1..l_grp_table.COUNT
7927 LOOP
7928 IF ( l_grouping_rows(i) = l_grp_table(j).grouping_id ) THEN
7929 l_carton_lpn_id := l_grp_table(j).carton_lpn_id ;
7930 END IF;
7931 END LOOP;
7932
7933 IF ( l_carton_lpn_id IS NULL ) THEN
7934 l_carton_lpn_id := get_next_package_id;
7935 l_grp_table(l_index ).grouping_id := l_grouping_rows(i);
7939
7936 l_grp_table(l_index ).carton_lpn_id := l_carton_lpn_id;
7937 l_index := l_index + 1 ;
7938 END IF;
7940 IF (g_trace_on = 1) THEN
7941 log_event('Got carton_lpn_id :'||l_carton_lpn_id );
7942 END IF;
7943
7944 UPDATE wms_cartonization_temp
7945 SET cartonization_id = l_carton_lpn_id
7946 WHERE transaction_temp_id IN
7947 (SELECT wct.transaction_temp_id
7948 FROM wsh_delivery_details wdd ,
7949 wms_cartonization_temp wct,
7950 mtl_txn_request_lines mtrl
7951 WHERE wdd.delivery_detail_id = l_del_det_id_tab (i)
7952 AND wct.pick_slip_number = l_pick_slip
7953 AND wdd.source_line_id = wct.demand_source_line
7954 AND wdd.move_order_line_id = mtrl.line_id
7955 AND wct.move_order_line_id = mtrl.line_id
7956 AND wct.cartonization_id IS NULL
7957 AND mtrl.header_id = p_move_order_header_id
7958 AND mtrl.organization_id = p_org_id
7959 ) ;
7960
7961 IF (g_trace_on = 1) THEN
7962 log_event('Updated WCT for wdd :'||l_del_det_id_tab (i) );
7963 END IF;
7964 END LOOP ; --FOR l_del_det_id_tab records
7965
7966 IF (g_trace_on = 1) THEN
7967 log_event('Done with all non-delivery WDDs for this pick slip number ' );
7968 END IF;
7969 l_grp_table.DELETE ;
7970 l_del_det_id_tab.DELETE ;
7971 END IF; --WDD table count.
7972 EXCEPTION
7973 WHEN NO_DATA_FOUND THEN
7974 IF (g_trace_on = 1) THEN
7975 log_event('All WDDs have delivery associated .' );
7976 END IF;
7977 WHEN OTHERS THEN
7978 IF (g_trace_on = 1) THEN
7979 log_event('OTHERS Exception !!! .' );
7980 END IF;
7981 x_return_status := fnd_api.g_ret_sts_unexp_error ;
7982 END ;
7983 END LOOP ; -- Pick slip cursor.
7984 IF Pick_slip_cur%ISOPEN THEN
7985 CLOSE Pick_slip_cur;
7986 ELSIF Pick_slip_sub_cur%ISOPEN THEN
7987 CLOSE Pick_slip_sub_cur;
7988 END IF;
7989 IF (g_trace_on = 1) THEN
7990 log_event('Done with all pick slip numbers ' );
7991 END IF;
7992 x_return_status := fnd_api.g_ret_sts_success;
7993 IF (g_trace_on = 1) THEN
7994 log_event('Cartonize_pick_slip finished normally.');
7995 END IF;
7996 EXCEPTION
7997 WHEN OTHERS THEN
7998 IF (g_trace_on = 1) THEN
7999 log_event('Error in cartonize_pick_clip () :'||SQLERRM);
8000 END IF;
8001 x_return_status := fnd_api.g_ret_sts_unexp_error ;
8002 END cartonize_pick_slip;
8003
8004
8005 PROCEDURE cartonize_customer_logic
8006 (
8007 p_org_id IN NUMBER
8008 , p_move_order_header_id IN NUMBER
8009 , p_subinventory_name IN VARCHAR2
8010 , x_return_status OUT NOCOPY VARCHAR2
8011 )
8012 IS
8013
8014 TYPE l_cart_tab_type IS TABLE OF mtl_material_transactions_temp.cartonization_id%TYPE INDEX BY BINARY_INTEGER;
8015 TYPE l_trans_temp_tab_type IS TABLE OF mtl_material_transactions_temp.transaction_temp_id%TYPE INDEX BY BINARY_INTEGER;
8016
8017 l_mmtt_table WMS_CARTONIZATION_USER_PUB.mmtt_type;
8018 l_out_mmtt_table WMS_CARTONIZATION_USER_PUB.mmtt_type;
8019
8020 CURSOR Delivery_cur (p_pick_slip_number NUMBER)
8021 IS
8022 SELECT DISTINCT wda.delivery_id
8023 FROM mtl_txn_request_lines mtrl,
8024 wms_cartonization_temp wct,
8025 wsh_delivery_details wdd ,
8026 wsh_delivery_assignments wda
8027 WHERE mtrl.organization_id = p_org_id
8028 AND mtrl.header_id = p_move_order_header_id
8029 AND wct.move_order_line_id = mtrl.line_id
8030 AND wct.organization_id = mtrl.organization_id
8031 AND wct.pick_slip_number = p_pick_slip_number
8032 AND wct.cartonization_id IS NULL
8033 AND wct.demand_source_line = wdd.source_line_id
8034 AND wdd.move_order_line_id = mtrl.line_id
8035 AND wda.delivery_detail_id = wdd.delivery_detail_id
8036 AND wda.delivery_id IS NOT NULL
8037 ORDER BY 1 ;
8038
8039 CURSOR Delivery_sub_cur (p_pick_slip_number NUMBER)
8040 IS
8041 SELECT DISTINCT wda.delivery_id
8042 FROM mtl_txn_request_lines mtrl,
8043 wms_cartonization_temp wct,
8044 wsh_delivery_details wdd ,
8045 wsh_delivery_assignments wda
8046 WHERE mtrl.organization_id = p_org_id
8047 AND mtrl.header_id = p_move_order_header_id
8048 AND wct.move_order_line_id = mtrl.line_id
8049 AND wct.organization_id = mtrl.organization_id
8053 AND wct.demand_source_line = wdd.source_line_id
8050 AND wct.subinventory_code = p_subinventory_name
8051 AND wct.pick_slip_number = p_pick_slip_number
8052 AND wct.cartonization_id IS NULL
8054 AND wdd.move_order_line_id = mtrl.line_id
8055 AND wda.delivery_detail_id = wdd.delivery_detail_id
8056 AND wda.delivery_id IS NOT NULL
8057 ORDER BY 1 ;
8058
8059 l_pick_slip NUMBER;
8060 l_carton_lpn_id NUMBER ;
8061 l_curr_deliv NUMBER;
8062 l_del_det_id_tab WSH_UTIL_CORE.id_tab_type;
8063 l_grouping_rows WSH_UTIL_CORE.id_tab_type;
8064 l_return_status VARCHAR2(100);
8065 l_msg_count NUMBER;
8066 l_msg_data VARCHAR2(10000);
8067 l_index NUMBER;
8068
8069 TYPE l_grp_rec
8070 IS RECORD
8071 (
8072 grouping_id NUMBER ,
8073 carton_lpn_id NUMBER
8074 );
8075
8076 TYPE l_grp_tb
8077 IS
8078 TABLE OF l_grp_rec INDEX BY BINARY_INTEGER;
8079
8080 l_grp_table l_grp_tb;
8081 l_cart_tab l_cart_tab_type;
8082 l_trans_temp_tab l_trans_temp_tab_type;
8083 l_invalid_cartonization EXCEPTION;
8084 l_grouping_rows_temp NUMBER;
8085 l_carton_id_exists VARCHAR2(1);
8086 l_cart_return_status VARCHAR2(1);
8087 l_delivery_id_temp NUMBER;
8088 l_carton_delivery_count NUMBER;
8089 l_cartons_not_stamped VARCHAR2(1) := 'Y';
8090
8091 BEGIN
8092
8093 IF (g_trace_on = 1) THEN
8094 log_event('In CARTONIZE_CUSTOMER_LOGIC() with following parameters ');
8095 log_event('p_org_id =>'|| p_org_id );
8096 log_event('p_move_order_header_id =>'|| p_move_order_header_id );
8097 log_event('p_subinventory_name =>'|| p_subinventory_name );
8098 END IF;
8099
8100 IF p_subinventory_name IS NOT NULL THEN
8101
8102 SELECT wct.* BULK COLLECT INTO l_mmtt_table
8103 FROM wms_cartonization_temp wct,
8104 mtl_txn_request_lines mtrl,
8105 mtl_secondary_inventories sub,
8106 mtl_parameters mtlp
8107 WHERE wct.move_order_line_id =mtrl.line_id
8108 AND mtrl.header_id = p_move_order_header_id
8109 AND mtlp.organization_id = wct.organization_id
8110 AND sub.organization_id = wct.organization_id
8111 AND sub.secondary_inventory_name = wct.subinventory_code
8112 AND wct.subinventory_code = p_subinventory_name
8113 AND wct.organization_id = p_org_id
8114 AND wct.cartonization_id IS NULL
8115 AND wct.transfer_lpn_id IS NULL
8116 AND((Nvl(mtlp.cartonization_flag,-1) = 1) OR
8117 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
8118 ORDER BY wct.move_order_line_id,
8119 wct.inventory_item_id,
8120 Abs(wct.transaction_temp_id);
8121 ELSE
8122
8123 SELECT wct.* BULK COLLECT INTO l_mmtt_table
8124 FROM wms_cartonization_temp wct,
8125 mtl_txn_request_lines mtrl,
8126 mtl_secondary_inventories sub,
8127 mtl_parameters mtlp
8128 WHERE wct.move_order_line_id =mtrl.line_id
8129 AND mtrl.header_id = p_move_order_header_id
8130 AND mtlp.organization_id = wct.organization_id
8131 AND sub.secondary_inventory_name = wct.subinventory_code
8132 AND sub.organization_id = wct.organization_id
8133 AND wct.organization_id = p_org_id
8134 AND wct.cartonization_id IS NULL
8135 AND wct.transfer_lpn_id IS NULL
8136 AND((Nvl(mtlp.cartonization_flag,-1) = 1) OR
8137 (Nvl(mtlp.cartonization_flag,-1) = 3 AND sub.cartonization_flag = 1))
8138 ORDER BY wct.move_order_line_id,
8139 wct.inventory_item_id,
8140 Abs(wct.transaction_temp_id);
8141
8142 END IF;
8143
8144 IF (g_trace_on = 1) THEN
8145 log_event('l_mmtt_table.COUNT : ' || l_mmtt_table.COUNT);
8146 END IF;
8147
8148 WMS_CARTONIZATION_USER_PUB.CARTONIZE (
8149 x_return_status => l_cart_return_status
8150 , x_msg_count => l_msg_count
8151 , x_msg_data => l_msg_data
8152 , x_task_table => l_out_mmtt_table
8153 , p_organization_id => p_org_id
8154 , p_task_table => l_mmtt_table
8155 );
8156
8157 IF (g_trace_on = 1) THEN
8158 log_event('l_out_mmtt_table.COUNT : ' || l_out_mmtt_table.COUNT);
8159 END IF;
8160
8161 IF NVL(l_cart_return_status,'E') = 'E'
8162 OR l_mmtt_table.COUNT <> l_out_mmtt_table.COUNT THEN
8163 IF (g_trace_on = 1) THEN
8164 log_event('WMS_CARTONIZATION_USER_PUB.cartonize() returned failure, exiting cartonize_customer_logic() ');
8165 END IF;
8166 x_return_status := 'E';
8167 RETURN;
8168 END IF;
8169
8170 -- loop to get the distinct cartonization ids
8171 -- l_cart_tab(1) := l_out_mmtt_table(1).cartonization_id;
8172
8173 l_cart_tab.DELETE;
8174
8175 IF (g_trace_on = 1) THEN
8176 log_event('Reached SAVEPOINT CUSTOMER_LOGIC_SP');
8177 END IF;
8178
8179 SAVEPOINT CUSTOMER_LOGIC_SP;
8180
8181 FOR i IN l_out_mmtt_table.FIRST .. l_out_mmtt_table.LAST LOOP
8182
8183 IF l_out_mmtt_table(i).cartonization_id IS NOT NULL THEN
8184
8185 IF l_cart_tab.COUNT = 0 THEN
8186 l_cart_tab(1) := l_out_mmtt_table(i).cartonization_id;
8187 END IF;
8188
8189 l_cartons_not_stamped := 'N';
8190
8191 UPDATE wms_cartonization_temp
8192 SET cartonization_id = l_out_mmtt_table(i).cartonization_id
8193 , container_item_id = l_out_mmtt_table(i).container_item_id
8194 WHERE transaction_temp_id = l_out_mmtt_table(i).transaction_temp_id;
8195
8196 l_carton_id_exists := 'N';
8197
8198 FOR j IN l_cart_tab.FIRST .. l_cart_tab.LAST LOOP
8199 IF l_out_mmtt_table(i).cartonization_id = l_cart_tab(j) THEN
8200 l_carton_id_exists := 'Y';
8201 EXIT;
8202 END IF;
8203 END LOOP;
8204 IF l_carton_id_exists = 'N' THEN
8205 l_cart_tab(l_cart_tab.COUNT + 1) := l_out_mmtt_table(i).cartonization_id;
8206 END IF;
8207 END IF;
8208
8209 END LOOP;
8210
8211 IF (g_trace_on = 1) THEN
8212 log_event('Updated WCT rows with customer logic cartonization ids');
8213 END IF;
8214
8215 IF l_cartons_not_stamped = 'Y' THEN
8216 IF (g_trace_on = 1) THEN
8217 log_event('The customer did not stamp cartonization_id on any task, returning');
8218 END IF;
8219 RAISE L_INVALID_CARTONIZATION;
8220 END IF;
8221
8222 FOR i IN l_cart_tab.FIRST .. l_cart_tab.LAST LOOP
8223
8224 l_del_det_id_tab.DELETE;
8225
8226 IF (g_trace_on = 1) THEN
8227 log_event('Getting WDD rows for cartonization_id : '|| l_cart_tab(i));
8228 END IF;
8229
8230 SELECT DISTINCT wdd.delivery_detail_id BULK COLLECT
8231 INTO l_del_det_id_tab
8232 FROM wsh_delivery_details wdd,
8233 wms_cartonization_temp wct,
8234 mtl_txn_request_lines mtrl
8235 WHERE wct.move_order_line_id = mtrl.line_id
8236 AND mtrl.header_id = p_move_order_header_id
8237 AND wct.organization_id = mtrl.organization_id
8238 AND wct.demand_source_line = wdd.source_line_id
8239 AND wct.organization_id = p_org_id
8240 AND wdd.move_order_line_id = mtrl.line_id
8241 AND wct.cartonization_id = l_cart_tab(i);
8242
8243 IF (g_trace_on = 1) THEN
8244 FOR j IN l_del_det_id_tab.FIRST .. l_del_det_id_tab.LAST LOOP
8245 log_event('l_del_det_id_tab ('|| i ||') : '|| l_del_det_id_tab(j));
8246 END LOOP;
8247 END IF;
8248
8249 IF (l_del_det_id_tab.COUNT > 0 ) THEN
8250
8251 IF (g_trace_on = 1) THEN
8255 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping
8252 log_event('calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping' );
8253 END IF;
8254
8256 (
8257 p_line_rows => l_del_det_id_tab,
8258 x_grouping_rows => l_grouping_rows,
8259 x_return_status => l_return_status
8260 );
8261
8262 IF NVL(l_return_status,'E') = 'E' THEN
8263 IF (g_trace_on = 1) THEN
8264 log_event('API WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping returned Error' );
8265 END IF;
8266 RAISE L_INVALID_CARTONIZATION;
8267 END IF;
8268
8269 IF (g_trace_on = 1) THEN
8270 log_event('Grouping rows returned for cartonization_id : '|| l_cart_tab(i));
8271 FOR j IN l_grouping_rows.FIRST .. l_grouping_rows.LAST LOOP
8272 log_event('l_grouping_rows ( '|| i || ' ) : ' || l_grouping_rows(j));
8273 END LOOP;
8274 END IF;
8275
8276 l_grouping_rows_temp := l_grouping_rows(1);
8277 FOR j IN l_grouping_rows.FIRST .. l_grouping_rows.LAST LOOP
8278 IF l_grouping_rows_temp <> l_grouping_rows(j) THEN
8279 log_event('Tasks associated with cartonization_id '|| l_cart_tab(i)|| ' cannot be shipped together');
8280 RAISE L_INVALID_CARTONIZATION;
8281 END IF;
8282 END LOOP;
8283 END IF;
8284 END LOOP;
8285
8286 IF (g_trace_on = 1) THEN
8287 log_event ('Suggest containers by customer algorithm are verified successfully.');
8288 log_event ('Exiting normally from cartonize_customer_logic()');
8289 END IF;
8290
8291 EXCEPTION
8292 WHEN L_INVALID_CARTONIZATION THEN
8293 x_return_status := fnd_api.g_ret_sts_unexp_error ;
8294 IF (g_trace_on = 1) THEN
8295 log_event('Unable to cartonize, ROLLING BACK to CUSTOMER_LOGIC_SP and exiting from cartonize_customer_logic');
8296 END IF;
8297 ROLLBACK TO CUSTOMER_LOGIC_SP;
8298 WHEN OTHERS THEN
8299
8300 x_return_status := fnd_api.g_ret_sts_unexp_error ;
8301 IF (g_trace_on = 1) THEN
8302 log_event('Unexpected error in cartonize_customer_logic(), rolling back to CUSTOMER_LOGIC_SP');
8303 log_event('SQLCODE : ' || SQLCODE);
8304 log_event('SQLERRM : ' || SQLERRM);
8305 END IF;
8306 ROLLBACK TO CUSTOMER_LOGIC_SP;
8307
8308 END cartonize_customer_logic;
8309
8310
8311 PROCEDURE cartonize_default_logic (
8312 p_org_id IN NUMBER,
8313 p_move_order_header_id IN NUMBER,
8314 p_out_bound IN VARCHAR2,
8315 x_return_status OUT NOCOPY VARCHAR2,
8316 x_msg_count OUT NOCOPY NUMBER,
8317 x_msg_data OUT NOCOPY VARCHAR2
8318 )
8319 IS
8320 l_api_return_status VARCHAR2(1);
8321
8322 BEGIN
8323
8324 IF (g_trace_on = 1) THEN
8325 log_event ('IN CARTONIZE_DEFAULT_LOGIC()');
8326 log_event ('calling procedure CARTONIZE_SINGLE_ITEM()');
8327 END IF;
8328
8329 cartonize_single_item
8330 (
8331 x_return_status => l_api_return_status,
8332 x_msg_count => x_msg_count,
8333 x_msg_data => x_msg_data,
8334 p_out_bound => 'Y',
8335 p_org_id => p_org_id,
8336 p_move_order_header_id => p_move_order_header_id
8337 );
8338
8339 IF (g_trace_on = 1) THEN
8340 log_event ('calling procedure CARTONIZE_MIXED_ITEM()');
8341 END IF;
8342
8343 cartonize_mixed_item
8344 (
8345 x_return_status => l_api_return_status,
8346 x_msg_count => x_msg_count,
8347 x_msg_data => x_msg_data,
8348 p_out_bound => 'Y',
8349 p_org_id => p_org_id,
8350 p_move_order_header_id => p_move_order_header_id,
8351 p_transaction_header_id => NULL,
8352 p_stop_level => 0, -- For first level only
8353 p_pack_level => 0
8354 );
8355
8356 IF (g_trace_on = 1) THEN log_event ('Returing normally from CARTONIZE_DEFAULT_LOGIC()'); END IF;
8357 x_return_status := 'S';
8358 EXCEPTION
8359 WHEN OTHERS THEN
8360 IF (g_trace_on = 1) THEN log_event ('SQL Error Message : '|| SQLERRM); END IF;
8361 IF (g_trace_on = 1) THEN log_event ('SQL Error Code : '|| SQLCODE); END IF;
8362 x_return_status := 'E';
8363 END;
8364
8365 PROCEDURE insert_ph
8366 (
8367 p_move_order_header_id IN NUMBER,
8368 p_current_header_id IN NUMBER,
8369 x_return_status OUT NOCOPY NUMBER
8370 )
8371 IS
8372
8373 L_PREV_PACKAGE_ID NUMBER;
8374 L_PREV_HEADER_ID NUMBER;
8375 L_CURRENT_HEADER_ID NUMBER;
8376 l_qty NUMBER := NULL;
8377 l_tr_qty NUMBER := NULL;
8378 l_sec_tr_qty NUMBER := NULL;
8379 l_clpn_id NUMBER := NULL;
8380 l_citem_id NUMBER := NULL;
8381 l_package_id NUMBER := NULL;
8382 l_upd_qty_flag VARCHAR2(1) := NULL;
8383 L_no_pkgs_gen VARCHAR2(1);
8384 l_temp_id NUMBER;
8385 l_item_id NUMBER;
8386 l_return_status VARCHAR2(1);
8387 l_msg_count NUMBER;
8391 CURSOR opackages(p_hdr_id NUMBER) IS
8388 l_msg_data VARCHAR2(2000);
8389
8390
8392 SELECT
8393 wct.transaction_temp_id,
8394 wct.inventory_item_id,
8395 wct.primary_quantity,
8396 wct.transaction_quantity,
8397 wct.secondary_transaction_quantity, --invconv kkillams
8398 wct.content_lpn_id,
8399 wct.container_item_id,
8400 wct.cartonization_id
8401 FROM
8402 wms_cartonization_temp wct,
8403 mtl_txn_request_lines mtrl
8404 WHERE
8405 wct.move_order_line_id = mtrl.line_id AND
8406 mtrl.header_id = p_move_order_header_id
8407 ORDER BY wct.cartonization_id;
8408
8409 BEGIN
8410
8411 IF (g_trace_on = 1) THEN log_event('Coming in my insert_ph'); END IF;
8412 IF (g_trace_on = 1) THEN log_event('Pack_level' || pack_level); END IF;
8413 l_prev_package_id := -1;
8414 l_prev_header_id := p_current_header_id;
8415 l_current_header_id := get_next_header_id;
8416 curr_header_id_for_mixed := l_current_header_id;
8417
8418 IF (g_trace_on = 1) THEN log_event('Setting curr_header_id_for_mixed : ' || curr_header_id_for_mixed); END IF;
8419
8420
8421 t_lpn_alloc_flag_table.DELETE;
8422
8423 OPEN opackages(l_prev_header_id);
8424 l_no_pkgs_gen := 'Y';
8425
8426 LOOP
8427
8428 IF (g_trace_on = 1) THEN
8429 log_event('Fetching Packages cursor ');
8430 END IF;
8431
8432 error_code := 'CARTONIZE 240';
8433
8434 FETCH opackages INTO l_temp_id,l_item_id, l_qty, l_tr_qty,l_sec_tr_qty, l_clpn_id, l_citem_id, l_package_id;
8435 EXIT WHEN opackages%notfound;
8436
8437 IF (g_trace_on = 1) THEN
8438 log_event('temp_id '||l_temp_id );
8439 log_event('item_id '||l_item_id );
8440 log_event('qty '||l_qty );
8441 log_event('tr_qty '||l_tr_qty);
8442 log_event('sec_tr_qty '||l_sec_tr_qty);
8443 log_event('clpn_id '||l_clpn_id);
8444 log_event('citem_id '||l_citem_id);
8445 log_event('package_id '||l_package_id);
8446 END IF;
8447
8448 IF( l_package_id IS NOT NULL ) THEN
8449
8450 l_no_pkgs_gen := 'N';
8451 IF( l_package_id <> l_prev_package_id ) THEN
8452 l_prev_package_id := l_package_id;
8453
8454 IF (g_trace_on = 1) THEN
8455 log_event(' Inserting a new row for package '||l_package_id);
8456 END IF;
8457
8458 insert_mmtt
8459 (
8460 p_transaction_temp_id => l_temp_id,
8461 p_primary_quantity => l_qty,
8462 p_transaction_quantity => l_tr_qty,
8463 p_secondary_quantity => l_sec_tr_qty, --invconv kkillams
8464 p_new_txn_hdr_id => l_current_header_id,
8465 p_new_txn_tmp_id => get_next_temp_id,
8466 p_clpn_id => l_package_id,
8467 p_item_id => l_citem_id,
8468 x_return_status => l_return_status,
8469 x_msg_count => l_msg_count,
8470 x_msg_data => l_msg_data
8471 );
8472 END IF;
8473
8474 IF (g_trace_on = 1) THEN
8475 log_event(' Calling InsertPH for temp_id'||l_temp_id);
8476 END IF;
8477
8478 insert_ph(p_move_order_header_id, l_temp_id);
8479
8480 END IF;
8481 END LOOP;
8482
8483 IF opackages%isopen THEN
8484 CLOSE opackages;
8485 END IF;
8486
8487 END insert_ph;
8488
8489
8490
8491 END WMS_CARTNZN_PUB;