fy36
2025-05-14 a37aca60ff9914b0abb710f04118b22420f4f398
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
--[[
    编码: WMS-01-01#1
    名称: 容器-创建前
    作者:HAN  
    日期:2025-01-29
 
    级别: 项目
    
    函数: BeforeDataObjCreate
 
    功能:
        -- 根据容器类型生成容器编码  FB-0001
 
    来源项目: 巨星料箱库
             适合带料格的料箱创建
             
    更改记录:
 
--]]
 
wms_base = require( "wms_base" )
 
function BeforeDataObjCreate ( strLuaDEID ) 
    local   nRet, strRetInfo
 
    -- 改进测试
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_CODE", "S_SPEC","S_TYPE" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local code = lua.Get_StrAttrValue( obj_attrs[1].value )
    local cntr_spec = lua.Get_StrAttrValue( obj_attrs[2].value )
    local cntr_type = lua.Get_StrAttrValue( obj_attrs[3].value )
 
    -- 生成【容器】编码
    if ( code == '' ) then
        local strHeader
        if ( cntr_type == "Cell_Box" ) then
            strHeader = 'FB-'
        elseif ( cntr_type == "Picking_Box" ) then
            strHeader = 'ZB-'
        elseif ( cntr_type == "Pallet") then
            strHeader = 'TP-'
        else
            strHeader = 'C-'
        end
        nRet, code = mobox.getSerialNumber( "容器", strHeader, 4 )  
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),'申请【容器】编码失败!'..code ) end            
    end
 
    -- 获取最大料格数
    local max_cell_num = 0
    if ( cntr_type == "Cell_Box" ) then
        if ( cntr_spec == 'A') then
            max_cell_num = 1
        elseif ( cntr_spec == 'B') then
            max_cell_num = 2         
        elseif ( cntr_spec == 'C') then
            max_cell_num = 3       
        elseif ( cntr_spec == 'D') then
            max_cell_num = 4        
        elseif ( cntr_spec == 'E') then 
            max_cell_num = 6
        end   
    end
 
    -- 设置信息
    local   attr_value = {}
    attr_value[1] = { attr = "S_CODE", value = code }
    attr_value[2] = { attr = "N_MAX_CELL_NUM", value = max_cell_num }
    attr_value[3] = { attr = "N_EMPTY_CELL_NUM", value = max_cell_num }
 
    nRet, strRetInfo = mobox.setCurEditDataObjAttr( strLuaDEID, lua.table2str(attr_value) ) 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"设置【容器】信息失败!  "..strRetInfo ) end       
end