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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
ÿþ--[[
   x:
    Tðy: }v­pў!hŒš-¹pûQnxš[T
   \O€ÿLZH
   åegÿ2024-08-27
 
   ýQpeÿ AfterClickOk
   ŸRý€:
   -- !hŒš¹[hV/f&Tò]ۏLˆxØvÍd\O
   -- !hŒš5u¯hãS/f&TŒTir™e„v“^:Sù[”^
   -- ub\ON ÿÎN5u¯hãS0R‰|™es^“^
 
   ôf9e°‹U_:
   V1.1 LZH PDAkbx·ƒÖS„v/fAm4l÷S ÿ¡l    g¹[hV÷S
   V1.2 LZH 20240919  N!hŒšsOWMS NÑS„v“^:SÈ~¹pŒTå]ºN,dЏ„v5u¯hãS/f&TNô,å]ºNpêTN¹„v5u¯h1\Rú^êTN¹„vûN¡R ÿ
            FO/f Ný€…ÇÙ*Nir™eô~¤b(W0‰|™eÔk‹Oô~¤b0̑b—„vÔk‹O ÿÔk‹O͑ϑ = yb!k÷S;`͑ * (ô~¤bÔk‹O / 10)
 
--]]
 
json  = require("json")
mobox = require("OILua_JavelinExt")
m3 = require( "oi_base_mobox" )
wms_cntr = require( "wms_container" )
wms_base = require( "wms_base" )
wms_wh = require( "wms_wh" )
function AfterClickOk(strLuaDEID)
    local nRet, strRetInfo
    -- ·ƒÖSÂSpe
    nRet, strRetInfo = mobox.getCurEditDataObjAttr(strLuaDEID, "S_SERIAL_NO", "DT_LOC_CODE")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "·ƒÖSS_MR‘^\'`1Y%! " .. strRetInfo) end
    lua.Debug(strLuaDEID, debug.getinfo(1), 'strRetInfo', strRetInfo)
    local obj_attrs = json.decode(strRetInfo)
    local serial_no = obj_attrs[1].value
    local loc_code = obj_attrs[2].value
    -- V1.1 !hŒšÂSpe Ný€:Nzz
    if (serial_no == nil or serial_no == '') then lua.Error(strLuaDEID, debug.getinfo(1), "Am4l÷S Ný€:Nzz! ") end
    if (loc_code == nil or loc_code == '') then lua.Error(strLuaDEID, debug.getinfo(1), "5u¯hãS÷S Ný€:Nzz! ") end
    -- Ç¹[hV·ƒÖS'ÁTáOo` ÿ:NzzR¥b•
    local strCondition = "S_SERIAL_NO = '" .. serial_no .. "'"
    local cg_detail_list
    nRet, cg_detail_list = m3.GetDataObjByCondition(strLuaDEID, "CG_Detail", strCondition)
    if (nRet == 1) then lua.Error(strLuaDEID, debug.getinfo(1), "*gۏLˆXbØvir™eÑ~š[Íd\O!") end
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. cg_detail_list) end
    local cntr_code = cg_detail_list.cntr_code
 
    strCondition = "S_ITEM_CODE = '" .. cg_detail_list.item_code .. "'"
    local material
    nRet, material = m3.GetDataObjByCondition(strLuaDEID, "Material", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. material) end
    
    -- !hŒšsOWMS NÑS„v“^:SÈ~¹pŒTå]ºN,dЏ„v5u¯hãS/f&TNô
    -- DT-01     N|i‰|™e“^JS¢”5u¯h / DT-02     N|i‰|™e“^hQ¢”5u¯h
    -- if (loc_code == "DT-01") then
    --     if (material.area_code ~= 'JS¢”') then
    --         lua.Error(strLuaDEID, debug.getinfo(1), "ir™e NÑS„v“^:SŒT5u¯hãS NNô!")
    --     end
    -- else
    --     if (material.area_code ~= 'hQ¢”') then
    --         lua.Error(strLuaDEID, debug.getinfo(1), "ir™e NÑS„v“^:SŒT5u¯hãS NNô!")
    --     end
    -- end
 
    -- ÇAm4l÷S·ƒÖSeQ“^US÷S
    strCondition = "S_SERIAL_NO = '" .. cg_detail_list.serial_no .. "'"
    local label_card
    nRet, label_card = m3.GetDataObjByCondition(strLuaDEID, "GT_Label_Crad", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. label_card) end
    local order_no = label_card.order_no
 
    -- ·ƒÖSeQ“^USáOo`
    strCondition = "S_ORDER_NO = '" .. order_no .. "'"
    local incoming_Info
    nRet, incoming_Info = m3.GetDataObjByCondition(strLuaDEID, "GT_Incoming_Info", strCondition)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. incoming_Info) end
 
    -- -- V1.2 ·ƒÖSir™e„vÔk‹Oô~¤b,¡‹—{Ôk‹O„v͑ϑ,·ƒÖSù[”^“^:S̑b—ir™e„v;`͑ϑ R
Nå‹ir™e„v͑ϑ‚Yœg…ÇÔk‹O„v͑ϑR¥b•
    -- -- ·ƒÖSir™e„vÔk‹Oô~¤b
    -- strCondition = "S_ITEM_CODE = '" .. cg_detail_list.item_code .. "'"
    -- local fl_Percentum
    -- nRet, fl_Percentum = m3.GetDataObjByCondition(strLuaDEID, "GT_FL_Percentum", strCondition)
    -- if (nRet == 1) then lua.Error(strLuaDEID, debug.getinfo(1), "*gô~¤bir™eÔk‹O!") end
    -- if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "m3.GetDataObjByCondition 1Y%!" .. fl_Percentum) end
    -- local actual_qty = tonumber(incoming_Info.actual_qty)
    -- local area_code
    -- local ratio
    -- -- ·ƒÖS5u¯hù[”^„v“^:S
    -- if (loc_code == "DT-01") then
    --     area_code = 'FLD'
    --     ratio = tonumber(fl_Percentum.d_ratio)
    -- else
    --     area_code = 'FLX'
    --     ratio = tonumber(fl_Percentum.x_ratio)
    -- end
    -- local ratio_qty = actual_qty * (ratio / 10)  -- Ôk‹O͑ϑ
 
    -- -- ·ƒÖSù[”^“^:S ir™e„v;`͑ϑ
    -- local inside_info
    -- local strFromTabInfo = "TN_Loc_Container a LEFT JOIN TN_CG_Detail b ON a.S_CNTR_CODE = b.S_CNTR_CODE"
    -- strFromTabInfo = strFromTabInfo .. " LEFT JOIN TN_Location c ON a.S_LOC_CODE = c.S_CODE"
    -- -- ågâ‹&{TagöN„v͑ϑ;`ŒT
    -- local strAttrInfo = " SUM(b.F_QTY) "
    -- -- ågâ‹agöN ir™exøv T,9hnc5u¯hcš[“^:S
    -- local Condition = "b.S_ITEM_CODE = '"..cg_detail_list.item_code.."' AND c.S_AREA_CODE = '"..area_code.."'"
    -- local strOrderBy = "a.T_CREATE DESC"
    -- nRet, inside_info = mobox.queryMultiTable(strLuaDEID, strAttrInfo, strFromTabInfo, 1, Condition,strOrderBy)
    -- if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "queryMultiTable 1Y%!" .. inside_info) end
    -- lua.Debug(strLuaDEID, debug.getinfo(1), 'inside_info!', inside_info)
    -- local all_qty =  tonumber(inside_info[1][1]) -- ir™e÷S(W5u¯hãSù[”^“^:S„v;`͑ϑ
    -- all_qty = all_qty + tonumber(cg_detail_list.qty)
 
    -- if(ratio_qty >= all_qty) then
    --     lua.Error(strLuaDEID, debug.getinfo(1), area_code.."“^:S̑ir™e÷S:"..cg_detail_list.item_code.."„vir™e͑ϑò]¾0RÔk‹Oô~¤b„v͑ϑ!")
    -- end
 
 
    -- 'MO¹[hVÑ~š[
    local binding
    nRet, binding = wms_wh.Loc_Container_Binding(strLuaDEID, loc_code, cntr_code, "Ñ~š[ã‰Ñ~¹eÕl-û|ß~", "û|ß~Ñ~š[")
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), ''MO¹[hVÑ~š[1Y%!' .. binding) end
 
    -- ·ƒÖSw¹páOo`
    local loc_start
    nRet, loc_start = wms_wh.GetLocInfo(loc_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. loc_start) end
 
 
 
    -- žX ReQ“^USnc„v/}¡‹peϑ
    -- 0eQ“^USnc4Y0-N /}¡‹Åˆ±{peϑ + 1  ‚Yœg…úQ XbØvpe û|ß~¥b•
    local accQty
    strCondition = "S_ORDER_NO = '" .. order_no .. "'"
    nRet, accQty = mobox.incDataObjAccQty(strLuaDEID, "GT_Incoming_Info", strCondition, "N_CNTR_QTY",
        "N_ACC_PACK_QTY", 1)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), "incDataObjAccQty 1Y%! " .. accQty) end
    lua.Debug(strLuaDEID, debug.getinfo(1), "accQty", accQty)
    if (accQty ~= '') then
        -- ô‹f/} Rpeϑ…úQ F_ACTUAL_QTY û|ß~¥b•
        lua.Error(strLuaDEID, debug.getinfo(1), "eQ“^US: " .. strRetInfo.order_no .. " -N„v/}¡‹peϑ…Çž[E–XbØvpeϑ!")
    end
 
    -- $R­eeQ“^USnc„v¶r`/f&T:NŒ[b
    local order
    nRet, order = m3.GetDataObjectByKey(strLuaDEID, "GT_Incoming_Info", "S_ORDER_NO", order_no)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), order) end
    if (tonumber(order.acc_pack_qty) == tonumber(order.cntr_qty)) then
        strCondition = "S_ORDER_NO = '" .. order.order_no .. "'"
        local strSetSQL = "S_STATE = 'Œ[b'"
        nRet, strRetInfo = mobox.updateTableAttrByCondition(strLuaDEID, "TN_GT_Incoming_Info", strCondition,
            strSetSQL)
        if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), strRetInfo) end
    end
    
    local area_code
    -- ·ƒÖS5u¯hù[”^„v“^:S
    if (loc_code == "DT-01") then
        area_code = 'FLD'
    else
        area_code = 'FLX'
    end
 
    -- ·ƒÖSÈ~¹páOo`
    local loc_end
    nRet, loc_end = wms_base.GetAreaAvaliableLoc(strLuaDEID, area_code)
 
    nRet, loc_end = wms_wh.GetLocInfo(loc_end.loc_code)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'WMS_GetLocInfo1Y%!' .. loc_end) end
 
    -- Rú^ÎN5u¯hãS0R‰|™es^“^„v\ON
    local operation           = m3.AllocObject(strLuaDEID, "Operation")
    -- w¹páOo`
    operation.start_wh_code   = loc_start.wh_code
    operation.start_area_code = loc_start.area_code
    operation.start_loc_code  = loc_start.code
 
    operation.op_type         = wms_base.Get_nConst(strLuaDEID, "\ON{|‹W-eQ“^")
    operation.op_def_name     = "5u¯heQ“^"
    operation.cntr_code       = cntr_code
    -- È~¹páOo`
    operation.end_wh_code     = loc_end.wh_code
    operation.end_area_code   = loc_end.area_code
    operation.end_loc_code    = loc_end.code
 
    nRet, operation           = m3.CreateDataObj(strLuaDEID, operation)
    if (nRet ~= 0) then lua.Error(strLuaDEID, debug.getinfo(1), 'Rú^0\ON01Y%!' .. operation) end
    lua.Debug(strLuaDEID, debug.getinfo(1), "\ONRú^TáOo`", operation)
    lua.Debug(strLuaDEID, debug.getinfo(1), "loc_end", loc_end)
    wms_base.Add_WHAreaQty_ByCGDetail(strLuaDEID, "AHYLK", loc_end.area_code, operation.cntr_code)
 
    mobox.setInfo(strLuaDEID, "!hŒšbŸR!")
end