1
Jianw
2025-07-09 88e26a2a960dbbc148332772448b79b9877102d8
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
--[[
    编码: WMS-52-17
    名称: 出库分拣-条码输入变化后
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: AfterUPCChange
 
    功能:
        -- 根据输入的条码到【SKU_UPC】找到货品编码
        -- 如果当前入库任务的货品编码相同 组盘数量+1
 
 
    更改记录:
 
--]]
 
prj_base = require( "prj_base" )
wms_out  = require ("wms_outbound")
 
function AfterUPCChange ( strLuaDEID ) 
    local nRet, strRetInfo
 
    -- 获取UPC
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "UPC","S_ITEM_CODE","F_ACC_P_QTY", "F_QTY", "TaskFinish") 
    if ( nRet ~= 0 )  then 
        lua.Stop( strLuaDEID, "获取当前编辑属性失败! "..strRetInfo ) 
        return
    end 
    local obj_attrs = json.decode( strRetInfo ) 
    local upc = lua.Get_StrAttrValue( obj_attrs[1].value )  
    local item_code = lua.Get_StrAttrValue( obj_attrs[2].value )  
    local acc_p_qty = lua.Get_NumAttrValue( obj_attrs[3].value )  
    local qty = lua.Get_NumAttrValue( obj_attrs[4].value )  
    local task_finish = lua.Get_NumAttrValue( obj_attrs[5].value )      -- 1 表示任务强制完成
    local str_prompt = "请扫商品编码..."
    local qty_input_enable = false  -- 分拣数量输入框是否可以输入
 
    if ( upc == '' ) then return end
 
    local runtime_parameter
    nRet, runtime_parameter = m3.GetRuntimeParam(strLuaDEID)
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetRuntimeParam失败! "..runtime_parameter ) end
    -- 获取【组盘输入】面板的参数
    local parameter
    nRet, parameter = m3.GetRuntimePanel_InputParamter( strLuaDEID, runtime_parameter.panel, "出库分拣" )
    if ( nRet == 1 ) then 
        mobox.setInfo( strLuaDEID, "没有定义'出库分拣'面板参数!")
        return 
    end
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, parameter ) 
        return
    end 
    if ( parameter == nil ) then return end
 
    -- V3.0
    if ( acc_p_qty == qty or task_finish == 1 ) then
        -- 扫码进入的应该是拣货箱编码
        if ( upc ~= parameter.pick_box_code ) then
            -- 扫码的拣货箱编码不正确
            str_prompt = "请扫拣货箱编码..."
            mobox.setInfo( strLuaDEID, "扫码绑定的拣货箱编码不正确!")
            goto set_dlg_attr    
        else
            -- 分拣任务完成
            local id = parameter.id             -- 当前点中的入库任务标识
            local dc_no = parameter.dc_no       -- 当前点中的入库任务所属配盘号
            if ( dc_no == nil or dc_no == "") then
                mobox.setInfo( strLuaDEID, "'出库分拣'面板必须有配盘号参数!")
                return         
            end
        
            -- 设置【配盘明细】状态 = 2/PickingOK(完成分拣)
            local strCondition = "S_ID = '"..id.."'"
            local strUpdateSql = "N_B_STATE = "..DC_DETAIL_STATE.PickingOK..", F_ACC_P_QTY = "..acc_p_qty
            nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR_Detail", strCondition, strUpdateSql )
            if ( nRet ~= 0 ) then  
                lua.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo )
                return
            end  
        
            -- 拣出的货品和拣料箱进行绑定,创建 Picking_CNTR_Detail
            local pc_detail_data
            if ( parameter.pick_box_code ~= '' and parameter.pick_box_code ~= nil and acc_p_qty > 0 ) then
                nRet, pc_detail_data = wms_out.Creat_Picking_CNTR_Detail( strLuaDEID, id, acc_p_qty, parameter.pick_box_code )
                if ( nRet ~= 0 ) then 
                    lua.Stop( strLuaDEID, '创建拣料箱CG_Detail时失败!'..pc_detail_data ) 
                    return
                end          
            end
        
            local action 
            nRet, action = prj_base.Distribution_CNTR_PostProcess( strLuaDEID, parameter )
            if ( nRet ~= 0 ) then
                lua.Stop( strLuaDEID, action )
                return
            end
            
            nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
            if ( nRet ~= 0 ) then 
                lua.Stop( strLuaDEID, "setAction失败! "..strRetInfo..' action = '..strAction ) 
                return
            end 
            return         
        end
 
    else
        -- 通过条码找到物料编码
        local sku_upc
        nRet, sku_upc = m3.GetDataObjectByKey(strLuaDEID, "SKU_UPC", "S_UPC_CODE", upc)
 
        if (nRet ~= 0 ) then 
            if ( nRet == 1 ) then
                mobox.setInfo( strLuaDEID, "条码'"..upc.."'没有对应的货品,请检查物料条码对照表!")
                goto set_dlg_attr
            end
            lua.Stop( strLuaDEID, "获取【SKU_UPC】信息失败! " .. sku_upc ) 
            return
        end
 
        -- 判断扫码的货品是否是目前的入库任务
        if ( item_code ~= sku_upc.item_code ) then
            mobox.setInfo( strLuaDEID, "条码'"..upc.."'对应的货品编码='"..sku_upc.item_code.."不是当前入库任务中的货物!")
            goto set_dlg_attr    
        end
        acc_p_qty = acc_p_qty + 1
        qty_input_enable = true
        if ( qty == acc_p_qty ) then
            str_prompt = "请扫拣货箱编码..."
        end
    end
 
    ::set_dlg_attr::
    local action = 
    {
        {
            action_type = "set_panel_dlg_attr",
            value = {
                    panel_name = "出库分拣",
                    attrs = {
                                {
                                    attr = "F_ACC_P_QTY",
                                    value = acc_p_qty,
                                    enable = qty_input_enable
                                },
                                {
                                    attr = "UPC",
                                    value = "",
                                    prompt = str_prompt
                                }, 
                                {
                                    attr = "Prompt",
                                    value = str_prompt
                                }                                                              
                            }
                    }
             
        }
    }
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action)  )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, "setAction失败! "..strRetInfo )
        return
    end 
end