--[[
|
编码: 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
|