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
94
95
96
97
98
99
100
101
102
103
104
105
--[[
    编码: WMS-13-07
    名称: 预收货通知-新增界面选择来源单号后
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: AeforeSelectBSNo
 
    功能:
        1)根据选中的数据对象,比如业务来源是“采购订单”,选中的就是采购订单,该脚本把选中的采购订单中的采购明细加入ASN明细
 
    更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
-- 获取采购订单明细,返回插入ROW数据
function GetPurchaseOrderDetail( strLuaDEID, strPONo )
    local strCondition, nRet, strRetInfo
    local strOrder = 'N_ROW_NO'
 
    strCondition = "S_PO_NO = '"..strPONo.."'"
    nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "Purchase_Detail",strCondition, strOrder, "S_ITEM_CODE", "S_ITEM_NAME","S_ITEM_SPEC","S_UOM","F_QTY" )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【Purchase_Detail】属性失败! "..strRetInfo ) end
 
    local retObjs = json.decode( strRetInfo )
    local nObjs =  #retObjs    
    local n
    local attrs
    local strInsertRow = ''
 
    for n = 1, nObjs do
        attrs = retObjs[n].attrs
        strInsertRow = strInsertRow..'{"attrs":'..lua.table2str(attrs)..'},'
    end
    if ( strInsertRow ~= '') then 
        return '['..lua.trim_laster_char(strInsertRow)..']'
    end
    return ''
end
 
function AeforeSelectBSNo ( strLuaDEID )
    local nRet, strRetInfo
    local strBSType = ''
    local strClsID = ''
 
    -- 获取界面上输入的 业务类型
    nRet, strBSType = m3.GetSysCurEditDataOneAttr( strLuaDEID, "S_BS_TYPE" ) 
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "GetSysCurEditDataOneAttr失败! "..strBSType ) end
    -- 如果业务类型为空,不能做查询
    if ( strBSType == '') then lua.Error( strLuaDEID, debug.getinfo(1), "请先选来源类型!") end
    if ( strBSType == '采购订单') then
        strClsID = 'Purchase_Order'
    else
        lua.Error( strLuaDEID, debug.getinfo(1), "不合法的来源类型!")
    end
 
    local strDataJson
    -- 获取选择面板中选中的数据
    nRet, strDataJson = mobox.getCurEditDataPacket( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取Lua数据包!") end
    if ( strDataJson == '' ) then lua.Error( strLuaDEID, debug.getinfo(1), "接口数据包为空!") end
 
    -- 解析输入的Json格式文本
    local obj, success
    success, obj = pcall( json.decode, strDataJson)
    if ( success == false ) then lua.Error( strLuaDEID, debug.getinfo(1), "非法的JSON格式!"..obj ) end 
 
    -- 因为是单选 格式:{"id":"","attr1":"",...}
    -- 获取返回的数据对象属性
    local strBSNo = ''          -- 业务来源单号
    local strSpplierNo = ''     -- 供应商编码
    local strSpplierName = ''   -- 供应商名称
    local bSetDlgAttr = false
    local strInsertRow = ''
    if ( strBSType == '采购订单') then
        strBSNo = obj.S_NO
        strSpplierNo = obj.S_SUPPLIER_NO
        strSpplierName = obj.S_SUPPLIER_NAME
        if (strBSNo == '' or strBSNo == nil ) then return end
        if (strSpplierNo == nil ) then strSpplierNo = '' end
        if (strSpplierName == nil ) then strSpplierName = '' end
        bSetDlgAttr = true
        -- 获取采购订单明细
        strInsertRow = GetPurchaseOrderDetail( strLuaDEID, strBSNo )
    end
 
    if (bSetDlgAttr) then 
        local setAttr = '[{"attr":"S_BS_NO","value":"'..strBSNo..'"},{"attr":"S_SUPPLIER_NO","value":"'..strSpplierNo..'"},'
        setAttr = setAttr..'{"attr":"S_SUPPLIER_NAME","value":"'..strSpplierName..'"}]'
 
        local strAction = '[{"action_type":"set_dlg_attr","value":'..setAttr..'}'
        if ( strInsertRow ~= '' ) then 
            strAction = strAction..',{"action_type":"clear_rows","value":""},{"action_type":"insert_bottom_row","value":'..strInsertRow..'}'
        end
        strAction = strAction..']'
        nRet, strRetInfo = mobox.setAction( strLuaDEID, strAction  )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end 
    end
end