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
--[[
    编码: JX-20-28
    名称: 入库单刷新
    作者:KUN 
    日期:2025-3-14
 
    级别:项目
    
    函数: Refresh
    功能: 刷新入库单明细的体积和重量
 
    更改记录:
--]]
 
jx_base = require("jx_base")
wms_count = require("wms_count")
 
function Refresh(strLuaDEID)
    local nRet, obj
 
    -- 获取传入的数据包
    nRet, obj = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        lua.Error(strLuaDEID, debug.getinfo(1), "无法获取数据包!" .. obj)
        return
    end
    lua.Debug(strLuaDEID, debug.getinfo(1), "obj", obj)
 
    local nCount = #obj
    if (nCount == 0) then
        return
    end
 
    local qty, volume, weight
    -- 遍历每条入库单
    for i = 1, #obj do
        local item = obj[i]
        local obj_attrs = m3.KeyValueAttrsToObjAttr(item.attrs)
 
        -- 根据入库单号查询入库单明细
        local strCondition = "S_IO_NO = '" .. obj_attrs.S_NO .. "'"
        nRet, inbound_order = m3.QueryDataObject(strLuaDEID, "Inbound_Detail", strCondition)
        if (nRet ~= 0 or inbound_order == '') then
            lua.Error(strLuaDEID, debug.getinfo(1), '无法查询入库单明细!' .. inbound_order)
        end
 
        -- 遍历每条入库单明细
        for n = 1, #inbound_order do
            local inbound_detail = inbound_order[n]
            local inbound_attrs = m3.KeyValueAttrsToObjAttr(inbound_detail.attrs)
 
            -- 获取物料编码
            local item_code = inbound_attrs.S_ITEM_CODE
            if (item_code == nil or item_code == '') then
                lua.Error(strLuaDEID, debug.getinfo(1), "物料编码为空!")
            end
 
            -- 根据物料编码查询物料表
            local strCondition = "S_ITEM_CODE = '" .. item_code .. "'"
            nRet, material = m3.GetDataObjByCondition(strLuaDEID, "Material", strCondition)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, debug.getinfo(1), "获取物料信息失败,商品编码:" .. item.inco)
            end
 
            -- 计算总体积和总重量
            qty = tonumber(inbound_attrs.F_QTY) 
            volume = material.volume
            weight = material.weight
            
            
            local strUpdateSql = "F_WEIGHT = '"..weight.."', F_VOLUME = '"..volume.."', S_CELL_TYPE = '"..material.cell_type.."' "
            local strCondition = "S_IO_NO = '" .. obj_attrs.S_NO .. "' AND S_ITEM_CODE = '" .. item_code.. "'" 
            
            local nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Inbound_Detail", strCondition, strUpdateSql)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, "更新 Inbound_Detail 表失败: " .. strRetInfo)
            end
 
        end
    end
    mobox.setInfo(strLuaDEID, "更新成功!")
 
end