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
--[[
    编码: WMS-15-01
    名称: 收货单-创建前
    作者:HAN  
    日期:2025-1-29
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: BeforeDataObjCreate
 
    功能:
        1)生成到货单编码 S_NO 格式:RO2301-00001
        2) 如果创建的时候没有赋值 S_FACTORY 系统获取操作者的所在单位
 
    更改记录:
]]
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
function BeforeDataObjCreate ( strLuaDEID ) 
    local   nRet, strRetInfo
 
    -- V7.0
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_FACTORY", "S_NO" ) 
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
    local obj_attrs = json.decode( strRetInfo ) 
    local factory = lua.Get_StrAttrValue( obj_attrs[1].value )
    local strCode = lua.Get_StrAttrValue( obj_attrs[2].value )  
 
    -- 如果工厂标识为空,系统自动赋值当前操作者的单位为 S_FACTORY
    if ( factory == '') then
        local strUserLogin, strUserName
        nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end
        -- 获取当前操作人员的单位编码,作为工厂标识
        nRet, strRetInfo = mobox.getUserSectionUnit( strUserLogin )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员所属单位失败! "..strRetInfo ) end
        local orgInfo = json.decode( strRetInfo ) 
        factory = orgInfo.company_code
    end
 
    -- 生成发货单编码
    if  ( strCode == '' ) then
        local strHeader = 'RO'..os.date("%y%m")..'-'
        nRet,strCode = mobox.getSerialNumber( "收货单", strHeader, 5 )  
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),  '申请收货单编码失败!'..strCode ) end
    end
     
    -- 设置信息
    local   attr_value = {}
    attr_value[1] = lua.KeyValueObj( "S_FACTORY", factory )
    attr_value[2] = lua.KeyValueObj( "S_NO", strCode )
    nRet, strRetInfo = mobox.setCurEditDataObjAttr( strLuaDEID, lua.table2str(attr_value) ) 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【收货单】信息失败!  "..strRetInfo ) end   
end