Jianw
2025-05-13 3b39fe3810c3ee2ec9ec97236c1769c5c85e062c
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
--[[
    编码: WMS-22-04
    名称: 发货单-定版后
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: AfterStateChange
 
    功能:
        -- 删除系统中和发货单号相关的最大行号记录 
        -- 【发货单明细】设置为定版
        -- 如果 C_AUTO_SORTING = Y 触发【发货单】的{创建分拣单}事件
    更改记录:
        V7.0 -- 如果C_AUTO_SORTING = Y 触发【发货单】的{创建分拣单}事件
 
--]]
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
function AfterStateChange ( strLuaDEID ) 
    local   nRet, strRetInfo
 
    -- 获取 S_NO
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_NO","S_STATE", "C_AUTO_SORTING" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
 
    local obj_attrs = json.decode( strRetInfo ) 
    local shipping_no = obj_attrs[1].value           -- 发货单编号
    local state = obj_attrs[2].value                 -- 发货单状态
    local auto_sorting = obj_attrs[3].value          -- 系统自动生成分拣单
 
    if ( shipping_no == '') then
        lua.Warning( strLuaDEID, debug.getinfo(1), "发货单编号为空! " )
        return
    end
 
    -- 清除 shipping_no 的最大行号记录
    nRet, strRetInfo = mobox.removeSerialNumber( "行号", shipping_no )
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "removeSerialNumber() 失败! "..strRetInfo ) end 
 
    -- 设置【发货单明细】的状态=定版
    local strCondition = "S_SHIPPING_NO = '"..shipping_no.."'"
    nRet, strRetInfo = mobox.setDataObjStateByCondition( strLuaDEID, "Shipping_Detail", strCondition, state )
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "setDataObjStateByCondition() 失败! "..strRetInfo ) end 
 
    -- V7.0
    -- 如果需要系统自动生成分拣单
    if ( auto_sorting == 'Y') then
        -- 触发【发货单】的{创建分拣单}脚本
        --获取当前编辑的数据对象标识
        local strClsID, strObjID
        nRet, strClsID, strObjID = mobox.getCurEditDataObjID( strLuaDEID )
        if ( nRet ~=0 ) then
            lua.Error( strLuaDEID, debug.getinfo(1), "获取当前对象标识失败!" )
        end
        nRet, strRetInfo = mobox.triggerClsEvent( strLuaDEID, strClsID, strObjID, "创建分拣单" )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "执行【发货单】创建分拣单脚本失败!"..strRetInfo ) end
    end
end