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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
--[[
    版本:     Version 1.0
    创建日期: 2025-6-10
    创建人:   HAN
 
    功能:
        WMS 库内管理
 
        -- Create_SOO_ByContainer  根据容器号创建一个指定出库作业
 
    更改说明:
 
--]]
 
wms_cntr = require ("wms_container")
wms_wh   = require ("wms_wh")
 
local wms_mang = {_version = "0.1.1"}
 
local function create_so_cntr_detail( strLuaDEID, station, cntr_code, so_no, soc_no, item_code )
    local nRet, strRetInfo
    local obj_attrs, data_objs
    local strCondition = "S_CNTR_CODE = '"..cntr_code.."'"
    local so_cntr_detail
 
    if ( item_code ~= nil and item_code ~= '' ) then
        strCondition = strCondition.." AND S_ITEM_CODE = '"..item_code.."'"
    end
 
    nRet, data_objs = m3.QueryDataObject( strLuaDEID, "INV_Detail", strCondition )
    if ( nRet ~= 0 ) then return 1, "获取【INV_Detail】失败! "..data_objs end
    if ( data_objs == '' ) then return 0 end
 
    for n = 1, #data_objs do
        obj_attrs = m3.KeyValueAttrsToObjAttr(data_objs[n].attrs)
 
        so_cntr_detail = m3.AllocObject(strLuaDEID,"SO_CNTR_Detail")
        so_cntr_detail.soc_no = soc_no
        so_cntr_detail.station = station
        so_cntr_detail.so_no = so_no
        so_cntr_detail.cntr_code = cntr_code
        so_cntr_detail.qty = lua.Get_NumAttrValue( obj_attrs.F_QTY )
        so_cntr_detail.cell_no = obj_attrs.S_CELL_NO
        so_cntr_detail.item_code = obj_attrs.S_ITEM_CODE
        so_cntr_detail.item_name = obj_attrs.S_ITEM_NAME
        so_cntr_detail.item_state = lua.StrToNumber( obj_attrs.N_ITEM_STATE )
        so_cntr_detail.batch_no = obj_attrs.S_BATCH_NO  
        so_cntr_detail.serial_no = obj_attrs.S_SERIAL_NO  
        so_cntr_detail.erp_wh_code = obj_attrs.S_ERP_WH_CODE  
        so_cntr_detail.end_user = obj_attrs.S_END_USER  
        so_cntr_detail.owner = obj_attrs.S_OWNER  
        so_cntr_detail.supplier = obj_attrs.S_SUPPLIER_NO   
        
        so_cntr_detail.uom = obj_attrs.S_UOM        
        so_cntr_detail.ext_attr1 = obj_attrs.S_EXT_ATTR1      
        so_cntr_detail.ext_attr2 = obj_attrs.S_EXT_ATTR2 
        so_cntr_detail.ext_attr3 = obj_attrs.S_EXT_ATTR3 
        so_cntr_detail.ext_attr4 = obj_attrs.S_EXT_ATTR4 
        so_cntr_detail.ext_attr5 = obj_attrs.S_EXT_ATTR5                                                       
 
        nRet, so_cntr_detail = m3.CreateDataObj( strLuaDEID, so_cntr_detail )
        if ( nRet ~= 0 ) then 
            return 1, 'mobox 创建【指定出库容器货品明细】对象失败!'..so_cntr_detail
        end         
    end  
    return 0  
end
 
-- 根据指(so)定出库货品,创建指定出库容器和 指定出库容器明细
local function create_so_cntr_operation( strLuaDEID, station, so_no, cntr_code, to_loc, item_code, source_sys )
    local nRet, strRetInfo
 
    if ( source_sys == nil ) then source_sys = "" end
    -- 获取容器所在的货位
    local from_loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, cntr_code )    
    if  ( from_loc_code == '' ) then return 1, "容器'"..cntr_code.."'无法获取货位!" end
    local from_loc
    nRet, from_loc = wms_wh.GetLocInfo( from_loc_code )
    if ( nRet ~= 0 ) then return 1, '获取货位信息失败! '..from_loc end       
 
    -- 创建 指定出库容器
    local so_cntr = m3.AllocObject(strLuaDEID,"Specify_Outbound_CNTR")
 
    so_cntr.so_no = so_no
    so_cntr.cntr_code = cntr_code
    so_cntr.wh_code = from_loc.wh_code
    so_cntr.area_code = from_loc.area_code
    so_cntr.loc_code = from_loc.code
    so_cntr.to_loc_code = to_loc.code
    so_cntr.station = station
    nRet, so_cntr = m3.CreateDataObj( strLuaDEID, so_cntr )   
    if (nRet ~= 0) then return 1, "创建【盘点单】失败!"..so_cntr end  
    
    nRet, strRetInfo = create_so_cntr_detail( strLuaDEID, station, cntr_code, so_no, so_cntr.soc_no, item_code )
    if ( nRet ~= 0 ) then return nRet, strRetInfo end
 
    local operation = m3.AllocObject(strLuaDEID,"Operation")
    operation.source_sys = source_sys
    operation.start_wh_code = from_loc.wh_code
    operation.start_area_code = from_loc.area_code
    operation.start_loc_code = from_loc.code
 
    operation.end_wh_code = to_loc.wh_code
    operation.end_area_code = to_loc.area_code
    operation.end_loc_code = to_loc.code
    operation.lock_cntr = "N"                                   -- 作业启动时不需要锁容器
    operation.cntr_code = cntr_code
 
    operation.op_type = OPERATION_TYPE.Outbound
    operation.op_def_name = "指定出库"
    operation.bs_type = "Specify_Outbound"
    operation.bs_no = so_no
    nRet, operation = m3.CreateDataObj( strLuaDEID, operation )
    if ( nRet ~= 0 ) then return 2, '创建【作业】失败!'..operation end  
 
    -- 容器加出库锁/2 -- 加内存同时加数据库
    nRet, strRetInfo = wms_cntr.Lock( strLuaDEID, cntr_code, 2, so_no )
    if ( nRet ~= 0 ) then
        return 2, "给容器'"..cntr_code.."'加出库锁失败!"
    end 
 
    return 0
