--[[
|
编码: GT-122-01
|
名称: 点击确定按钮后
|
作者:LZH
|
日期:2024-8-25
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: AfterClickOk
|
|
功能:
|
|
|
更改记录:
|
V1.1 LZH 20241028 出库重新统计【烘胶维护】里面的库存量
|
|
--]]
|
json = require("json")
|
mobox = require("OILua_JavelinExt")
|
wms_wh = require("wms_wh")
|
wms_base = require("wms_base")
|
wms_cntr = require("wms_container")
|
function AfterClickOk(strLuaDEID)
|
local nRet, strRetInfo
|
|
nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_CNTR_CODE")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! " .. strRetInfo) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
|
local obj_attrs = json.decode(strRetInfo)
|
local cntr_code = obj_attrs[1].value
|
|
--获取货位容器信息
|
nRet, strRetInfo = m3.GetDataObjectByKey(strLuaDEID, "Loc_Container", "S_CNTR_CODE", cntr_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
|
local loc_code = strRetInfo.loc_code
|
|
-- 容器货位解绑
|
nRet, strRetInfo = wms_wh.Loc_Container_Unbinding(strLuaDEID, loc_code, cntr_code, "绑定解绑方法-系统",
|
"强制完成")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '货位容器解绑失败!' .. strRetInfo) end
|
|
-- 容器解锁
|
local container
|
nRet, container = wms_cntr.GetInfo(strLuaDEID, cntr_code)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '获取容器对象失败!' .. container) end
|
nRet, strRetInfo = wms_cntr.SetLock(strLuaDEID, container, "锁类型-无", "无")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), '托盘容器解锁失败!' .. strRetInfo) end
|
|
-- 获取出库单据明细信息
|
local stock_out
|
local strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( '执行','等待')"
|
nRet, stock_out = m3.GetDataObjByCondition(strLuaDEID, "GT_SO_Detail", strCondition)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. stock_out)
|
end
|
-- 设置出库单明细状态为完成
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "' AND S_STATE IN( '执行','等待')"
|
local strSetSQL_update = " S_STATE = '完成'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_SO_Detail", strCondition, strSetSQL_update)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end
|
|
strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "' AND S_STATE <> '完成'"
|
nRet, strRetInfo = mobox.getDataObjCount(strLuaDEID, "GT_SO_Detail", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
|
if (tonumber(strRetInfo) <= 0) then
|
-- 设置出库单状态为完成
|
strCondition = "S_DO_NO = '" .. stock_out.delivery_no .. "'"
|
strSetSQL_update = " S_STATE = '完成'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Stock_Out", strCondition, strSetSQL_update)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "修改出库单据状态失败!" .. strRetInfo) end
|
end
|
|
-- 获取容器货品信息
|
local cg_detail
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
nRet, cg_detail = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 失败!" .. cg_detail) end
|
|
-- 获取入库单据行信息
|
local label_crad
|
strCondition = "S_SERIAL_NO = '" .. cg_detail.serial_no .. "'"
|
nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition, "T_CREATE DESC")
|
if (nRet == 1) then
|
nRet, label_crad = m3.GetDataObjByCondition(strLuaDEID, "GT_ROM", strCondition, "T_CREATE DESC")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取流水号信息失败!" .. label_crad) end
|
elseif (nRet > 1) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据行信息失败!" .. label_crad)
|
end
|
|
-- 获取入库单据头信息
|
local incoming_Info
|
strCondition = "S_DELIVERY_NO = '" ..label_crad.delivery_no.. "' AND N_DELIVERY_ROW_NO = '" .. label_crad.delivery_row_no .. "'"
|
nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition, "T_CREATE DESC")
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "获取入库单据头信息失败!" .. incoming_Info) end
|
|
-- 如果出库单是手工录入的则创建GTWMS同步记录
|
if (incoming_Info.type == '人工录入') then
|
-- 创建【GTWMS同步记录】
|
local sys_record = m3.AllocObject(strLuaDEID, "GTWMS_SYNC_RECORD")
|
sys_record.delivery_no = incoming_Info.delivery_no
|
sys_record.delivery_row_no = incoming_Info.delivery_row_no
|
sys_record.lpn = cg_detail.serial_no
|
sys_record.rfid = cg_detail.cntr_code
|
sys_record.lpnweight = cg_detail.qty
|
sys_record.sku = cg_detail.item_code
|
sys_record.batch_no = cg_detail.batch_no
|
sys_record.remark3 = cg_detail.serial_no
|
sys_record.grade = incoming_Info.level
|
sys_record.type = "出库回传"
|
lua.Debug(strLuaDEID, debug.getinfo(1), 'sys_record', sys_record)
|
nRet, sys_record = m3.CreateDataObj(strLuaDEID, sys_record)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【GTWMS同步记录】对象失败!' .. sys_record) end
|
else
|
-- 出库结果回传
|
local data = {
|
wh_code = "wmwhse1",
|
task_no = stock_out.delivery_no,
|
batch_no = cg_detail.batch_no,
|
sku = cg_detail.item_code,
|
qty = cg_detail.qty,
|
rfid = cg_detail.cntr_code,
|
number_no = label_crad.serial_no,
|
supplier = incoming_Info.vendor,
|
grade = incoming_Info.level,
|
subloc = label_crad.subpool
|
}
|
local source = "GTWMS出库回传"
|
|
-- 调用GT-WMS的回传接口
|
local url = wms_base.Get_sConst(strLuaDEID, "GTWMS-url")
|
local strurl = url
|
local strHeader = ""
|
local strBody = {
|
application = "GITI",
|
code = "WCS_SO_WMS",
|
data = data
|
}
|
nRet, strRetInfo = CreateInterfaceExc(strLuaDEID, strurl, strHeader, strBody, "GTWMS", source)
|
if (nRet ~= 0) then
|
lua.Error(strLuaDEID, debug.getinfo(1), "调用WCS接口失败!" .. strRetInfo)
|
end
|
end
|
|
-- 删除容器货品明细记录
|
strCondition = "S_CNTR_CODE = '" .. cntr_code .. "'"
|
nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "CG_Detail", strCondition)
|
if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
|
|
mobox.setInfo(strLuaDEID, "出库成功!")
|
end
|