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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--[[
    编码: WMS-29-10
    名称: 盘点容器货品明细-确定
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: ClickOK
 
    功能:
          -- 创建【盘点差异表】Count_Diff
          -- 修改【计划盘点容器】CP_Count_Container 的盘点人信息和状态
    更改记录:
 
--]]
 
wms_base = require( "wms_base" )
 
function ClickOK ( strLuaDEID )
    local nRet, strRetInfo
    local attrs
 
    -- step1  获取5601码盘界面中表头界面的输入参数(容器编号/托盘号)
    nRet, attrs = m3.GetSysInputParameter( strLuaDEID ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前输入面板里的属性失败! "..attrs ) end 
    local input_attr = m3.KeyValueAttrsToObjAttr(attrs)
    local cntr_code = input_attr.S_CNTR_CODE
    local count_no = input_attr.S_COUNT_NO
    if (cntr_code == nil or cntr_code == '') then lua.Error( strLuaDEID, debug.getinfo(1), "主界面中容器编码不能为空!" ) end
    if (count_no == nil or count_no == '') then lua.Error( strLuaDEID, debug.getinfo(1), "主界面中盘点单号不能为空!" ) end
 
    -- *** 这里要注意获取盘点计划单,需要和PDA的界面一起检查一下
    
    local strUserLogin, strUserName
    nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end
 
    local strDataJson
    -- step2  获取"盘点货品"中的数据对象,这些数据保存在 DataJson中 格式如下:
    --   [{"page_name":"", ext_data:{},"item_list":[{"id":"","attrs":[{"attr":"x1","value":"xx"},...]},..]},...]
    local page
    nRet, page = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取数据包!"..obj ) end
    local item_list = page[1].item_list
    local n
    local qty, check_qty
    local item = m3.KeyValueAttrsToObjAttr(item_list[1].attrs)
    local count_cg_detail
    -- 判断是否存在必须输入的属性
    if ( item.F_QTY == nil ) then lua.Error( strLuaDEID, debug.getinfo(1), "盘点输入页面必须有F_QTY属性!" ) end
    if ( item.F_ACT_QTY == nil ) then lua.Error( strLuaDEID, debug.getinfo(1), "盘点输入页面必须有F_ACT_QTY属性!" ) end
 
    -- step3 创建【盘点差异表】    
    local curTime = os.date("%Y-%m-%d %H:%M:%S")
    for n = 1, #item_list do
        item = m3.KeyValueAttrsToObjAttr(item_list[n].attrs)
        qty = lua.StrToNumber( item.F_QTY )
        check_qty = lua.StrToNumber( item.F_ACT_QTY )
        if ( qty ~= check_qty ) then
            -- 有差异,创建【盘点差异表】
            -- 生成差异表的时候需要完整的 【Count_CG_Detail】
            nRet, count_cg_detail = m3.GetDataObject( strLuaDEID, "Count_CG_Detail", item_list[n].id ) 
            if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), count_cg_detail ) end 
 
            local count_diff = m3.AllocObject(strLuaDEID,"Count_Diff")
            count_diff.cntr_code = cntr_code
            count_diff.count_no = count_no
            count_diff.qty = qty
            count_diff.act_qty = check_qty
            count_diff.cell_no = count_cg_detail.cell_no
            count_diff.item_code = count_cg_detail.item_code
            count_diff.item_name = count_cg_detail.item_name                                    
            count_diff.item_state = count_cg_detail.item_state   
            count_diff.batch_no = count_cg_detail.batch_no   
            count_diff.serial_no = count_cg_detail.serial_no
            
            count_diff.checker = strUserName
            count_diff.checker_id = strUserLogin
            count_diff.t_check = curTime
 
            nRet, cg_detail = m3.CreateDataObj( strLuaDEID, count_diff )
            if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), 'mobox 创建【盘点差异表】对象失败!'..cg_detail ) end 
        end
    end
 
    -- step4 更新【计划盘点容器】中的盘点状态
    local strCondition = "S_COUNT_NO = '"..count_no.."' AND S_CNTR_CODE = '"..cntr_code.."'"
    -- N_B_STATE = 3 完成
    local strSetAttr = "N_B_STATE = 3, S_CHECKER = '"..strUserName.."', S_CHECKER_ID = '"..strUserLogin.."', T_CHECK = '"..curTime.."'"
    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "CP_Count_Container", strCondition, strSetAttr )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "updateDataAttrByCondition失败"..strRetInfo ) end       
        
end