end
 
--[[ 
    根据容器号创建一个指定出库作业
    SOO -- Specify Outbound Operation
    输入参数:
    so_no       -- 指定出库指令号
    cntr_code   -- 容器编码
    to_loc_code -- 出库口货位
    op_def_name -- 作业类型
    source_sys  -- 来源系统
--]]
function wms_mang.Create_SOO_ByContainer( strLuaDEID, station, so_no, cntr_code, to_loc_code, op_def_name, source_sys )
    local nRet, strRetInfo, n
 
    -- step1:输入参数合法性检查
    if ( so_no == nil or so_no == '') then return 1, "so_no 必须有值!" end    
    if ( cntr_code == nil or cntr_code == '') then return 1, "cntr 必须有值!" end
    if ( to_loc_code == nil or to_loc_code == '') then return 1, "loc_code 必须有值!" end
    if ( station == nil or station == '') then return 1, "station 必须有值!" end
    if ( source_sys == nil ) then source_sys = "" end
    -- 判断目标货位是否正确
    local to_loc
    nRet, to_loc = wms_wh.GetLocInfo( to_loc_code )
    if ( nRet ~= 0 ) then return 1, '获取货位信息失败! '..to_loc end   
 
    -- 创建指定出库容器+容器明细+作业
    nRet, strRetInfo = create_so_cntr_operation( strLuaDEID, station, so_no, cntr_code, to_loc, "", source_sys )
    if ( nRet ~= 0 ) then 
        wms.wms_AbortCntrLockTrans( so_no ) 
        return nRet, strRetInfo 
    end   
    
    -- 设置 Specify_Outbound 状态为执行 N_B_STATE = 2 执行中
    strUpdateSql = "N_B_STATE = 2, N_CNTR_TOTAL = 1"
    strCondition = "S_SO_NO = '"..so_no.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Specify_Outbound", strCondition, strUpdateSql )
    if ( nRet ~= 0 ) then  
        wms.wms_AbortCntrLockTrans( so_no ) 
        return 2, "更新【Specify_Outbound】信息失败!"..strRetInfo
    end  
    -- create_so_cntr_operation 有锁容器操作
    wms.wms_CommitCntrLockTrans( so_no ) 
 
 
    return 0
end
 
--[[
    容器从当前锁定的货位移动到新的货位
    注意:这些容器必须已经绑定货位,已经在 INV_Detail 中
--]]
function wms_mang.CNTR_Move( strLuaDEID, cntr_code, to_loc_code, note )
    local nRet, strRetInfo
 
    if lua.StrIsEmpty( cntr_code ) or lua.StrIsEmpty( to_loc_code ) then
        return 1, "wms_mang.CNTR_Move 函数输入参数不合规!"
    end
    if note == nil then note = '' end
 
    -- 得到容器当前货位(担心上传上来的 start_location 和当前容器的绑定货位不一致,还是从 Loc_Container 获取比较保险)
    local cntr_cur_loc = wms_wh.GetLocCodeByCNTR( strLuaDEID, cntr_code )
    if cntr_cur_loc == '' then
        return 1,"容器 '"..cntr_code.."' 没有绑定货位!"
    end
 
    -- 解绑原来的位置
    nRet, strRetInfo = wms_wh.Loc_Container_Unbinding( strLuaDEID, cntr_cur_loc, cntr_code, METHOD_TYPE.System, note )
    if ( nRet ~= 0 ) then 
        return 1, '货位容器绑定失败!'..strRetInfo
    end 
 
    -- 绑定新的货位
    nRet, strRetInfo = wms_wh.Loc_Container_Binding( strLuaDEID, to_loc_code, cntr_code, METHOD_TYPE.System, note )
    if ( nRet ~= 0 ) then 
        return 1, '货位容器绑定失败!'..strRetInfo
    end 
 
    -- 库存量转移
    nRet, strRetInfo = wms_inv.Move( strLuaDEID, cntr_code, cntr_cur_loc, to_loc )
    if ( nRet ~= 0 )  then 
        return 1, "wms_inv.Move 失败! "..strRetInfo
    end     
 
    -- 更新容器中的位置信息
    local strCondition = "S_CODE = '"..cntr_code.."'"       
    local strSetAttr = "S_POSITION = '"..to_loc_code.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container", strCondition, strSetAttr )
    if ( nRet ~= 0 ) then  
        return 2, "更新【容器料格】信息失败!"..strRetInfo 
    end     
    return 0
end
 
return wms_mang