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
--[[
   编码: JX-24-23
   名称: 
   作者:
   日期:2025-03-28
 
   函数: Refresh
   功能:
 
   更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
function Refresh(strLuaDEID)
    local nRet, obj
    local total_weight = 0  
    local total_volume = 0 
 
    -- 获取传入的数据包
    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_OO_NO = '" .. obj_attrs.S_NO .. "'"
        nRet, inbound_order = m3.QueryDataObject(strLuaDEID, "Outbound_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.."' "
            local strCondition = "S_OO_NO = '" .. obj_attrs.S_NO .. "' AND S_ITEM_CODE = '" .. item_code.. "'" 
            
            local nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "Outbound_Detail", strCondition, strUpdateSql)
            if (nRet ~= 0) then
                lua.Error(strLuaDEID, "更新 Inbound_Detail 表失败: " .. strRetInfo)
            end
            
            -- 体积和重量的累加,按每个商品的数量和体积、重量进行计算
            total_weight = total_weight + (material.volume  * qty)  -- 单个商品的重量 * 数量
            total_volume = total_volume + (material.weight * qty)  -- 单个商品的体积 * 数量
            
            lua.Debug(strLuaDEID, debug.getinfo(1), "total_volume", total_volume)
            lua.Debug(strLuaDEID, debug.getinfo(1), "total_weight", total_weight)
            
 
        end
        
    end
 
end