--[[
|
版本: Version 2.1
|
创建日期: 2024-7-26
|
创建人: HAN
|
|
WMS-Basis-Model-Version: V15.5
|
|
功能:
|
所以和入库相关的函数
|
|
更改说明:
|
|
--]]
|
|
wms_base = require ("wms_base")
|
wms_wh = require ("wms_wh")
|
|
local wms_in = {_version = "0.2.1"}
|
|
--[[
|
预分配容器取消
|
-- 组盘【Pre_Alloc_Container】状态设置为 6/取消 同时
|
-- 组盘明细【Pre_Alloc_CNTR_Detail】状态改为 3
|
-- 来源业务数据中的取消数量+ 组盘明细中的数量
|
--]]
|
function wms_in.Pre_Alloc_CNTR_Cancel( strLuaDEID, pac_obj )
|
local n, nRet, strRetInfo
|
-- 组盘已经完成或取消状态不需要再做 取消
|
if ( pac_obj.b_state > 1 ) then return 0 end
|
|
-- 6 表示'取消'
|
local strUpdateSql = "N_B_STATE = 6"
|
local strCondition = "S_PAC_NO = '"..pac_obj.pac_no.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_Container", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then return 1, "更新【预分配容器】信息失败!"..strRetInfo end
|
-- 更新 Pre_Alloc_CNTR_Detail 中的状态
|
strUpdateSql = "N_B_STATE = 3"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then return 1, "更新【预分配容器明细】信息失败!"..strRetInfo end
|
|
-- 查询组盘明细
|
local data_objects
|
nRet, data_objects = m3.QueryDataObject(strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, "N_BS_ROW_NO" )
|
if (nRet ~= 0) then return 2, "QueryDataObject失败!"..data_objects end
|
if ( data_objects == '') then return 0 end
|
|
local obj_attrs
|
local strSetAttr
|
for n = 1, #data_objects do
|
obj_attrs = m3.KeyValueAttrsToObjAttr(data_objects[n].attrs)
|
|
-- 根据业务来源加 F_ACC_I_QTY/累计入库数量
|
if ( obj_attrs.S_BS_TYPE == "Inbound_Order" ) then
|
if ( obj_attrs.S_BS_NO ~= nil and obj_attrs.S_BS_NO ~= '' ) then
|
strCondition = "S_IO_NO = '"..obj_attrs.S_BS_NO.."' AND S_ITEM_CODE = '"..obj_attrs.S_ITEM_CODE.."'"
|
strSetAttr = "F_ACC_C_QTY = F_ACC_C_QTY + "..obj_attrs.F_QTY
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Inbound_Detail", strCondition, strSetAttr )
|
if (nRet ~= 0) then return 1, "设置【Inbound_Detail】累计入库数量失败!"..strRetInfo end
|
end
|
elseif ( obj_attrs.S_BS_TYPE == 'Inbound_Wave' ) then
|
if ( obj_attrs.S_BS_NO ~= nil and obj_attrs.S_BS_NO ~= '' ) then
|
strCondition = "S_WAVE_NO = '"..obj_attrs.S_BS_NO.."' AND S_ITEM_CODE = '"..obj_attrs.S_ITEM_CODE.."'"
|
strSetAttr = "F_ACC_C_QTY = F_ACC_C_QTY + "..obj_attrs.F_QTY
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "IW_Detail", strCondition, strSetAttr )
|
if (nRet ~= 0) then return 1, "设置【IW_Detail】累计入库数量失败!"..strRetInfo end
|
end
|
end
|
end
|
return 0
|
end
|
|
-- 获取收货单明细和存储量有关的信息
|
local function get_inventory_info( strLuaDEID, receipt_obj )
|
local inventory_info = '{"wh_code": "'..receipt_obj.wh_code..'",'
|
inventory_info = inventory_info..'"area_code": "'..receipt_obj.area_code..'",'
|
inventory_info = inventory_info..'"item_code": "'..receipt_obj.item_code..'",'
|
inventory_info = inventory_info..'"item_name": "'..lua.FormatJsonString(receipt_obj.item_name)..'",'
|
inventory_info = inventory_info..'"item_state": "'..receipt_obj.item_state..'",'
|
inventory_info = inventory_info..'"item_route": "'..receipt_obj.item_route..'",'
|
inventory_info = inventory_info..'"qty": "'..receipt_obj.qty..'"}'
|
return inventory_info
|
end
|
|
-- 通过收货单创建检验单及验单明细,并且加仓库
|
-- receipt_obj 收货单数对象
|
-- inspection_area 检验区
|
function wms_in.CreateInspectionOrder( strLuaDEID, receipt_obj, inspection_area )
|
local strCondition, nRet, strRetInfo
|
|
-- step1 创建检验单
|
local inspection = m3.AllocObject(strLuaDEID,"Inspect_Order")
|
local ret_obj
|
local n, area_items
|
|
inspection.wms_op_no = receipt_obj.no
|
inspection.inspect_type = 1 -- 收货检
|
inspection.factory = receipt_obj.factory
|
inspection.bs_type = receipt_obj.bs_type
|
inspection.bs_no = receipt_obj.bs_no
|
inspection.wh_code = receipt_obj.wh_code
|
|
-- 获取检验区
|
-- 获取仓库检验区可以看成是逻辑上的检验区)
|
local inspection_area = ''
|
n,area_items = wms_wh.GetArea( strLuaDEID, wh_code, 3 )
|
if ( n == 1 ) then
|
inspection_area = lua.trim_quotation_mark( area_items )
|
elseif ( n > 1 ) then
|
end
|
inspection.area_code = inspection_area
|
|
nRet, ret_obj = m3.CreateDataObj( strLuaDEID, inspection )
|
if ( nRet ~= 0 ) then return 1, "创建【检验单】失败! "..ret_obj end
|
local strNo = ret_obj.no
|
if ( strNo == nil or strNo == '' ) then return 1, "创建【检验单】后获取的验单号为空或 nil! " end
|
|
-- step2: 获取收货单明细生成验单明细
|
local strOrder = 'N_ROW_NO'
|
strCondition = "S_RECEIPT_NO = '"..receipt_obj.no.."'"
|
nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "Receipt_Detail", strCondition, strOrder, "S_ITEM_CODE", "S_ITEM_NAME","S_ITEM_SPEC","N_ITEM_STATE",
|
"S_BATCH_NO", "S_SERIAL_NO", "F_QTY", "S_UOM", "S_BATCH_NO", "S_SERIAL_NO" )
|
if ( nRet ~= 0 ) then return 1, "获取【收货单明细】失败! "..strRetInfo end
|
|
local retObjs = json.decode( strRetInfo )
|
local nObjs = #retObjs
|
local n, nMaxAttr
|
local attrs
|
local receipt_detail
|
local inventory_change = ''
|
|
for n = 1, nObjs do
|
attrs = retObjs[n].attrs
|
nMaxAttr = #attrs
|
nRet, receipt_detail = m3.ObjAttrStrToLuaObj( "Receipt_Detail", lua.table2str(attrs) )
|
if ( nRet ~= 0 ) then return 1, "m3.ObjAttrStrToLuaObj(Receipt_Detail) 失败! "..receipt_detail end
|
|
attrs[nMaxAttr+1] = lua.KeyValueObj( "S_INSPECT_NO", strNo )
|
nRet, strRetInfo = mobox.createDataObj( strLuaDEID, "Inspect_Detail", lua.table2str(attrs) )
|
if ( nRet ~= 0 ) then return 1, "创建【检验单明细】失败! "..strRetInfo end
|
|
-- 生成仓库量变化输入参
|
inventory_change = inventory_change .. get_inventory_info( strLuaDEID, receipt_detail )..","
|
end
|
inventory_change = lua.trim_laster_char( inventory_change )
|
if ( inventory_change ~= '' ) then
|
nRet, strRetInfo = wms.wms_AddWHInventoryChange(strLuaDEID, 5, '['..inventory_change..']')
|
if ( nRet ~= 0 ) then return 1, "wms_AddWHInventoryChange 失败! "..strRetInfo end
|
end
|
|
return 0
|
end
|
|
|
return wms_in
|