1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
169
170
171
172
173
174
175
176
177
--[[
   编码: JX-24-16
   名称: 出库单-拣料箱绑定界面-确定
   作者:
    日期:2025-1-29
 
   函数: main
   功能:
        -- 创建出库波次,把拣货箱绑定到 出库单
        
   更改记录:
        V2.0 HAN 20241024
            参数改成从     m3.GetSysInputParameter( strLuaDEID ) 获取
            一个出库单也形成出库波次
        V3.0 HAN 20241026
            触发一个后台 WFP 进行配盘操作
--]]
wms_base = require ("wms_base")
 
function main( strLuaDEID )
    local nRet, strRetInfo
    local parameter
    nRet,  parameter = m3.GetSysInputParameter( strLuaDEID ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "m3.GetSysInputParameter 失败! "..parameter ) end 
 
    lua.Debug( strLuaDEID, debug.getinfo(1), "parameter", parameter )
    
    local total_qty = 0                         -- 货品种类
    local ipa_item_list = {}                    -- 预分配库存时用到
    local sum_detail_list = parameter.o_detail_list
    local bWave = false
    local compose = parameter.wave_compose
    local wh_code = parameter.wh_code
    local area_code = parameter.area_code
    local station = parameter.station
    local exit_loc = parameter.exit_loc
    local login = parameter.login
    local user_name = parameter.user_name
    local nCount = #compose
 
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "PickingBoxCode", "PickingBoxNum" )
    local input_value = json.decode( strRetInfo ) 
    local picking_box_codes = lua.Get_StrAttrValue( input_value[1].value )
    if ( picking_box_codes == '' ) then
        lua.Stop( strLuaDEID, "必须绑定拣料箱!")
        return
    end
    -- 拣料箱数量
    local picking_box_num = lua.Get_NumAttrValue( input_value[2].value )
    if ( picking_box_num <= 0 ) then
        lua.Stop( strLuaDEID, "拣料箱数量不合法!")
        return
    end
 
    local pick_box_code_array = lua.split( picking_box_codes, ";" )
    if ( #pick_box_code_array ~=  picking_box_num ) then
        lua.Stop( strLuaDEID, "绑定的拣料箱数量必须="..picking_box_num)
        return
    end
 
    -- 【step3】 如果是波次出库,系统生成出库波次对象(需要用波次号区锁定容器)
    local strUpdateSql
    local oo_no_set = {}
    local wave_detail
    local wave
 
    -- 创建出库波次
    wave = m3.AllocObject(strLuaDEID,"Outbound_Wave")
    wave.wh_code = wh_code
    wave.area_code = area_code
    wave.station = station
    wave.operator_name = user_name
    wave.operator = login
    wave.good_type_num = #sum_detail_list
    wave.total_qty = parameter.total_qty
    wave.picking_box_num = parameter.picking_box_num
 
    nRet, wave = m3.CreateDataObj( strLuaDEID, wave )
    if ( nRet ~= 0 ) then 
        lua.Error( strLuaDEID, debug.getinfo(1), '创建【出库波次】对象失败!'..wave ) 
    end      
 
    -- 创建出库波次组成
    local nCurCodeIndex = 1     -- 拣料箱编码游标
    local pick_box_code
    local m
    local pickbox_index = 1
    -- compose 是组成波次的出库单的一些基础信息
    -- nCount 出库单数量,创建波次组成
    for n = 1, nCount do
        table.insert( oo_no_set, compose[n].oo_no )
 
        local ow_compose = m3.AllocObject(strLuaDEID,"OW_Compose")
        ow_compose.oo_no = compose[n].oo_no
        ow_compose.wave_no = wave.wave_no
        nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, ow_compose )
        if ( nRet ~= 0 ) then 
            lua.Error( strLuaDEID, debug.getinfo(1), '创建【出库波次组成】对象失败!'..strRetInfo ) 
        end    
 
        -- 获取和该出库单进行绑定的拣料箱编码
        pick_box_code = ''
        for m = 1, compose[n].pick_box_num do
            if (pick_box_code ~= '') then
                pick_box_code = pick_box_code..";"
            end
            pick_box_code = pick_box_code..pick_box_code_array[pickbox_index]
            pickbox_index = pickbox_index + 1
        end
        strUpdateSql = "S_WAVE_NO = '"..wave.wave_no.."', S_STATION_NO = '"..wave.station.."', S_OPERATOR_NAME = '"..wave.operator_name.."',"
        -- 更新【出库单】状态, 并且把拣料箱绑定
        -- N_B_STATE = 1 表示出库单已经配货
        strUpdateSql = strUpdateSql.."S_OPERATOR = '"..wave.operator.."', N_B_STATE = 1, S_PICK_BOX_CODE = '"..pick_box_code.."'"
        strCondition = "S_NO = '"..compose[n].oo_no.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Outbound_Order", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then  
            lua.Error( strLuaDEID, debug.getinfo(1), "更新【出库单】信息失败!"..strRetInfo ) 
        end               
    end
 
    -- 创建出库波次明细
    for n = 1, #sum_detail_list do
        wave_detail = m3.AllocObject(strLuaDEID,"OW_Detail")
        wave_detail.wave_no = wave.wave_no
        wave_detail.row_no = n
        wave_detail.item_code = sum_detail_list[n].item_code
        wave_detail.item_name = sum_detail_list[n].item_name
        wave_detail.qty = sum_detail_list[n].qty
        wave_detail.weight = sum_detail_list[n].weight
        wave_detail.volume = sum_detail_list[n].volume
        nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, wave_detail )
        if ( nRet ~= 0 ) then 
            lua.Error( strLuaDEID, debug.getinfo(1), '创建【出库波次明细】对象失败!'..strRetInfo ) 
        end          
    end
 
    -- 需要清空 拣料箱中的货品明细 CG_Detail
    local in_cntr_code = ''
    for n = 1, #pick_box_code_array do
        in_cntr_code = in_cntr_code.."'"..pick_box_code_array[n].."',"
    end
    in_cntr_code = lua.trim_laster_char( in_cntr_code )  -- 取消最后一个,号
    strCondition = "S_CNTR_CODE IN ("..in_cntr_code..")"
    nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "CG_Detail", strCondition)
    if (nRet ~= 0) then 
        lua.Error( strLuaDEID, debug.getinfo(1), "删除【CG_Detail】失败!"..strRetInfo) 
    end            
 
    local parameter = {
                            station = station,
                            cntr_out_op_def = "货品出库",
                            cntr_back_op_def = "料箱入库",                             
                            login = strUserLogin,
                            user_name = strUserName,
                            wave_no = wave.wave_no              -- 出库波次号
                    }  
 
    -- 在后台排队线程进行自动配盘处理
    nRet, strRetInfo = mobox.addBackendScriptProc( "Outbound_Wave", "出库波次自动配盘", lua.table2str( parameter ) )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, strRetInfo ) 
        return
    end
    local action = {
        {
            action_type = "close_dlg",
            value = ""
        },
        {
            action_type = "refresh",
            value = ""
        }
    }
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end        
 
end