lzh
2025-06-24 13c4a636539584ab977fddacfae884b3ec250aee
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
ÿþ--[[
   x: GT-27-20
    Tðy: Rú^sOûN¡R
   \O€ÿLZH
   åegÿ2025-01-06
 
   ýQpeÿ CreateTask
   ŸRý€:  Rú^ûN¡R
 
   ôf9e°‹U_:
 
--]]
 
json   = require("json")
mobox  = require("OILua_JavelinExt")
m3     = require("oi_base_mobox")
wms_wh = require("wms_wh")
function CreateTask(strLuaDEID)
    local nRet, strRetInfo
 
    -- ·ƒÖS0‰|™eŒèb3u÷‹US0
    local allot_order
    nRet, allot_order = m3.GetSysCurEditDataObj(strLuaDEID, "GT_Allot_Order")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), allot_order) end
    if (allot_order == nil or allot_order == '') then goto coroutine end
    lua.Debug(strLuaDEID, debug.getinfo(1), '‰|™eŒèb3u÷‹US', allot_order)
 
    -- ÂSpe
    local id = allot_order.id                         -- /UNhƋ
    local item_code = allot_order.item_code           -- ir™ex
    local area_code = allot_order.area_code           -- “^:Sx
    local allot_qty = tonumber(allot_order.allot_qty) -- ŒèbXbpe
    local level = tonumber(allot_order.level)         -- eˆ'§~+R 1 '}%` 2ck8^
    local no = allot_order.bs_no
    
    local str_area = ''
    if(area_code == 'TFL')then
        str_area = 'PFL'
    elseif(area_code == 'PFL')then
        str_area = 'TFL'
    elseif(area_code == 'HWPFL')then
        str_area = 'HWTFL'
    elseif(area_code == 'HWTFL')then
        str_area = 'HWPFL'
    end
 
    -- ·ƒÖSw¹p
    -- ågâ‹cš[“^:SŒTir™ex„v¹[hVÿ*g
N•    ÿsQT€„v'MOÿ*g
N•    ÿ
    local strCondition =
        "S_CNTR_CODE IN(SELECT S_CODE FROM TN_Container WHERE N_LOCK_STATE = 0 AND S_CODE IN(SELECT S_CNTR_CODE FROM TN_CG_Detail WHERE S_ITEM_CODE = '" ..
        item_code ..
        "')) AND S_LOC_CODE IN (SELECT S_CODE FROM TN_Location WHERE N_LOCK_STATE = 0 AND S_AREA_CODE = '" ..
        str_area .. "' )"
    local loc_container
    nRet, loc_container = m3.QueryDataObject(strLuaDEID, "Loc_Container", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "QueryDataObject1Y%!" .. loc_container) end
    if (loc_container == '') then lua.Error(strLuaDEID, debug.getinfo(1), "“^X[ N³!") end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'loc_container', loc_container)
 
    for i = 1, #loc_container do
        -- S_án³ŒèbXbpeöeóúQª_¯sSO
        if (allot_qty < i) then goto coroutine end
        -- lbc<h_
        -- \ [{"attr":"a1","value":"xxx1"},{"attr":"a2","value":"xxx2"},..] <h_lbcb {"lua_a1":"xxx1","lua_a2":"xxx2"}
        local attr
        nRet, attr = m3.ObjAttrStrToLuaObj("Loc_Container", lua.table2str(loc_container[i].attrs))
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "ObjAttrStrToLuaObj1Y%! " .. attr) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'attr', attr)
 
        local loc_code = attr.loc_code -- w¹p'MO
        -- ·ƒÖSw¹p'MOáOo`
        local location
        nRet, location = wms_wh.Location_GetInfo(strLuaDEID, loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%! " .. location) end
 
        -- ·ƒÖSÈ~¹p
        nRet, loc_code = wms_base.GetAreaAvaliableLoc(strLuaDEID, area_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_GetAreaAvaliableLoc1Y%! " .. loc_code) end
        local end_location
        nRet, end_location = wms_wh.Location_GetInfo(strLuaDEID, loc_code.loc_code)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "WMS_Location_GetInfo1Y%! " .. end_location) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'end_location', end_location)
 
        -- Rú^sOûN¡R
        local gt_task = m3.AllocObject(strLuaDEID, "GT_Task")
        lua.Debug(strLuaDEID, debug.getinfo(1), 'gt_task', gt_task)
        -- w¹páOo`
        gt_task.start_wh_code = location.wh_code
        gt_task.start_area_code = location.area_code
        gt_task.start_loc_code = location.code
        -- È~¹páOo`
        gt_task.end_wh_code = end_location.wh_code
        gt_task.end_area_code = end_location.area_code
        gt_task.end_loc_code = end_location.code
        gt_task.type = 1 -- 1 ‰|™eŒèb,dЏ 2 Øpö€,dЏ
        gt_task.bs_no = no
        gt_task.cntr_code = attr.cntr_code
 
        -- eˆ'§~+R:N'}%`ROHQ§~ؚ,ck8^ROHQ§~NO
        if (level == 1) then
            gt_task.priority = 2 -- 'Y„vOHQ
        end
        nRet, gt_task = m3.CreateDataObj(strLuaDEID, gt_task)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0sOûN¡R01Y%!' .. gt_task) end
        lua.Debug(strLuaDEID, debug.getinfo(1), 'gt_task', gt_task)
 
        -- îO9e‰|™eŒèb3u÷‹USN¡R¶r`:N gbLˆ-N
        strCondition = "S_ID = '" .. id .. "'"
        local strSetAttr = "S_B_STATE = 2"
        nRet, strRetInfo = mobox.updateDataAttrByCondition(strLuaDEID, "GT_Allot_Order", strCondition, strSetAttr)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "¾‹n¶r`1Y%!" .. strRetInfo) end
    end
 
    ::coroutine::
end