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
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
--[[ 
 编码: JX-API-06
 名称: DeleteOutboundOrder
 作者: kun
 入口函数:main
 功能说明: 
     - 判断出库单状态是否为“新建”
     - 若为新建,删除出库单及其明细
     - 否则提示不可删除
 输入数据格式:
    {
        "Name": "DeleteOutboundOrder",
        "Source": "ERP",
        "Data":
            {
                "S_NO": "CKD001",
                "SourceKey": ""
            }
    }
--]]
 
-- 引入基础模块
json = require("json")
mobox = require("OILua_JavelinExt")
m3 = require("oi_base_mobox")
wms_base = require("wms_base")
 
function DeleteOutboundOrder(strLuaDEID)
    
    m3.PrintLuaDEInfo( strLuaDEID )
    
    -- 初始化变量
    local nRet, inputData
    local item
    local inbound_data
    local s_no
    local outbound_date
    local Condition
    
    local nRetl, strRetInfop,item
    local inboundOrder
    local strCondition
    local sqlstrCondition
    local container_data, nRet
    local strRetInfo
    
    local err_code = 0
    local err_msg 
    local err = {}
 
    -- 获取接口传入的数据
    nRet, inputData = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0) then
        table.insert(err, "无法获取数据包:" .. inputData)
        goto continue
    end
 
    --inbound_data = inputData.Data
    
    if (inputData == nil or inputData == "")then
        table.insert(err, "Data 不合法!:" .. inbound_data)
        goto continue
    end
    
    if (inputData.S_NO == nil or inputData.S_NO == "") then
        table.insert(err, "来源单号不能为空!:" .. inbound_data)
        goto continue
    end
    
    s_no = inputData.S_NO           -- 来源单号
 
    -- 用于校验出库单的状态值,料箱库的入库单看N_B_STATE,人工库的看累计出库数量是否有值
    strCondition = "S_BS_NO = '"..s_no.."' AND N_B_STATE <> 0  AND S_AREA_CODE = '料箱库' "
    nRet, outbound_date = m3.QueryDataObject(strLuaDEID, "Outbound_Order", strCondition)
    if (nRet ~= 0) then
        table.insert(err, "查询对应的出库单失败!:" .. s_no)
        goto continue
    end
    if (outbound_date ~= "") then
        table.insert(err, "该来源单号对应的出库单有非新建状态,不可删除!:" .. s_no)
        goto continue
    end
    
    
    Condition = "S_OO_NO IN (SELECT S_NO FROM TN_Outbound_Order WHERE S_BS_NO = '"..s_no.."')  AND F_ACC_O_QTY <> 0 "
    nRet, container_data = m3.QueryDataObject(strLuaDEID, "Outbound_Detail", Condition)
    if (nRet ~= 0) then
        table.insert(err, "查询对应的出库单失败!:" .. s_no)
        goto continue
    end
    
    if (container_data ~= "") then
        table.insert(err, "该来源单号对应的出库单明细有已出库的数据,不可删除!:" .. s_no)
        goto continue
    end
    
    -- 用来源单号查询入库单信息是否存在
    sqlstrCondition = "S_BS_NO = '" .. s_no .. "'"
    nRetl, strRetInfop = mobox.existThisData(strLuaDEID, "Outbound_Order", sqlstrCondition)
    if (nRetl ~= 0) then
        table.insert(err, "调用方法existThisData出错" .. strRetInfop)
        goto continue
    end
    if (strRetInfop == 'yes') then
        local nRet, inbound_order = m3.QueryDataObject(strLuaDEID, "Outbound_Order", sqlstrCondition)
        if (nRet ~= 0 or not inbound_order) then
            lua.Stop(strLuaDEID, "查询失败: ".. s_no )
            return
        end
        
        -- 查询入库单信息
        nRet, strRetInfo= mobox.dbdeleteData(strLuaDEID, "Outbound_Order", sqlstrCondition)
        if (nRet ~= 0) then
            lua.Stop(strLuaDEID, "删除出库单失败:"..no)
            return
        end
        
        for i = 1, #inbound_order do
            local record = m3.KeyValueAttrsToObjAttr(inbound_order[i].attrs)
            local no = record.S_NO  
            local sqlCondition = "S_OO_NO = '" .. no .. "'"
            nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "Outbound_Detail", sqlCondition)
            if (nRet ~= 0) then
                lua.Stop(strLuaDEID, "删除出库单明细失败:" ..no)
                return
            end
        end
    else 
        table.insert(err, "查询出库单失败")
    end
    
    -- 返回参数
    ::continue::
 
    if (#err > 0) then
        err_code = 1
        err_msg = "出库单删除失败!" .. table.concat(err, ",")
    else
        err_code = 0
        err_msg = "出库单删除成功!"
    end
 
    local result =
    {
        SourceKey = inputData.SourceKey,
        err_code = err_code,
        err_msg = err_msg,
        result = {
            S_NO = s_no
        }
    }
    mobox.returnValue(strLuaDEID, 1, lua.table2str(result))
    
end