lzh
2025-06-19 3a6436e0c88042c6ce8dca2fe8adb0109f0ad9e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--[[
    编码: GT-100-02
    名称: GT-WMS出库任务下发
    作者:LZH
    入口函数: SendOutboundOrder
 
 
    功能说明:
        GT-WMS下发出库信息给 GZ-WMS系统,GZ-WMS系统根据出库信息生成【出库单据】和【作业】            
 
        输入数据:        
        {
            "task_no": "xxxx",    -- 出库任务号
            "batch_no": "xxx",    -- 批次号
            "item_code": "xxx",         -- 物料编码
            "end_loc": "xxx",       -- 机台
            "qty": "xxx",         -- 数量默认1托
            "wh_code": "xxx",     -- 仓库编号
            "mes_task_no": "xxx",     -- MES任务单号
            "remark1": "",  -- 备注 暂未启用
            "remark2": "",  -- 备注 暂未启用
            "remark3": "",  -- 备注 暂未启用
            "remark4": ""   -- 备注 暂未启用
        }                                                                                            
 
        处理逻辑
        -- step1 解析接口传递的 datajson 参数
                判断 json 解析是否成功,不成功返回报错
                判断 字段 是否都有值?没值报错返回
 
        -- step2 根据字段信息生产【出库单】
        -- step3 调用【出库单】创建作业事件
                                                                    
    变更记录:
    20241122 LZH V1.1 出库单修改为主子表,代码调整
    20250221 LZH V1.2 新增4个备用字段
    20250429 LZH V1.3 新增MES任务单号
--]]
m3    = require("oi_base_mobox")
json  = require("json")
mobox = require("OILua_JavelinExt")
require("GT-Base")
function CreateDelivery(strLuaDEID)
    local nRet, strRetInfo, in_date, dictItem
    -- step1 获取接口数据
    nRet, in_date = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WCStoreCallback 无法获取数据包!" .. in_date) end
    lua.Debug(strLuaDEID, debug.getinfo(1), '出库单据下发参数:', in_date)
 
    -- 获取 task_no、wh_code 、batch_no、end_loc、item_code 判断是否都有值?没值报错返回
    local task_no = in_date.task_no
    if (task_no == nil or task_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "出库任务号不能为空!") end
    local wh_code = in_date.wh_code
    if (wh_code == nil or wh_code == '') then wh_code = 'wmwhse1' end
    local batch_no = in_date.batch_no
    if (batch_no == nil or batch_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "批次号不能为空!") end
    local end_loc = in_date.end_loc
    if (end_loc == nil or end_loc == '') then lua.Error(strLuaDEID, debug.getinfo(1), "机台不能为空!") end
    local item_code = in_date.item_code
    if (item_code == nil or item_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "物料号不能为空!") end
    -- V1.2 新增备用字段
    local remark1 = in_date.remark1
    local remark2 = in_date.remark2
    local remark3 = in_date.remark3
    local remark4 = in_date.remark4
    -- V1.3 新增MES任务单号
    local mes_task_no = in_date.mes_task_no
 
    -- 获取不需要审核的物料类型字典
    nRet, dictItem = mobox.getDictItemIInfo("GT_NotAuditType")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), dictItem) end
    dictItem = json.decode(dictItem)
    lua.Debug(strLuaDEID, debug.getinfo(1), '不需要审核的物料:', dictItem)
 
    -- 获取该物料的物料类型
    local item_type, material
    nRet, item_type, material = GT_Get_ItemType(strLuaDEID, item_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), item_type) end
 
    -- 获取一个初始的【出库单】数据对象
    local stock_out = m3.AllocObject(strLuaDEID, "GT_Stock_Out")
    stock_out.delivery_no = task_no
    stock_out.batch_no = batch_no
    stock_out.wh_code = wh_code
    stock_out.item_code = item_code
    stock_out.ms_code = end_loc
    -- V1.3 新增MES任务单号
    stock_out.mes_task_no = mes_task_no
    -- step3 如果出库库区为立库的出库单,触发后台脚本进行配货逻辑
    for m = 1, #dictItem do
        if (item_type == dictItem[m].name) then
            stock_out.state = "启用"
            goto back
        end
    end
    ::back::
    nRet, stock_out = m3.CreateDataObj(strLuaDEID, stock_out)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'mobox 创建【出库单】对象失败!' .. stock_out) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'stock_out:', stock_out)
 
    if(item_type ~= '碳黑' and item_type ~= '帘子布' and item_type ~= '辅材')then
        -- 调用创建作业事件
        nRet, strRetInfo = mobox.triggerClsEvent(strLuaDEID, "GT_Stock_Out", stock_out.id, "创建作业")
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "执行【出库单】创建作业脚本失败!" .. strRetInfo) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'nRet:', nRet)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo:', strRetInfo)
    end
end