fy36
2025-07-01 350eb5ec9163d3ea21416b1525bb80191e958071
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
106
--[[
    编码: WMS-15-06
    名称: 收货单-主从面板-选ASN后
    作者:HAN  
    日期:2025-1-29
 
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: AeforeSelectASN
 
    功能:
        1)选中一个ASN后,把ASN中还可以收货的物料加入收货单明细
    更改记录:
  
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require("oi_base_mobox")
 
-- 获取采购订单明细,返回插入ROW数据
function GetASNDetail( strLuaDEID, strAsnNo )
    local strCondition, nRet, strRetInfo
    local strOrder = 'N_ROW_NO'
 
    strCondition = "F_QTY > F_ACC_R_QTY + F_ACC_C_QTY AND S_ASN_NO = '"..strAsnNo.."'"
    nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "ASN_Detail", strCondition, strOrder, "F_QTY", "F_ACC_R_QTY","F_ACC_C_QTY",
                                               "S_ITEM_CODE", "S_ITEM_NAME","S_ITEM_SPEC","S_UOM" )
    if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【预收货单明细】失败! "..strRetInfo ) end
 
    local retObjs = json.decode( strRetInfo )
    local nObjs =  #retObjs    
    local n, nCol, nMaxCol
    local attrs
    local strInsertRow = ''
    local qty, acc_r_qty, acc_c_qty
 
    -- 获取 ASN_Detial 中的属性,设置到 Receipt_Detail
    nMaxCol = #retObjs[1].attrs
    for n = 1, nObjs do
        attrs = retObjs[n].attrs
        -- 判断一下数量
        qty = lua.StrToNumber( attrs[1].value )
        acc_r_qty = lua.StrToNumber( attrs[2].value )
        acc_c_qty = lua.StrToNumber( attrs[3].value )
 
        --组织插入的 Receipt_Detail 数据
        local receipt_detail_attrs = {}
        local nIndex = 1
        for nCol = 4, nMaxCol do
            receipt_detail_attrs[nIndex] = attrs[nCol]
            nIndex = nIndex+1
        end
        -- 数量是 最大可收货数量
        receipt_detail_attrs[nIndex] = lua.KeyValueObj( "F_QTY", qty-acc_r_qty-acc_c_qty )
        strInsertRow = strInsertRow..'{"attrs":'..lua.table2str(receipt_detail_attrs)..'},'
    end
    if ( strInsertRow ~= '') then 
        return '['..lua.trim_laster_char(strInsertRow)..']'
    end
    return ''
end
 
function AeforeSelectASN ( strLuaDEID )
    local nRet, strRetInfo
    local strDataJson
 
    -- step1:获取选择面板中选中的数据
    nRet, strDataJson = mobox.getCurEditDataPacket( strLuaDEID )
    if ( nRet ~=0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "无法获取Lua数据包!") end
    if ( strDataJson == '' ) then return end
 
    -- step2: 解析输入的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 strAsnNo = ''         -- ASN编码
    local strSpplierNo = ''     -- 供应商编码
    local strSpplierName = ''   -- 供应商名称
    local strInsertRow = ''
 
    strAsnNo = obj.S_NO
    strSpplierNo = obj.S_SUPPLIER_NO
    strSpplierName = obj.S_SUPPLIER_NAME
    if (strAsnNo == '' or strAsnNo == nil ) then return end
    if (strSpplierNo == nil ) then strSpplierNo = '' end
    if (strSpplierName == nil ) then strSpplierName = '' end
 
    -- 获取ASN中还可以收货的货品清单
    strInsertRow = GetASNDetail( strLuaDEID, strAsnNo )
 
    -- 设置主从窗口中 主表中的属性
    local setAttr = '[{"attr":"S_ASN_NO","value":"'..strAsnNo..'"},{"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