1
Jianw
2025-07-09 f6f5e6b632d6649386a380558d84003f3de7ec6c
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
--[[
   编码: AMS-102-02
   名称: 
   作者:
   日期:2025-05-21
 
   函数: Clickafter
   功能:
 
   更改记录:
 
--]]
 
json  = require ("json")
mobox = require ("OILua_JavelinExt")
m3 = require ("oi_base_mobox")
 
function Clickafter( strLuaDEID )
    local nRet,strRetInfo1,strRetInfo2
    --获取PDA参数
    nRet,strRetInfo1 = mobox.getCurEditDataObjAttr(strLuaDEID,"S_CODE")
    if(nRet ~=0) then lua.Error(strLuaDEID,debug.getinfo(1), "调用方法GetSysDataJson出错") end
    
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo1', strRetInfo1)
    
    local obj_attrs = json.decode(strRetInfo1)
    
    local serial_no = obj_attrs[1].value
    if (serial_no == nil or serial_no == '') then return end
    
    
    --查询出库单号为空的信息
    local label_attrs, strCondition
    local strCondition = "COALESCE(LTRIM(RTRIM(S_CNTR_CODE)), '') + COALESCE(LTRIM(RTRIM(S_ITEM_CODE)), '') = '" .. serial_no .. "'" .." AND COALESCE(S_NO, '') = ''"  -- 检查出库单号是否为空
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strCondition', strCondition)
    
    
    nRet, label_attrs = m3.GetDataObjByCondition(strLuaDEID,"Outbound_Request",strCondition)
    -- if (nRet ~= 0) then 
    --   lua.Error(strLuaDEID, debug.getinfo(1), label_attrs) 
    -- end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'label_attrs', label_attrs)
    
    
    if(nRet == 0) then
      -- 存在记录,提示已下发出库需求
      mobox.setInfo(strLuaDEID,"该料箱"..label_attrs.cntr_code.."中的物料"..label_attrs.item_code.."已下发出库需求,请勿重复下发")
      --return 
      goto continue 
      
    elseif(nRet ~=0 ) then
        local header = 'AM'..os.date("%y%m%d")..'-'
        local nRet,no = mobox.getSerialNumber("出库需求",header,4)
        if(nRet ~= 0)then
            table.insert(err,"申请出库需求单号失败:"..order_no)
            return
        end
          -- 不存在记录,创建出库需求
        local new_Outbound = m3.AllocObject(strLuaDEID,"Outbound_Request")
       
        local nRet,input_paramter = m3.GetSysInputParameter(strLuaDEID)
     
        
        lua.Debug(strLuaDEID, debug.getinfo(1), 'input_paramter', input_paramter)
 
        
        -- local ss = json.decode(stt)
        -- local attrs = ss.attrs
        -- local parameter = m3.KeyValueAttrsToObjAttr(attrs)
        -- local paramter = json.decode(input_paramter)
        
        local attrs = input_paramter.attrs
        lua.Debug(strLuaDEID, debug.getinfo(1), 'attrs', attrs)
        local parameter = m3.KeyValueAttrsToObjAttr(attrs)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'parameter',parameter)
        
        
        local label_attrs1
        local item_code = parameter.S_ITEM_CODE
        lua.Debug(strLuaDEID,debug.getinfo(1),'item_code',item_code)
        local strCondition1 = "S_ITEM_CODE = '"..item_code.."'"
        nRet,label_attrs1 = m3.GetDataObjByCondition(strLuaDEID,"SKU",strCondition1)
        lua.Debug(strLuaDEID,debug.getinfo(1),'label_attrs1',label_attrs1)
        if(nRet ~= 0) then
            mobox.setInfo(strLuaDEID,"获取库区失败!"..label_attrs1)
            return 
        end
 
        new_Outbound.oo_no  = no
        new_Outbound.loc_code = lua.Get_StrAttrValue(parameter.S_LOC_CODE)
        new_Outbound.cntr_code = lua.Get_StrAttrValue(parameter.S_CNTR_CODE)
        new_Outbound.item_code = lua.Get_StrAttrValue(parameter.S_ITEM_CODE)
        new_Outbound.item_name = lua.Get_StrAttrValue(parameter.S_ITEM_NAME)
        new_Outbound.area_code = lua.Get_StrAttrValue(label_attrs1.udf01)
        new_Outbound.qty = lua.Get_StrAttrValue(parameter.F_QTY)
        
        lua.Debug(strLuaDEID, debug.getinfo(1), 'new_Outbound', new_Outbound)
        
        -- nRet, strRetInfo = m3.CreateDataObject(strLuaDEID, "Outbound_Request", new_Outbound)
        nRet, strRetInfo2 = m3.CreateDataObj(strLuaDEID, new_Outbound)
        lua.Debug(strLuaDEID, debug.getinfo(1), 'nRet', nRet)
       
        if(nRet == 0) then
          mobox.setInfo(strLuaDEID, "出库需求创建成功!")
          goto continue 
        elseif(nRet ~= 0) then
          mobox.setInfo(strLuaDEID, debug.getinfo(1), "创建出库需求失败: "..tostring(strRetInfo2))
          goto continue 
        end
        if(nRet > 1) then
          lua.Error(strLuaDEID, debug.getinfo(1), "GetDataByCondition失败: "..label_attrs) 
        end
    end
    
    -- --校验出库需求查询中业务状态是否再为0,如再为0,提示已下发出库需求(多余)
    -- local label_attrs1,strCondition1
    -- local strCondition1 =  "COALESCE(LTRIM(RTRIM(S_CNTR_CODE)), '') + COALESCE(LTRIM(RTRIM(S_ITEM_CODE)), '') = '" .. serial_no .. "'".." AND COALESCE(N_B_STATE,'') = '0'"    
    -- lua.Debug(strLuaDEID,debug.getinfo(1),"strCondition",strCondition)
 
    -- nRet, label_attrs1 = m3.GetDataObjByCondition(strLuaDEID,"Outbound_Request",strCondition1)
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'label_attrs1', label_attrs1)
 
    -- if(nRet == 0) then
    --     -- 存在记录,提示已下发出库需求
    --     mobox.setInfo(strLuaDEID,"该料箱"..label_attrs1.cntr_code.."中的物料"..label_attrs1.item_code.."已发出库需求,请勿重复下发")
    -- end
    
    --清除页面数据
    ::continue::
    local action_array = {}
    action_array[1] = {
        action_type = "set_dlg_attr",
        value = {
            {attr = "S_CODE", value = "", enable = true},
            {attr = "S_LOC_CODE", value = ""},
            {attr = "S_CNTR_CODE", value = ""},
            {attr = "S_ITEM_CODE", value = ""},
            {attr = "S_ITEM_NAME", value = ""},
            {attr = "F_QTY", value = ""}
        }
    }
    local nRet1, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action_array)  )
    if ( nRet1 ~= 0 ) then 
        mobox.setInfo(strLuaDEID, "清空页面失败! " .. strRetInfo)
        return
    end
    
    -- local action = {
    --     {
    --         action_type = "refresh",
    --         value = ""
    --     }
    -- }
    -- local nRetAction, strRetInfo8 = mobox.setAction(strLuaDEID, lua.table2str(action))
    -- if nRetAction ~= 0 then
    --     lua.Error(strLuaDEID, debug.getinfo(1), 'setAction错误: ' .. strRetInfo8)
    -- end
    
end