· 9 years ago · Jan 05, 2017, 09:14 PM
1*--- Class : clsipcpr_ApplyPoChnage.prg
2*--- Author : Nasim Huq 11/07/07
3*--- Purpose : Use SQL update to make the change.
4*--- Change : TR 1027127 NH
5*---
6*---
7*--- TR 1034532 NH
8#Include SYSTEM.h
9#Include EDI.h
10#DEFINE EDI_BULK_ORDER "BK"
11#DEFINE EDI_BLANKET_ORDER "BL"
12*=== TR 1034532 NH
13
14Define Class clsipcpr_applyPoChange As BPOEDIBase
15
16 oMainProcess = .F.
17 lScheduled = .F.
18 oFrmProgressBar = .F.
19 oLog = .F.
20 lUserInterface = .F.
21 oCopyUtil = .F.
22 nProcessed = 0
23
24 *--- TR 1034532 NH
25 c860SODetailAddMatchCriteria = ""
26 *=== TR 1034532 NH
27
28 * --- TR 1047609 7/7/10 CM
29 cTmpSLNTable = ""
30 * === TR 1047609 7/7/10 CM
31
32 *--- TechRec 1085945 28-May-2015 vkrishnamurthy ---
33 cZzxniblr = ''
34 cZzoordwh = ''
35 cZzoordwd = ''
36 NibBatchNum = 0 &&--- zzoordrh.pkey + NibBatchNum will be unique record in zzoordwh table
37 cOrdHdrOld = ""
38 cOrdDtlOld = ""
39 cOrdHdrNew = ""
40 cOrdDtlNew = ""
41
42 cOpenCnclHdr= ""
43 cUniqueHdr = ""
44 cCnclDtlOld = ""
45 *=== TechRec 1085945 28-May-2015 vkrishnamurthy ===
46
47
48*-----------------------------------------------------------------------------------------
49
50 Procedure Init
51
52 Local llRetVal
53 llRetVal = .T.
54
55 This.oCopyUtil = Newobject("CopyUtil","CopyUtil.prg")
56 llRetVal = (Vartype(This.oCopyUtil) = "O")
57 Return llRetVal
58 Endproc
59
60*-----------------------------------------------------------------------------------------
61
62 Procedure ApplyPoChange(toMainProcess)
63
64 If Not Vartype(toMainProcess) = "O"
65 Return .F.
66 Endif
67
68 *THIS.InitThermoWithCaption(@l_nThermoCnt, 7, "Creating and open transaction views...")
69
70 Local lcFilterCriteria,lnIpcth, lnIpctd
71 STORE 0 TO lnIpcth, lnIpctd
72
73 lcFilterCriteria = Alltrim(toMainProcess.cFilterCriteria)
74 lcFilterCriteria = Strtran(lcFilterCriteria,"Where","")
75
76 This.oMainProcess = toMainProcess
77 This.lScheduled = toMainProcess.lScheduled
78 This.oFrmProgressBar = toMainProcess.oFrmProgressBar
79 This.oLog = toMainProcess.oLog
80 THIS.lUserInterface = toMainProcess.lUserInterface
81 this.nProcessed = 0
82
83 *--- TR 1052615 22-Feb-2011 BNarayan Change the qualifier NZ to RZ again as it is reverted
84 *- in AddNewOrderForNZ
85 This.oMainProcess.MoveNZtoRZ()
86 *=== TR 1052615 22-Feb-2011 BNarayan
87
88 *--- TR 1034532 NH
89 this.c860SODetailAddMatchCriteria = toMainProcess.c860SODetailAddMatchCriteria
90 *=== TR 1034532 NH
91
92 LOCAL lcThermoTotalCaption
93 lcThermoTotalCaption = "Apply PO Change"
94 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
95
96 * --- TR 1047609 7/7/10 CM
97 This.cTmpSLNTable = toMainProcess.cTmpSLNTable
98 * === TR 1047609 7/7/10 CM
99
100 *--- use filter to get transaction records create four table zzeipcth, zzeipctd, zzeipcth_nt, zzeipctd_nt
101
102 *--- validate and apply change QI to zzoordrd -
103 *--- validate and apply change AI to zzoordrd -
104 *--- validate and apply change PC to zzoordrd -
105 *--- validate and apply change CT to zzoordrd - Date change in detail
106 *--- all detail error will be recorded in zzeipctd_v and then it will be translated to zzeipctd
107
108 Local llRetVal, lnOldSelect
109 llRetVal = .T.
110 lnOldSelect = Select()
111 LOCAL lcZzeipcth,lcZzeipctd
112 STORE " " TO lcZzeipcth,lcZzeipctd
113 *--- use filter to get transaction records create four table zzeipcth, zzeipctd, zzeipcth_nt, zzeipctd_nt
114 llRetVal = llRetVal And This.Get860TransTables(@lcZzeipcth,@lcZzeipctd, lcFilterCriteria)
115 This.LogEntry("Retreive data from 860 transaction to apply the change " + Iif(llRetVal,"completed.","failed."))
116
117 *--- get unique PO, Customer, Store
118 *--- run AppyPoChange for each unique batch
119 LOCAL lcZzeipcth_batch, lnTotalProcssed,lnBatchRecCount
120 lcZzeipcth_batch = ""
121 lnBatchRecCount = 0
122 LOCAL lcZzeipcth_bat,lcZzeipctd_bat
123 STORE " " TO lcZzeipcth_bat,lcZzeipctd_bat
124
125 llRetVal = llRetVal and this.GetRecordsForUniquePoCustomerStore(lcZzeipcth,lcZzeipctd, ;
126 @lcZzeipcth_bat,@lcZzeipctd_bat,@lnBatchRecCount,@lcThermoTotalCaption)
127
128 this.oMainProcess.nProcessed = 0 &&--- TR 1036066 NH
129
130 DO WHILE llRetVal AND lnBatchRecCount > 0
131 this.nProcessed = 0 &&--- clear prior cycle processed count.
132 llRetVal = llRetVal and this.ApplyPoChangeInBatch(lcZzeipcth_bat,lcZzeipctd_bat, @lcThermoTotalCaption,lcZzeipcth,lcZzeipctd)
133 IF llRetVal
134 this.oMainProcess.nProcessed = this.oMainProcess.nProcessed + this.nProcessed
135 *--- log results
136 ENDIF
137 llRetVal = llRetVal and this.GetRecordsForUniquePoCustomerStore(lcZzeipcth,lcZzeipctd, ;
138 @lcZzeipcth_bat,@lcZzeipctd_bat,@lnBatchRecCount)
139
140 ENDDO
141
142 Select(lnOldSelect)
143 Return llRetVal
144
145 Endproc
146
147*-----------------------------------------------------------------------------------------
148
149 PROCEDURE ApplyPoChangeInBatch(lcZzeipcth,lcZzeipctd, lcThermoTotalCaption, pcZzeipcth_total, pcZzeipctd_total)
150
151 Local llRetVal, lnOldSelect,lcUnique
152 llRetVal = .T.
153 lnOldSelect = Select()
154 lcUnique = SYS(2015)
155
156 LOCAL lcZzoordrh_Update, lcZzoordrd_update, lcZzoordrdv_update, lcZzoordsp_update, lcAlloc_update
157 STORE " " TO lcZzoordrh_Update, lcZzoordrd_update, lcZzoordrdv_update, lcZzoordsp_update, lcAlloc_update
158 LOCAL lcZzeipcth_nt, lcZzeipctd_nt, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update
159 STORE "" to lcZzeipcth_nt, lcZzeipctd_nt, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update
160
161 Local lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordrdv_orig, lcZzoordsp_orig,lcZzoordrh_new
162 Store "" To lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordrdv_orig, lcZzoordsp_orig, lcZzoordrh_new
163
164 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
165 LOCAL lczzeipohd,lczzeipohd_update
166 STORE "" TO lczzeipohd_update
167 lczzeipohd = "zzeipohd"
168 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
169
170 * --- TR 1047609 7/7/10 CM
171 LOCAL lcZzeipchs_Insert
172 lcZzeipchs_Insert = ""
173 * === TR 1047609 7/7/10 CM
174
175 this.LogMajorStage("Final Validation and apply PO change.")
176
177 LOCAL lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordsp_orig, lcZzoordrdv_orig
178 STORE " " TO lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordsp_orig, lcZzoordrdv_orig
179
180 llRetVal = llRetVal And This.FinalValidation(lcZzeipcth,lcZzeipctd,@lcZzoordrh_orig,@lcZzoordrd_orig,@lcZzoordrdv_orig,@lcZzoordsp_orig)
181 this.LogEntry("Final Validation " + IIF(llRetVal,"completed.","failed."))
182 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
183 LOCAL lnIpcth, lnIpctd
184 STORE 0 TO lnIpcth, lnIpctd
185 llRetVal = llRetVal and this.GoodTransRecordCount(lcZzeipcth,lcZzeipctd,@lnIpcth, @lnIpctd)
186 this.LogEntry("Good 860 transaction header record count " + TRANSFORM(lnIpcth))
187 this.LogEntry("Good 860 transaction detail record count " + TRANSFORM(lnIpctd))
188
189 IF lnIpcth = 0
190 RETURN .t.
191 ENDIF
192
193 *--- Now, all that is left in 860 transaction is good transaction records
194 *--- create Update date tables - lcZzoordrh_update, lcZzoordrd_update, lcZzoordsp_update, lcAlloc_update
195
196 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
197*!* llRetVal = llRetVal And This.CreateOrderUpdateTempTables(lcZzeipcth,lcZzeipctd, lcZzoordrdv_orig, @lcZzoordrh_Update, @lcZzoordrd_update, @lcZzoordrdv_update, @lcZzoordsp_update, @lcAlloc_update)
198 llRetVal = llRetVal And This.CreateOrderUpdateTempTables(lcZzeipcth,lcZzeipctd, lcZzoordrdv_orig, @lcZzoordrh_Update, @lcZzoordrd_update, @lcZzoordrdv_update, @lcZzoordsp_update, @lcAlloc_update,@lczzeipohd,@lczzeipohd_update)
199 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
200
201 *--- apply change to SO if there is POC_Purp = "01" - cancel
202 this.LogEntry("Create Temp tables to apply PO change " + IIF(llRetVal,"completed.","failed."))
203 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
204
205
206 llRetVal = llRetVal And This.Prepare860TransForQuantityChange(lcZzeipcth,lcZzeipctd,lcZzoordrdv_orig)
207 this.LogEntry("Prepare 860 transaction data for quantity change " + IIF(llRetVal,"completed.","failed."))
208 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
209
210 llRetVal = llRetVal And This.PrepareFor_PoCancel(lcZzeipcth,lcZzeipctd, lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordrh_Update, lcZzoordrd_update,lcZzoordsp_update)
211 this.LogEntry("Process PO cancel " + IIF(llRetVal,"completed.","failed."))
212 *--- Prepare quantity in temp SO tables (lcZzoordrh_update, lcZzoordrd_update) - create temp SO detail cancel record for decrease amount
213 *--- when order quantity is 0 then create temp SO header/detail delete records and create SO header/detail cancel records
214 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
215
216 llRetVal = llRetVal And This.PrepareForQualifier_QuantityDecrease(lcZzeipcth,lcZzeipctd,lcZzoordrh_orig, lcZzoordrdv_orig, lcZzoordrh_update,lcZzoordrdv_update, lcZzoordsp_update)
217 this.LogEntry("Process quantity decrease " + IIF(llRetVal,"completed.","failed."))
218 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
219
220 llRetVal = llRetVal And This.PrepareForQualifier_QuantityIncrease(lcZzeipcth, lcZzeipctd,lcZzoordrh_orig, lcZzoordrdv_orig, lcZzoordrh_Update, lcZzoordrdv_update, lcZzoordsp_update, @lcZzoordrh_new)
221 *--- apply change to SO if there is POC_Purp = "04" and 860 header only transcation record
222 this.LogEntry("Process quantity Increase " + IIF(llRetVal,"completed.","failed."))
223 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
224
225 *---- Adjust item quantity to set the actual quantity that will replace order line item quanity
226 llRetVal = llRetVal And This.SetActualQuantityToUpdateForAllItems(lcZzeipcth,lcZzeipctd,lcZzoordrh_orig,lcZzoordrd_orig,lcZzoordrdv_orig,;
227 lcZzoordrh_Update,lcZzoordrd_update, lcZzoordrdv_update, lcZzoordsp_update)
228
229 this.LogEntry("Set final quantity for open and cancel order " + IIF(llRetVal,"completed.","failed."))
230 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
231
232 *--- TR 1034532 NH : qualifier DB
233 llRetVal = llRetVal and this.PrepareForQualifier_DB(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_Update)
234 *=== TR 1034532 NH
235
236 llRetVal = llRetVal and this.PrepareSalesOrderTable_DateChange(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_Update)
237
238 *--- TechRec 1041233 15-Jul-2009 vkrishnamurthy ---
239 llRetVal = llRetVal and this.PrepareSalesOrderTable_TermsChange(lcZzeipcth,lcZzoordrh_Update)
240 *=== TechRec 1041233 15-Jul-2009 vkrishnamurthy ===
241
242 *--- TR 1059173 20-Feb-2012 Partha ---
243 llRetVal = llRetVal and this.PrepareSalesOrderTable_BillToChange(lcZzeipcth,lcZzoordrh_Update)
244 *=== TR 1059173 20-Feb-2012 Partha ===
245
246 *--- Price Change
247 llRetVal = llRetVal and this.PrepareSalesOrderTable_PriceChange(lcZzeipcth, lcZzeipctd, lcZzoordrh_orig, lcZzoordrd_orig, lcZzoordrh_Update, lcZzoordrd_Update)
248
249 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
250
251 *--- TechRec 1041520 09-Mar-2010 vkrishnamurthy ---
252*!* llRetVal = llRetVal And This.PrepareSalesOrderTable_850HDChange(lcZzeipctd,lczzeipohd_update)
253 llRetVal = llRetVal And This.PrepareSalesOrderTable_850HDChange(lcZzeipctd,lczzeipohd_update,lcZzoordrd_Update)
254 *=== TechRec 1041520 09-Mar-2010 vkrishnamurthy ===
255
256 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
257
258 *--- Delete order with zero quantity
259 llRetVal = llRetVal And This.PrepareOrderToDeleteForZeroQuantity(lcZzoordrh_update, lcZzoordrd_update, lcZzoordsp_update)
260
261 *----
262 *--- vertical order detail to horizontal order detail
263 llRetVal = llRetVal And This.PrepareForFinalUpdate(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_update, lcZzoordrdv_update, lcZzoordsp_update)
264 this.LogEntry("Prepare 860 order for final update " + IIF(llRetVal,"completed.","failed."))
265 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
266
267 *--- 860 Notes:
268 llRetVal = llRetVal and this.CreateNotesTables(lcZzeipcth,lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_update, @lcZzeipcth_nt,@lcZzeipctd_nt, @lcZzoordrh_nt_Update, @lcZzoordrd_nt_Update)
269 this.LogEntry("Create Temp tables to apply PO change Notes " + IIF(llRetVal,"completed.","failed."))
270 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
271
272 * --- TR 1047609 7/7/10 CM
273 If !Empty(This.cTmpSLNTable)
274 llRetVal = llRetVal And This.CreateSLNHistoryTable(lcZzeipcth, lcZzeipctd, @lcZzeipchs_Insert)
275 this.LogEntry("Create Temp table for SLN History " + IIF(llRetVal,"completed.","failed."))
276 Endif
277 * === TR 1047069 7/7/10 CM
278
279 *--- TR 1052615 22-Feb-2011 BNarayan Change back the qualifier changed from NZ to RZ
280 IF USED(This.oMainProcess.cNZLocalCursor)
281 This.oMainProcess.RevertFromRZtoNZ()
282 ENDIF
283 *=== TR 1052615 22-Feb-2011 BNarayan
284
285 *--- update all tables
286 *--- TechRec 1040484 19-Jun-2009 vkrishnamurthy ---
287*!* llRetVal = llRetVal And This.UpdateAllTables(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_update, lcZzoordsp_update, lcAlloc_update,;
288*!* lcZzeipcth_nt,lcZzeipctd_nt, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update,pcZzeipcth_total, pcZzeipctd_total,lcZzoordrh_new)
289
290 * --- TR 1047609 7/7/10 CM --- Added lcZzeipchs_Insert
291 llRetVal = llRetVal And This.UpdateAllTables(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_update, lcZzoordsp_update, lcAlloc_update,;
292 lcZzeipcth_nt,lcZzeipctd_nt, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update,pcZzeipcth_total, pcZzeipctd_total,lcZzoordrh_new,lczzeipohd_update,;
293 lcZzeipchs_Insert)
294 *=== TechRec 1040484 19-Jun-2009 vkrishnamurthy ===
295
296 this.LogEntry("Update of all 860 related tables " + IIF(llRetVal,"completed.","failed."))
297 this.AdvanceThermoTotalWithCaptionPlus(lcThermoTotalCaption)
298
299 Select(lnOldSelect)
300 Return llRetVal
301
302 Endproc
303
304*-----------------------------------------------------------------------------------------
305
306 PROCEDURE GetRecordsForUniquePoCustomerStore(pcZzeipcth, pcZzeipctd, ;
307 pcRefZzeipcth_batch, pcRefZzeipctd_batch, ;
308 pnRefBatchRecCount,lcThermoTotalCaption)
309
310 Local llRetVal, lnOldSelect,lcUnique, lcZzeipcth_batch, lcZzeipctd_batch
311 llRetVal = .T.
312 lnOldSelect = Select()
313 lcUnique = SYS(2015)
314 lcZzeipcth_batch = "#Zzeipcth_batch" + lcUnique
315 lcZzeipctd_batch = "#Zzeipctd_batch" + lcUnique
316
317 *--- find unique 860 transaction header
318 lcSQL = " SELECT th.* INTO " + lcZzeipcth_batch + " FROM " + pcZzeipcth + " th " + ;
319 " WHERE EXISTS (SELECT po_num, customer, store, MIN(ith.pkey) as pkey from " + pcZzeipcth + " ith " + ;
320 " GROUP BY po_num, customer, store " + ;
321 " HAVING MIN(ith.pkey) = th.pkey) "
322 llRetVal = llRetVal and v_sqlExec(lcSQL)
323
324 lcSQL = " SELECT td.* INTO " + lcZzeipctd_batch + " FROM " + pcZzeipctd + " td " + ;
325 " INNER JOIN " + lcZzeipcth_batch + " th ON th.pkey = td.fkey "
326 llRetVal = llRetVal and v_sqlExec(lcSQL)
327
328 *--- remove this batch records from all 860 transaction table.
329 lcSQL = " DELETE th FROM " + pcZzeipcth + " th INNER JOIN " + lcZzeipcth_batch + " thb ON " + ;
330 " thb.pkey = th.pkey "
331 llRetVal = llRetVal and v_sqlExec(lcSQL)
332
333 lcSQL = " DELETE td FROM " + pcZzeipctd + " td INNER JOIN " + lcZzeipctd_batch + " tdb ON " + ;
334 " tdb.pkey = td.pkey "
335 llRetVal = llRetVal and v_sqlExec(lcSQL)
336
337 llRetVal = llRetVal and v_sqlexec("select COUNT(*) ToProcess from " + lcZzeipcth_batch,"toPorcess")
338 IF llRetVal
339 pcRefZzeipcth_batch = lcZzeipcth_batch
340 pcRefZzeipctd_batch = lcZzeipctd_batch
341 pnRefBatchRecCount = toPorcess.ToProcess
342 ENDIF
343
344 Select(lnOldSelect)
345 Return llRetVal
346
347 Endproc
348
349*-----------------------------------------------------------------------------------------
350
351 PROCEDURE CreateNotesTables(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update, pcRefZzeipcth_nt, pcRefZzeipctd_nt, ;
352 pcRefZzoordrh_nt_Update, pcRefZzoordrd_nt_Update)
353
354 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt, lcUnique
355 llRetVal = .T.
356 lnOldSelect = Select()
357 lnThermoCnt = 0
358 lcUnique = SYS(2015)
359
360 LOCAL lcZzeipcth_nt, lcZzeipctd_nt, lcZzoordrh_nt_orig, lcZzoordrd_nt_orig, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update
361 lcZzeipcth_nt = "#Zzeipcth_nt" + lcUnique
362 lcZzeipctd_nt = "#Zzeipctd_nt" + lcUnique
363 lcZzoordrh_nt_Update = "#Zzoordrh_nt" + lcUnique
364 lcZzoordrd_nt_Update = "#Zzoordrd_nt" + lcUnique
365 lcZzoordrh_nt_orig = "#Zzoordrh_nt_orig" + lcUnique
366 lcZzoordrd_nt_orig = "#Zzoordrd_nt_orig" + lcUnique
367
368 llRetVal = llRetVal and this.loadTransAndOrderHeaderNotes(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update, ;
369 lcZzeipcth_nt, lcZzeipctd_nt, lcZzoordrh_nt_Update, lcZzoordrd_nt_Update,;
370 lcZzoordrh_nt_orig, lcZzoordrd_nt_orig)
371
372 llRetVal = llRetVal and this.CreateOrderNotes(pcZzeipcth, pcZzoordrh_Update, lcZzeipcth_nt,lcZzoordrh_nt_orig,lcZzoordrh_nt_Update)
373 llRetVal = llRetVal and this.CreateOrderDetailNotes(pcZzeipctd, pcZzoordrd_update, lcZzeipctd_nt,lcZzoordrd_nt_orig,lcZzoordrd_nt_Update)
374
375 pcRefZzeipcth_nt = lcZzeipcth_nt
376 pcRefZzeipctd_nt = lcZzeipctd_nt
377 pcRefZzoordrh_nt_Update = lcZzoordrh_nt_Update
378 pcRefZzoordrd_nt_Update = lcZzoordrd_nt_Update
379
380 Select(lnOldSelect)
381 Return llRetVal
382
383 Endproc
384
385*-----------------------------------------------------------------------------------------
386
387 PROCEDURE LoadTransAndOrderHeaderNotes(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update, ;
388 pcZzeipcth_nt, pcZzeipctd_nt, pcZzoordrh_nt_Update, pcZzoordrd_nt_Update,;
389 pcZzoordrh_nt_orig, pcZzoordrd_nt_orig)
390
391 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt, lcUnique
392 llRetVal = .T.
393 lnOldSelect = Select()
394 lnThermoCnt = 0
395 lcUnique = SYS(2015)
396
397 *--- load transaction header notes
398 lcSQL = " SELECT n.* into " + pcZzeipcth_nt + " FROM sysnotes n INNER JOIN " + pcZzeipcth + " th ON " + ;
399 " th.PKEY = n.fkey and n.table_name = 'ZZEIPCTH'"
400 llRetVal = llRetVal and v_sqlexec(lcSQL)
401
402 lcSQL = " UPDATE n SET ord_num = th.ord_num, line_seq = 0 FROM " + pcZzeipcth_nt + " n INNER JOIN " + pcZzeipcth + ;
403 " th ON th.pkey = n.fkey "
404 llRetVal = llRetVal and v_sqlexec(lcSQL)
405
406 *--- load trans detail notes
407 lcSQL = " SELECT td.division, td.style, td.color_code, td.lbl_code, td.dimension, n.* INTO " + pcZzeipctd_nt + ;
408 " FROM sysnotes n INNER JOIN " + pcZzeipctd + " td ON td.pkey = n.fkey and n.table_name = 'ZZEIPCTD'"
409 llRetVal = llRetVal and v_sqlexec(lcSQL, )
410
411 lcSQL = " UPDATE n SET ord_num = td.ord_num FROM " + pcZzeipctd_nt + " n INNER JOIN " + pcZzeipctd + ;
412 " td ON td.pkey = n.fkey "
413 llRetVal = llRetVal and v_sqlexec(lcSQL)
414
415 *--- load order header notes
416 lcSQL = " SELECT n.* INTO " + pcZzoordrh_nt_orig + " FROM sysnotes n INNER JOIN " + pcZzoordrh_Update + ;
417 " oh ON oh.ORD_NUM = n.ORD_NUM and n.line_seq = 0 and n.table_name = 'ZZOORDRH'"
418 llRetVal = llRetVal and v_sqlexec(lcSQL)
419
420 *--- load order detail notes
421 lcSQL = " SELECT od.division, od.style, od.color_code, od.lbl_code, od.dimension, n.* INTO " + pcZzoordrd_nt_orig + ;
422 " FROM sysnotes n INNER JOIN " + pcZzoordrd_update + ;
423 " od ON od.ord_num = n.ord_num and od.line_seq = n.line_seq and n.table_name = 'ZZOORDRD'"
424 llRetVal = llRetVal and v_sqlexec(lcSQL)
425
426 Select(lnOldSelect)
427 Return llRetVal
428
429 Endproc
430
431*-----------------------------------------------------------------------------------------
432
433 PROCEDURE CreateOrderNotes(pcZzeipcth, pcZzoordrh_Update, pcZzeipcth_nt,pcZzoordrh_nt_orig,pcZzoordrh_nt_Update)
434
435 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt, lcipcth_nt_aggr
436 llRetVal = .T.
437 lnOldSelect = Select()
438 lnThermoCnt = 0
439 lcipcth_nt_aggr = "#Zzeipcth_nt" + SYS(2015)
440
441 *--- Aggregate on order number and notes type
442 llRetVal = llRetVal and this.AggregateOnNoteType(pcZzeipcth_nt, lcipcth_nt_aggr)
443
444 *--- create notes update temp tables
445 llRetVal = llRetVal and v_sqlexec("select * into " + pcZzoordrh_nt_Update + " FROM " + lcipcth_nt_aggr + " WHERE 1=2")
446 llRetVal = llRetVal and v_sqlexec("Alter table " + pcZzoordrh_nt_Update + " add SQL_Action char(1) default('') not null")
447
448 *--- update : - Adding notes to existing notes for same Notes Type
449 lcFlds = ""
450 lcValues = ""
451 lcExcludeFlds = "'SQL_action','notes'"
452 lcCalFlds = "SQL_action, notes "
453 lcCalFldsValues = "'U', CAST(ohn.notes as varchar(2000)) + CAST(COALESCE(thn.notes,'') as varchar(2000)) "
454
455 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_nt_Update , pcZzoordrh_nt_orig, ;
456 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'ohn')
457
458 lcSQL = " INSERT INTO " + pcZzoordrh_nt_Update + " ( " + lcFlds + " ) " + ;
459 " SELECT " + lcValues + " FROM " + pcZzoordrh_nt_orig + " ohn LEFT OUTER JOIN " + lcipcth_nt_aggr + " thn " + ;
460 " ON thn.ord_num = ohn.ord_num and thn.note_type = ohn.note_type "
461
462 llRetVal = llRetVal and v_sqlexec(lcSQL)
463
464 *--- Insert : - New notes to order
465 lcFlds = ""
466 lcValues = ""
467 lcExcludeFlds = "'SQL_action','table_name','seq'"
468 lcCalFlds = "SQL_action,table_name,seq"
469 lcCalFldsValues = "'I','ZZOORDRH',0"
470
471 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_nt_Update , lcipcth_nt_aggr, ;
472 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'thn')
473
474 lcSQL = " INSERT INTO " + pcZzoordrh_nt_Update + " ( " + lcFlds + " ) " + ;
475 " SELECT " + lcValues + " FROM " + lcipcth_nt_aggr + " thn " + ;
476 " WHERE NOT EXISTS (SELECT * FROM " + pcZzoordrh_nt_orig + " ohn " + ;
477 " WHERE thn.ord_num = ohn.ord_num and thn.note_type = ohn.note_type) "
478
479 llRetVal = llRetVal and v_sqlexec(lcSQL)
480
481 *--- only take ord_status = 'O' because the link between notes header and order header is base on ord_num only
482 lcSQL = " Update nh SET fkey = h.pkey FROM " + pcZzoordrh_nt_Update + " nh INNER JOIN " + pcZzoordrh_Update + " h " + ;
483 " ON nh.ord_num = h.ord_num and h.ord_status = 'O' "
484 llRetVal = llRetVal and v_sqlexec(lcSQL)
485
486 *--- set Hder Pkey
487 llRetVal = llRetVal and this.SetOrderHdrNotePkey(pcZzoordrh_nt_Update)
488
489 *--- Set Seq
490 llRetVal = llRetVal and this.SetOrderHdrNotesSeq(pcZzoordrh_nt_Update)
491
492 *--- set hasnotes flag in order header
493 lcSQL = " UPDATE h SET hasnotes = 'Y' FROM " + pcZzoordrh_Update + " h inner join " + pcZzoordrh_nt_Update + ;
494 " n ON n.ord_num = h.ord_num and n.line_seq = 0 and n.table_name = 'ZZOORDRH'"
495 llRetVal = llRetVal and v_sqlexec(lcSQL)
496 Select(lnOldSelect)
497 Return llRetVal
498
499 Endproc
500
501*-----------------------------------------------------------------------------------------
502
503 PROCEDURE SetOrderHdrNotePkey(pcZzoordrh_nt_Update)
504
505 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcSqlNtSeq
506 llRetVal = .T.
507 lnOldSelect = Select()
508
509 lcSQL = "SELECT count(*) newCount from " + pcZzoordrh_nt_Update + " where sql_action = 'I'"
510 llRetVal = llRetVal AND v_SqlExec(lcSQL,"NtRecord")
511
512 IF llRetVal AND NtRecord.newCount > 0
513 lnMaxPkey = v_NextPKey("SYSNOTES",NtRecord.newCount)
514 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(pcZzoordrh_nt_Update, "pkey", lnMaxPkey, NtRecord.newCount, ;
515 "pkey_I", "sql_action = 'I'","ORD_NUM,NOTE_TYPE",;
516 "ORD_NUM,NOTE_TYPE")
517 ENDIF
518
519 Select(lnOldSelect)
520 Return llRetVal
521
522 Endproc
523
524*-----------------------------------------------------------------------------------------
525
526 PROCEDURE SetOrderDtlNotePkey(pcZzoordrd_nt_Update)
527
528 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcSqlNtSeq
529 llRetVal = .T.
530 lnOldSelect = Select()
531
532 lcSQL = "SELECT count(*) newCount from " + pcZzoordrd_nt_Update + " where sql_action = 'I'"
533 llRetVal = llRetVal AND v_SqlExec(lcSQL,"NtRecord")
534
535 IF llRetVal AND NtRecord.newCount > 0
536 lnMaxPkey = v_NextPKey("SYSNOTES",NtRecord.newCount)
537 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(pcZzoordrd_nt_Update, "pkey", lnMaxPkey, NtRecord.newCount, ;
538 "pkey_I", "sql_action = 'I'","ORD_NUM,line_seq, NOTE_TYPE",;
539 "ORD_NUM,line_seq, NOTE_TYPE")
540 ENDIF
541
542 Select(lnOldSelect)
543 Return llRetVal
544
545 Endproc
546
547 *-----------------------------------------------------------------------------------------
548
549 PROCEDURE SetOrderHdrNotesSeq(pcZzoordrh_nt_Update)
550
551 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcSqlNtSeq
552 llRetVal = .T.
553 lnOldSelect = Select()
554 lcNt_Seq = "#NotesSeq" + SYS(2015)
555
556 lcSQL = " SELECT n.ORD_NUM, n.note_type, s.seq INTO " + lcNt_Seq + " FROM " + pcZzoordrh_nt_Update + " n " + ;
557 " INNER JOIN ( SELECT ORD_NUM, MAX(seq) + 1 as seq FROM " + pcZzoordrh_nt_Update + " GROUP BY ord_num) s " + ;
558 " ON n.ord_num = s.ord_num and n.SQL_action = 'I' ORDER BY n.ord_num "
559
560 llRetVal = llRetVal and v_sqlexec(lcSQL)
561
562*!* lcSQL = " select d.fkey, d.pkey, s.line_seq " + ;
563*!* " into " + lcline_seq + " from " + pcZzoordrd_update + " d inner join " + ;
564*!* " ( select fkey, max(line_seq) + 1 line_seq from " + pcZzoordrd_update + ;
565*!* " group by fkey) s " + ;
566*!* " on d.fkey = s.fkey " + ;
567*!* " where d.sql_action = 'I' " + ;
568*!* " order by d.fkey "
569*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
570
571 lcSQL = "alter table " + lcNt_seq + " add seq_I int identity(1,1) NOT NULL"
572 llRetVal = llRetVal and v_sqlexec(lcSQL)
573
574*!* lcSqlLnSeq = " select l.fkey, l.pkey, " + ;
575*!* " line_seq + (l.line_seq_I - o.line_seq_offset) as line_seq" + ;
576*!* " from " + lcline_seq + " l inner join " + ;
577*!* " (select fkey, min(line_seq_I) as line_seq_offset from " + lcline_seq + ;
578*!* " group by fkey) o " + ;
579*!* " on l.fkey = o.fkey "
580
581 lcSqlNtSeq = " SELECT s.ord_num, s.note_type, s.seq + (s.seq_I - o.seq_offset) as seq " + ;
582 " FROM " + lcNt_seq + " s INNER JOIN " + ;
583 " (SELECT ord_num, MIN(SEQ_I) as seq_offset FROM " + lcNt_seq + ;
584 " GROUP BY ord_num) o " + ;
585 " ON s.ord_num = o.ord_num "
586
587*!* lcSQL = "UPDATE d SET line_seq = l.line_seq FROM " + pcZzoordrd_update + " d INNER JOIN (" + ;
588*!* lcSqlLnSeq + ") l ON l.pkey = d.pkey"
589
590 lcSQL = "UPDATE n SET seq = s.seq FROM " + pcZzoordrh_nt_Update + " n INNER JOIN (" + ;
591 lcSqlNtSeq + ") s ON s.ord_num = n.ord_num and s.note_type = n.note_type "
592
593 llRetVal = llRetVal and v_sqlexec(lcSQL)
594
595 Select(lnOldSelect)
596 Return llRetVal
597
598 Endproc
599
600*-----------------------------------------------------------------------------------------
601
602 PROCEDURE SetOrderDtlNotesSeq(pcZzoordrd_nt_Update)
603
604 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcSqlNtSeq
605 llRetVal = .T.
606 lnOldSelect = Select()
607 lcNt_Seq = "#NotesSeq" + SYS(2015)
608
609 lcSQL = " SELECT n.ORD_NUM, n.line_seq, n.note_type, s.seq INTO " + lcNt_Seq + " FROM " + pcZzoordrd_nt_Update + " n " + ;
610 " INNER JOIN ( SELECT ORD_NUM, line_seq, MAX(seq) + 1 as seq FROM " + pcZzoordrd_nt_Update + " GROUP BY ord_num, line_seq) s " + ;
611 " ON n.ord_num = s.ord_num and n.line_seq = s.line_seq and n.SQL_action = 'I' ORDER BY n.ord_num, n.line_seq "
612
613 llRetVal = llRetVal and v_sqlexec(lcSQL)
614
615*!* lcSQL = " select d.fkey, d.pkey, s.line_seq " + ;
616*!* " into " + lcline_seq + " from " + pcZzoordrd_update + " d inner join " + ;
617*!* " ( select fkey, max(line_seq) + 1 line_seq from " + pcZzoordrd_update + ;
618*!* " group by fkey) s " + ;
619*!* " on d.fkey = s.fkey " + ;
620*!* " where d.sql_action = 'I' " + ;
621*!* " order by d.fkey "
622*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
623
624 lcSQL = "alter table " + lcNt_seq + " add seq_I int identity(1,1) NOT NULL"
625 llRetVal = llRetVal and v_sqlexec(lcSQL)
626
627*!* lcSqlLnSeq = " select l.fkey, l.pkey, " + ;
628*!* " line_seq + (l.line_seq_I - o.line_seq_offset) as line_seq" + ;
629*!* " from " + lcline_seq + " l inner join " + ;
630*!* " (select fkey, min(line_seq_I) as line_seq_offset from " + lcline_seq + ;
631*!* " group by fkey) o " + ;
632*!* " on l.fkey = o.fkey "
633
634 lcSqlNtSeq = " SELECT s.ord_num, s.line_seq, s.note_type, s.seq + (s.seq_I - o.seq_offset) as seq " + ;
635 " FROM " + lcNt_seq + " s INNER JOIN " + ;
636 " (SELECT ord_num, line_seq, MIN(SEQ_I) as seq_offset FROM " + lcNt_seq + ;
637 " GROUP BY ord_num, line_seq) o " + ;
638 " ON s.ord_num = o.ord_num and s.line_seq = o.line_seq "
639
640*!* lcSQL = "UPDATE d SET line_seq = l.line_seq FROM " + pcZzoordrd_update + " d INNER JOIN (" + ;
641*!* lcSqlLnSeq + ") l ON l.pkey = d.pkey"
642
643 lcSQL = "UPDATE n SET seq = s.seq FROM " + pcZzoordrd_nt_Update + " n INNER JOIN (" + ;
644 lcSqlNtSeq + ") s ON s.ord_num = n.ord_num and s.line_seq = n.line_seq and s.note_type = n.note_type "
645
646 llRetVal = llRetVal and v_sqlexec(lcSQL)
647
648 v_sqlexec("drop table " + lcNt_Seq)
649
650 Select(lnOldSelect)
651 Return llRetVal
652
653 Endproc
654
655*-----------------------------------------------------------------------------------------
656
657 PROCEDURE AggregateOnNoteType(pcZzeipcth_nt, pcZzeipcth_nt_aggr)
658
659 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt, lcipcth_nt_aggr
660 llRetVal = .T.
661 lnOldSelect = Select()
662 lnThermoCnt = 0
663 lcIpcth_nt_Cur = "Ipcth_nt" + SYS(2015)
664 lcipcth_nt_aggr = "Ipcth_nt_aggr" + SYS(2015)
665
666 lcSQL = "SELECT * FROM " + pcZzeipcth_nt
667 llRetVal = llRetVal and v_sqlexec(lcSQL,lcIpcth_nt_Cur)
668
669 IF NOT llRetVal
670 Select(lnOldSelect)
671 Return llRetVal
672 ENDIF
673 LOCAL lcOrd_NoteType
674 lcOrd_NoteType = " "
675
676 SELECT (lcIpcth_nt_Cur)
677 INDEX ON ALLTRIM(STR(ord_num)) + note_type TAG Ord_NTtyp
678
679 DIMENSION laFlds[1]
680 AFIELDS(laFlds,lcIpcth_nt_Cur)
681 CREATE CURSOR (lcipcth_nt_aggr) FROM ARRAY laFlds
682
683 LOCAL lcOrd_NTtyp, lcOrd_NTtypPrev, loNt
684 lcOrd_NTtyp = " "
685 lcOrd_NTtypPrev = " "
686 SELECT (lcIpcth_nt_Cur)
687 SCAN
688 SCATTER NAME loNt MEMO
689 lcOrd_NTtyp = ALLTRIM(STR(ord_num)) + note_type
690 IF lcOrd_NTtyp <> lcOrd_NTtypPrev
691 *--- create notes line
692 SELECT(lcipcth_nt_aggr)
693 APPEND BLANK
694 GATHER NAME loNt memo
695 ELSE
696 SELECT (lcipcth_nt_aggr)
697 IF NOT (loNt.notes $ notes)
698 replace notes WITH notes + ALLTRIM(loNt.notes) + CHR(13) + CHR(10) IN (lcipcth_nt_aggr)
699 ENDIF
700 ENDIF
701 lcOrd_NTtypPrev = lcOrd_NTtyp
702 ENDSCAN
703
704 *--- Move the aggregated notes back to server.
705 SELECT(lcipcth_nt_aggr)
706 this.cSQLTempTable = ""
707 llRetVal = llRetVal and this.GenerateSQLTempTable(lcipcth_nt_aggr)
708 IF RECCOUNT(lcipcth_nt_aggr) > 0
709 llRetVal = llRetVal and this.PopulateSQLTempTable(lcipcth_nt_aggr)
710 ENDIF
711 llRetVal = llRetVal and v_sqlexec("SELECT * INTO " + pcZzeipcth_nt_aggr + " FROM " + this.cSQLTempTable)
712 v_sqlexec("drop table " + this.cSQLTempTable)
713 Select(lnOldSelect)
714 Return llRetVal
715
716 Endproc
717
718*-----------------------------------------------------------------------------------------
719
720 PROCEDURE CreateOrderDetailNotes(pcZzeipctd, pcZzoordrd_update, pcZzeipctd_nt,pcZzoordrd_nt_orig,pcZzoordrd_nt_Update)
721
722 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt,lcipctd_nt_aggr
723 llRetVal = .T.
724 lnOldSelect = Select()
725 lnThermoCnt = 0
726 lcipctd_nt_aggr = "#Zzeipctd_nt" + SYS(2015)
727 *--- aggregate transaction notes to match with order detail notes.
728 llRetVal = llRetVal and this.AggregateOnDetailNoteType(pcZzeipctd_nt, lcipctd_nt_aggr)
729
730 *--- create notes update temp tables
731 llRetVal = llRetVal and v_sqlexec("select * into " + pcZzoordrd_nt_Update + " FROM " + lcipctd_nt_aggr + " WHERE 1=2")
732 llRetVal = llRetVal and v_sqlexec("Alter table " + pcZzoordrd_nt_Update + " add SQL_Action char(1) default('') not null")
733
734 *--- add notes that exists order and detail line.
735
736 *--- update : - Adding notes to existing notes for same Notes Type
737 lcFlds = ""
738 lcValues = ""
739 lcExcludeFlds = "'SQL_action','notes'"
740 lcCalFlds = "SQL_action, notes"
741 lcCalFldsValues = "'U', CAST(odn.notes as varchar(2000)) + CAST(COALESCE(tdn.notes,'') as varchar(2000))"
742
743 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_nt_Update , pcZzoordrd_nt_orig, ;
744 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'odn')
745
746 lcSQL = " INSERT INTO " + pcZzoordrd_nt_Update + " ( " + lcFlds + " ) " + ;
747 " SELECT " + lcValues + " FROM " + pcZzoordrd_nt_orig + " odn LEFT OUTER JOIN " + lcipctd_nt_aggr + " tdn " + ;
748 " ON tdn.ord_num = odn.ord_num and tdn.note_type = odn.note_type and tdn.division = odn.division " + ;
749 " AND tdn.style = odn.style AND tdn.color_code = odn.color_code and tdn.lbl_code = odn.lbl_code " + ;
750 " AND tdn.dimension = odn.dimension "
751
752 llRetVal = llRetVal and v_sqlexec(lcSQL)
753
754 *--- Insert : - New notes to order
755 lcFlds = ""
756 lcValues = ""
757 lcExcludeFlds = "'SQL_action','table_name','line_seq', 'fkey','parentkey','seq'"
758 lcCalFlds = "SQL_action,table_name,line_seq,fkey,parentkey,seq"
759 lcCalFldsValues = "'I','ZZOORDRD',d.line_seq, d.pkey,d.fkey,0"
760
761 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_nt_Update , lcipctd_nt_aggr, ;
762 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'tdn')
763
764 lcSQL = " INSERT INTO " + pcZzoordrd_nt_Update + " ( " + lcFlds + " ) " + ;
765 " SELECT " + lcValues + " FROM " + lcipctd_nt_aggr + " tdn " + ;
766 " INNER JOIN " + pcZzoordrd_update + " d ON d.ord_num = tdn.ord_num " + ;
767 " and d.division = tdn.division and d.style = tdn.style and d.color_code = tdn.color_code " + ;
768 " and d.lbl_code = tdn.lbl_code and d.dimension = tdn.dimension and d.sql_action <> 'D'" + ;
769 " AND d.line_status = 'O' " + ;
770 " WHERE NOT EXISTS (SELECT * FROM " + pcZzoordrd_nt_orig + " odn " + ;
771 " WHERE tdn.ord_num = odn.ord_num and tdn.note_type = odn.note_type " + ;
772 " and tdn.division = odn.division and tdn.style = odn.style " + ;
773 " and tdn.color_code = odn.color_code and tdn.lbl_code = odn.lbl_code " + ;
774 " and tdn.dimension = odn.dimension ) "
775
776 llRetVal = llRetVal and v_sqlexec(lcSQL)
777
778*!* *--- only take ord_status = 'O' because the link between notes header and order header is base on ord_num only
779*!* lcSQL = " Update nh SET fkey = h.pkey FROM " + pcZzoordrd_nt_Update + " nh INNER JOIN " + pcZzoordrd_Update + " h " + ;
780*!* " ON nh.ord_num = h.ord_num and h.ord_status = 'O' "
781*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
782
783 *--- set Pkey
784 llRetVal = llRetVal and this.SetOrderDtlNotePkey(pcZzoordrd_nt_Update)
785
786 *--- Set Seq
787 llRetVal = llRetVal and this.SetOrderDtlNotesSeq(pcZzoordrd_nt_Update)
788
789 lcSQL = "UPDATE d SET hasnotes = 'Y' FROM " + pcZzoordrd_update + " d INNER JOIN " + pcZzoordrd_nt_Update + ;
790 " n ON n.ord_num = d.ord_num and n.line_seq = d.line_seq and n.table_name = 'ZZOORDRD'"
791 llRetVal = llRetVal and v_sqlexec(lcSQL)
792
793 Select(lnOldSelect)
794 Return llRetVal
795
796 Endproc
797
798*-----------------------------------------------------------------------------------------
799
800 PROCEDURE AggregateOnDetailNoteType(pcZzeipctd_nt, pcipctd_nt_aggr)
801
802 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt, lcipctd_nt_aggr
803 llRetVal = .T.
804 lnOldSelect = Select()
805 lnThermoCnt = 0
806 lcIpctd_nt_Cur = "Ipctd_nt" + SYS(2015)
807 lcIpctd_nt_aggr = "Ipctd_nt_aggr" + SYS(2015)
808
809 lcSQL = "SELECT * FROM " + pcZzeIpctd_nt
810 llRetVal = llRetVal and v_sqlexec(lcSQL,lcIpctd_nt_Cur)
811
812 IF NOT llRetVal
813 Select(lnOldSelect)
814 Return llRetVal
815 ENDIF
816 LOCAL lcOrd_NoteType
817 lcOrd_NoteType = ""
818
819 SELECT (lcIpctd_nt_Cur)
820 INDEX ON ALLTRIM(STR(ord_num)) + division + style + color_code + lbl_code + dimension + note_type TAG Ord_ntGrp
821
822 DIMENSION laFlds[1]
823 AFIELDS(laFlds,lcIpctd_nt_Cur)
824 CREATE CURSOR (lcIpctd_nt_aggr) FROM ARRAY laFlds
825
826 LOCAL lcOrd_NTgrp, lcOrd_NTgrpPrev, loNt
827 lcOrd_NTgrp = " "
828 lcOrd_NTgrpPrev = " "
829 SELECT (lcIpctd_nt_Cur)
830 SCAN
831 SCATTER NAME loNt memo
832 lcOrd_NTgrp = ALLTRIM(STR(ord_num)) + division + style + color_code + lbl_code + dimension + note_type
833 IF lcOrd_NTgrp != lcOrd_NTgrpPrev
834 *--- create notes line
835 SELECT(lcIpctd_nt_aggr)
836 APPEND BLANK
837 GATHER NAME loNt memo
838 ELSE
839 SELECT (lcIpctd_nt_aggr)
840 IF NOT (loNt.notes $ notes)
841 replace notes WITH notes + ALLTRIM(loNt.notes) + CHR(13) + CHR(10) IN (lcIpctd_nt_aggr)
842 ENDIF
843 ENDIF
844 lcOrd_NTgrpPrev = lcOrd_NTgrp
845 ENDSCAN
846
847 *--- Move the aggregated notes back to server.
848 SELECT(lcIpctd_nt_aggr)
849
850 this.cSQLTempTable = ""
851 llRetVal = llRetVal and this.GenerateSQLTempTable(lcIpctd_nt_aggr)
852 IF RECCOUNT(lcIpctd_nt_aggr) > 0
853 llRetVal = llRetVal and this.PopulateSQLTempTable(lcIpctd_nt_aggr)
854 ENDIF
855 llRetVal = llRetVal and v_sqlexec("SELECT * INTO " + pcipctd_nt_aggr + " FROM " + this.cSQLTempTable)
856
857 v_sqlexec("drop table " + this.cSQLTempTable)
858
859 Select(lnOldSelect)
860 Return llRetVal
861
862 Endproc
863
864*-----------------------------------------------------------------------------------------
865
866 PROCEDURE PrepareSalesOrderTable_DateChange(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update)
867
868 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
869 llRetVal = .T.
870 lnOldSelect = Select()
871 lnThermoCnt = 0
872
873 *--- Date change detail line item - start_date and end_date
874 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
875 LOCAL lcFlds, lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
876 llRetVal = .T.
877 lnOldSelect = Select()
878 lnThermoCnt = 0
879
880 *--- TR 1035409 insert orders those are not in pcZzoordrh_update
881 *--- insert order header into pcZzoordrh_update if there is no record
882 llRetVal = llRetVal and this.AddOrderHdrToUpdateTbl(pcZzeipcth,pcZzoordrh_Update,pcZzoordrd_update)
883 *=== TR 1035409
884
885 *---- update start date
886 lcSQL = " UPDATE od SET Start_date = td.start_date " + ;
887 " FROM " + pcZzoordrd_update + " od INNER JOIN " + pcZzeipctd + " td ON od.ord_num = td.ord_num " + ;
888 " and od.division = td.division and od.style = td.style and od.color_code = od.color_code " + ;
889 " and od.lbl_code = td.lbl_code and od.dimension = td.dimension and od.line_status = 'O' " + ;
890 " WHERE td.qualifier = 'CT' AND td.start_date > {ts '1900-01-01 12:00:00.000'} "
891 llRetVal = llRetVal and v_sqlexec(lcSQL)
892
893 *---- update end date
894 lcSQL = " UPDATE od SET End_date = td.End_date " + ;
895 " FROM " + pcZzoordrd_update + " od INNER JOIN " + pcZzeipctd + " td ON od.ord_num = td.ord_num " + ;
896 " and od.division = td.division and od.style = td.style and od.color_code = od.color_code " + ;
897 " and od.lbl_code = td.lbl_code and od.dimension = td.dimension and od.line_status = 'O' " + ;
898 " WHERE td.qualifier = 'CT' AND td.End_date > {ts '1900-01-01 12:00:00.000'} "
899 llRetVal = llRetVal and v_sqlexec(lcSQL)
900
901 *---- update header with ealiest detail start/end dates
902 lcSQL = " UPDATE oh SET Start_date = od.start_date, End_date = od.End_date " + ;
903 " FROM " + pcZzoordrh_update + " oh " + ;
904 " INNER JOIN (SELECT d.ord_num, MIN(d.start_date) as start_date, MIN(d.end_date) as end_date " + ;
905 " FROM " + pcZzoordrd_update + " d WHERE d.line_status = 'O' GROUP BY d.ord_num ) od " + ;
906 " ON od.ord_num = oh.ord_num " + ;
907 " WHERE oh.ord_status = 'O' "
908
909 llRetVal = llRetVal and v_sqlexec(lcSQL)
910
911 *--- start_date change - header
912 *--- check only for empty start and end dates - other validations are done previously
913
914 lcSQL = " UPDATE oh SET start_date = th.start_date " + ;
915 " FROM " + pcZzoordrh_update + " oh " + ;
916 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
917 " WHERE th.poc_purp = '04' and th.start_date > {ts '1900-01-01 12:00:00.000'} "
918
919 llRetVal = llRetVal and v_sqlexec(lcSQL)
920
921 lcSQL = " UPDATE oh SET end_date = th.end_date " + ;
922 " FROM " + pcZzoordrh_update + " oh " + ;
923 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
924 " WHERE th.poc_purp = '04' and th.end_date > {ts '1900-01-01 12:00:00.000'} "
925
926 llRetVal = llRetVal and v_sqlexec(lcSQL)
927
928 *--- TR 1073302 23-Oct-2013 Bnarayanan update the start and end date ---
929 lcSQL = " UPDATE od SET Start_date = th.start_date " + ;
930 " FROM " + pcZzoordrd_update + " od "+ ;
931 " INNER JOIN " + pcZzeipcth + " th ON od.ord_num = th.ord_num " + ;
932 " WHERE od.line_status = 'O' AND th.poc_purp = '04' and th.start_date > {ts '1900-01-01 12:00:00.000'} "
933
934 llRetVal = llRetVal and v_sqlexec(lcSQL)
935
936 lcSQL = " UPDATE od SET End_date = th.End_date " + ;
937 " FROM " + pcZzoordrd_update + " od " + ;
938 " INNER JOIN " + pcZzeipcth + " th ON od.ord_num = th.ord_num " + ;
939 " WHERE od.line_status = 'O' AND th.poc_purp = '04' and th.End_date > {ts '1900-01-01 12:00:00.000'} "
940 llRetVal = llRetVal and v_sqlexec(lcSQL)
941 *=== TR 1073302 23-Oct-2013 Bnarayanan ===
942
943*- TR 1070064 FH- taking out the cascade, read dev note.
944 *--- finally cascade header start_date and end_date to all details
945*!* lcSQL = " UPDATE od SET start_date = oh.start_date, end_date = oh.end_date " + ;
946*!* " FROM " + pcZzoordrh_update + " oh " + ;
947*!* " INNER JOIN " + pcZzoordrd_update + " od ON oh.ord_num = od.ord_num " + ;
948*!* " WHERE oh.ord_status = 'O' AND od.line_status = 'O' "
949*!*
950*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
951*- TR 1070064 FH- taking out the cascade, read dev note.
952
953 Select(lnOldSelect)
954 Return llRetVal
955
956 ENDPROC
957
958*-----------------------------------------------------------------------------------------
959
960 *--- TR 1035409 nh
961 PROCEDURE AddOrderHdrToUpdateTbl(pcZzeipcth,pcZzoordrh_Update,pcZzoordrd_update)
962
963 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
964
965 *--- TR 1072834 20-Aug-2013 Goutam
966 LOCAL lcWarnCondition
967 *=== TR 1072834 20-Aug-2013 Goutam
968
969 llRetVal = .T.
970 lnOldSelect = Select()
971 lnThermoCnt = 0
972
973 LOCAL lcFlds, lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
974 lcFlds = ""
975 lcValues = ""
976 lcExcludeFlds = "'SQL_action'"
977 lcCalFlds = "SQL_action"
978 lcCalFldsValues = "'U'" && keep the sign negative for reduction of quantity
979
980 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update,"zzoordrh" , lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"oh")
981
982 *--- TR 1072834 20-Aug-2013 Goutam
983 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
984 *=== TR 1072834 20-Aug-2013 Goutam
985
986 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
987 lcSql = " select oh.* from zzoordrh oh (nolock) " + ;
988 " where exists ( select td.pkey from " + pcZzoordrd_update + " td " + ;
989 " where td.ord_num = oh.ord_num and td.line_status = oh.ord_status and td.line_status = 'O') " + ;
990 " and not exists ( select h.pkey from " + pcZzoordrh_Update + " h " + ;
991 " where h.ord_num = oh.ord_num and h.ord_status = oh.ord_status and h.ord_status = 'O') " + ;
992 " and oh.ord_status = 'O'" + ;
993 " and exists (select th.pkey from " + pcZzeipcth + " th where th.ord_num = oh.ord_num and th.errs_flg_h <> 'Y' " + lcWarnCondition + " )"
994
995 lcSQL = Strtran(lcSQL, "oh.*",lcValues)
996 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
997 llRetVal = llRetVal And v_SQLExec(lcSQL)
998
999 Select(lnOldSelect)
1000 Return llRetVal
1001
1002 ENDPROC
1003 *=== TR 1035409 nh
1004
1005*-----------------------------------------------------------------------------------------
1006
1007 PROCEDURE PrepareSalesOrderTable_PriceChange(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_Update, pcZzoordrd_update)
1008
1009 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
1010
1011 *--- TR 1072834 20-Aug-2013 Goutam
1012 LOCAL lcWarnCondition
1013 *=== TR 1072834 20-Aug-2013 Goutam
1014
1015 llRetVal = .T.
1016 lnOldSelect = Select()
1017 lnThermoCnt = 0
1018
1019*!* CASE tcEiPCtd.POC_Cost <> 0
1020*!* IF NOT .lOneDetailLineBad
1021*!* REPLACE Price WITH tcEiPCtd.POC_Cost IN Vzzoordrd_860I
1022*!* .lUpdateSalesOrder = .T.
1023*!* .lDelete860Records = .T.
1024*!* ENDIF
1025*!* CASE tcEiPCtd.POC_Price <> 0
1026*!* IF NOT .lOneDetailLineBad
1027*!* REPLACE Retail1 WITH tcEiPCtd.POC_Price IN Vzzoordrd_860I
1028*!* .lUpdateSalesOrder = .T.
1029*!* .lDelete860Records = .T.
1030*!* ENDIF
1031
1032 *--- TR 1034532 NH
1033 LOCAL lcAddJoin
1034 IF EMPTY(this.c860SODetailAddMatchCriteria)
1035 lcAddJoin = ""
1036 ELSE
1037 lcAddJoin = " and td.LINE_ID = od." + THIS.c860SODetailAddMatchCriteria
1038 ENDIF
1039 *=== TR 1034532 NH
1040
1041 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1042 llRetVal = .T.
1043 lnOldSelect = Select()
1044
1045 lcSQL = " UPDATE od SET Price = case when td.Poc_Cost > 0 then td.Poc_Cost else od.Price end " + ;
1046 " , Retail1 = case when td.Poc_Price > 0 then td.Poc_Price else od.Retail1 end " + ;
1047 " , Retail2 = case when td.Poc_Retail2 > 0 then td.Poc_Retail2 else od.Retail2 end " + ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1048 " FROM " + pcZzoordrd_update + " od INNER JOIN " + pcZzeipctd + " td ON od.ord_num = td.ord_num " + ;
1049 " and od.style = td.style and od.color_code = td.color_code and od.lbl_code = td.lbl_code " + ;
1050 " and od.dimension = td.dimension " + lcAddJoin + ;
1051 " WHERE td.qualifier = 'PC' "
1052
1053 llRetVal = llRetVal and v_sqlexec(lcSQL)
1054 *--- make sure the order header is also exists
1055*!* SELECT oh.* FROM #Zzoordrh_orig oh INNER JOIN ( SELECT ORD_NUM, SUM(size_qty) as ord_qty FROM #Zzoordrdv_update dvu
1056*!* WHERE dvu.size_qty < 0 AND dvu.line_status = 'O' group by dvu.ord_num) d ON oh.ord_num = d.ord_num AND oh.ord_status = 'O'
1057
1058 *--- TR 1032802 insert orders those are not in pcZzoordrh_update
1059 LOCAL lcFlds, lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
1060 lcFlds = ""
1061 lcValues = ""
1062 lcExcludeFlds = "'SQL_action'"
1063 lcCalFlds = "SQL_action"
1064 lcCalFldsValues = "'U'" && keep the sign negative for reduction of quantity
1065
1066 *--- TR 1072834 20-Aug-2013 Goutam
1067 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
1068 *=== TR 1072834 20-Aug-2013 Goutam
1069
1070 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update,"zzoordrh" , lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"oh")
1071
1072 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
1073 lcSql = " select oh.* from zzoordrh oh " + ;
1074 " where exists ( select td.pkey from " + pcZzoordrd_update + " td " + ;
1075 " where td.ord_num = oh.ord_num and td.line_status = oh.ord_status and td.line_status = 'O') " + ;
1076 " and not exists ( select h.pkey from " + pcZzoordrh_Update + " h " + ;
1077 " where h.ord_num = oh.ord_num and h.ord_status = oh.ord_status and h.ord_status = 'O') " + ;
1078 " and oh.ord_status = 'O'" + ;
1079 " and exists (select th.pkey from " + pcZzeipcth + " th where th.ord_num = oh.ord_num and th.errs_flg_h <> 'Y' " + lcWarnCondition + ")"
1080
1081 lcSQL = Strtran(lcSQL, "oh.*",lcValues)
1082 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
1083 llRetVal = llRetVal And v_SQLExec(lcSQL)
1084
1085 Select(lnOldSelect)
1086 Return llRetVal
1087
1088 ENDPROC
1089
1090*-----------------------------------------------------------------------------------------
1091
1092 PROCEDURE PrepareForFinalUpdate(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update, pcZzoordrdv_update,pcZzoordsp_update)
1093
1094 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
1095 llRetVal = .T.
1096 lnOldSelect = Select()
1097 lnThermoCnt = 0
1098 *--- set pkey for all insert Header and detail except delete records
1099 *--- set fkey for all dtl base on ord_num and ord status
1100 *--- TR 1036847 DEC-09-2008 BR - CHANGED InitThermoWithCaption count from 9 to 10
1101 this.InitThermoWithCaption(lnThermoCnt,10,"Prepare order for final update.")
1102
1103 llRetVal = llRetVal and this.SetOrderHdrPkey(pcZzoordrh_Update,pcZzoordrd_update)
1104 this.LogEntry("Update new order pkey and cascade to related detail fkey " + IIF(llRetVal,"completed.","failed."))
1105 this.AdvanceThermoPlus(@lnThermoCnt)
1106
1107 llRetVal = llRetVal and this.SetOrderDtlPkey(pcZzoordrd_update)
1108 this.LogEntry("Update new order detail pkey " + IIF(llRetVal,"completed.","failed."))
1109 this.AdvanceThermoPlus(@lnThermoCnt)
1110
1111 llRetVal = llRetVal and this.SetOrderSpPkey(pcZzoordsp_update)
1112 this.LogEntry("Update new order carton link table pkey " + IIF(llRetVal,"completed.","failed."))
1113 this.AdvanceThermoPlus(@lnThermoCnt)
1114
1115 *--- SET proper fkey to details for SQL_action = 'U'
1116 llRetVal = llRetVAl and THIS.SetFkeyValuesToDtl(pcZzoordrh_Update,pcZzoordrd_update)
1117 this.LogEntry("Update new order detail fkey for existing order " + IIF(llRetVal,"completed.","failed."))
1118 this.AdvanceThermoPlus(@lnThermoCnt)
1119
1120 llRetVal = llRetVal and this.SetLineSeq(pcZzoordrd_update)
1121 this.LogEntry("Update new order detail line sequence " + IIF(llRetVal,"completed.","failed."))
1122 this.AdvanceThermoPlus(@lnThermoCnt)
1123
1124 *- 1048785 FH 08/16/10 - set next_line in header to max(line_seq) of DTL +1
1125 llRetVal = llRetVal and this.UpdateNextLine(pcZzoordrh_Update,pcZzoordrd_update)
1126 this.LogEntry("Update next line in header " + IIF(llRetVal,"completed.","failed."))
1127 this.AdvanceThermoPlus(@lnThermoCnt)
1128 *=== 1048785 FH
1129
1130 *--- set cancel number
1131 llRetVal = llRetVal and this.SetCancelNumber(pcZzoordrh_Update)
1132 this.LogEntry("Update cancel order number " + IIF(llRetVal,"completed.","failed."))
1133 this.AdvanceThermoPlus(@lnThermoCnt)
1134
1135 *--- set cancel reason
1136 llRetVal = llRetVal and this.SetCancelReasonAndType(pcZzoordrh_Update,pcZzoordrd_update)
1137 this.LogEntry("Update cancel order number " + IIF(llRetVal,"completed.","failed."))
1138 this.AdvanceThermoPlus(@lnThermoCnt)
1139
1140 *--- set price
1141 llRetVal = llRetVal and this.SetPrice(pcZzoordrh_Update,pcZzoordrd_update,pcZzeipctd)
1142 this.LogEntry("Update order detail line item price " + IIF(llRetVal,"completed.","failed."))
1143 this.AdvanceThermoPlus(@lnThermoCnt)
1144
1145 *--- Resolve delivery Code
1146 llRetVal = llRetVal and this.SetDelvCodeForQualifierAI(pcZzoordrh_Update,pcZzoordrd_update,pcZzeipctd)
1147 this.AdvanceThermoPlus(@lnThermoCnt)
1148
1149 *--- TR 1058034 23-Nov-2011 Goutam
1150 *--- set price code
1151 llRetVal = llRetVal and this.SetPriceCode(pcZzoordrh_Update, pcZzeipcth)
1152 this.LogEntry("Update order header price code" + IIF(llRetVal,"completed.","failed."))
1153 this.AdvanceThermoPlus(@lnThermoCnt)
1154 *=== TR 1058034 23-Nov-2011 Goutam
1155
1156 *--- TR 1062197 7-Sep-2012 Goutam
1157 *--- set poc_store in store
1158 llRetVal = llRetVal and this.SetPOCStore(pcZzoordrh_Update, pcZzeipcth)
1159 this.LogEntry("Update order header Store code based on POC Store" + IIF(llRetVal,"completed.","failed."))
1160 this.AdvanceThermoPlus(@lnThermoCnt)
1161
1162 *--- set consolidator
1163 llRetVal = llRetVal and this.SetConsolidatorNCentercode(pcZzoordrh_Update, pcZzeipcth)
1164 this.LogEntry("Update order header Consolidator based on POC Shipto" + IIF(llRetVal,"completed.","failed."))
1165 this.AdvanceThermoPlus(@lnThermoCnt)
1166
1167 *=== TR 1062197 7-Sep-2012 Goutam
1168
1169 *--- Cascade header fields
1170 llRetVal = llRetVal and this.CascadeHeaderFields(pcZzoordrh_Update,pcZzoordrd_update) && TR 1036847 DEC-09-2008 BR
1171 this.AdvanceThermoPlus(@lnThermoCnt)
1172
1173 *--- Time Stamp and User id
1174 llRetVal = llRetVal and this.SetUserIdAndTimeStamp(pcZzoordrh_Update)
1175 llRetVal = llRetVal and this.SetUserIdAndTimeStamp(pcZzoordrd_update)
1176 llRetVal = llRetVal and this.SetUserIdAndTimeStamp(pcZzeipcth)
1177 llRetVal = llRetVal and this.SetUserIdAndTimeStamp(pcZzeipctd)
1178
1179 Select(lnOldSelect)
1180 Return llRetVal
1181
1182 Endproc
1183
1184*-----------------------------------------------------------------------------------------
1185
1186 PROCEDURE SetUserIdAndTimeStamp(pcTbl)
1187
1188 Local llRetVal, lnOldSelect,lcSQL
1189 llRetVal = .T.
1190 lnOldSelect = Select()
1191
1192 lcSQL = "UPDATE h SET last_mod = convert(datetime,convert(char,getdate(),120))," + ;
1193 " user_id = '" + goEnv.cUser + "' FROM " + pcTbl + " h "
1194 llRetVal = llRetVal and v_sqlexec(lcSQL)
1195
1196 Select(lnOldSelect)
1197 Return llRetVal
1198
1199 Endproc
1200
1201*-----------------------------------------------------------------------------------------
1202
1203 PROCEDURE SetPrice(pcZzoordrh_update, pcZzoordrd_update,pcZzeipctd)
1204 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1205 llRetVal = .T.
1206 lnOldSelect = Select()
1207
1208*!* Replace ;
1209*!* Cncl_Date WITH tcEiPCth.Cncl_Date, ;
1210*!* STYLE WITH tcEiPCtd.STYLE, ;
1211*!* color_code WITH tcEiPCtd.color_code, ;
1212*!* lbl_code WITH tcEiPCtd.lbl_code, ;
1213*!* DIMENSION WITH tcEiPCtd.DIMENSION, ;
1214*!* Org_Price WITH tcEiPCtd.Org_Price, ;
1215*!* line_seq WITH tnMaxOrdrdLine_seq, ;
1216*!* LINE_STATUS WITH Vzzoordrh_860I.Ord_status, ;
1217*!* Price WITH tcEiPCtd.poc_cost, ; && TR 1016560 NH :For AI item price needs to be populated by poc_price
1218*!* Total_Qty WITH 0 ;
1219*!* IN Vzzoordrd_860I
1220
1221 *--- UPDATE PRICE for qualifier "AI"
1222 *--- TechRec 1054692 21-Sep-2011 jisingh Added , Retail2 = td.POC_Retail2 ===
1223
1224 lcSQL = " UPDATE d SET price = td.poc_cost, Org_Price = td.Org_Price, Retail1 = td.POC_Price, Retail2 = td.POC_Retail2 " +;
1225 " FROM " + pcZzoordrd_update + " d " + ;
1226 " INNER JOIN " + pcZzeipctd + " td on d.ord_num = td.ord_num and d.division = td.division " + ;
1227 " and d.style = td.style and d.color_code = td.color_code and d.lbl_code = td.lbl_code " + ;
1228 " and d.dimension = td.dimension " + ;
1229 " WHERE d.line_status = 'O' and d.Sql_action = 'I' and td.qualifier IN ('AI','QI') "
1230 llRetVal = llRetVal and v_sqlexec(lcSQL)
1231
1232 *--- Update price for qualifier "PC"
1233 lcSQL = " UPDATE d SET price = CASE WHEN td.poc_cost > 0 THEN td.poc_cost ELSE d.price END " + ;
1234 " , Org_Price = CASE WHEN td.Org_Price > 0 THEN td.Org_Price ELSE d.Org_Price END " + ;
1235 " , Retail1 = CASE WHEN td.POC_Price > 0 THEN td.POC_Price ELSE td.POC_Price END " +;
1236 " , Retail2 = CASE WHEN td.POC_Retail2 > 0 THEN td.POC_Retail2 ELSE d.Retail2 END " +; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1237 " FROM " + pcZzoordrd_update + " d " + ;
1238 " INNER JOIN " + pcZzeipctd + " td on d.ord_num = td.ord_num and d.division = td.division " + ;
1239 " and d.style = td.style and d.color_code = td.color_code and d.lbl_code = td.lbl_code " + ;
1240 " and d.dimension = td.dimension " + ;
1241 " WHERE d.line_status = 'O' and td.qualifier IN ('PC', 'RZ') "
1242
1243 llRetVal = llRetVal and v_sqlexec(lcSQL)
1244
1245 *--- set detail line item price for new store order from existing order
1246 llRetVal = llRetVal and this.UpdatePriceForNewStoreDetails(pcZzoordrh_update, pcZzoordrd_update,pcZzeipctd)
1247
1248 Select(lnOldSelect)
1249 Return llRetVal
1250
1251 Endproc
1252
1253*-----------------------------------------------------------------------------------------
1254
1255 PROCEDURE UpdatePriceForNewStoreDetails(pcZzoordrh_update, pcZzoordrd_update,pcZzeipctd)
1256
1257 Local llRetVal, lnOldSelect, lcSQL
1258 llRetVal = .T.
1259 lnOldSelect = Select()
1260
1261 *--- Update Price for qualifier "AI", "QI", "RZ" and new store flag is 'Y'
1262 *--- first take from zzoordrd.price
1263 *--- second if zzoordrd.price is zero take from zzeipctd
1264
1265 lcSql = " UPDATE d SET " + ;
1266 " price = case when d.price = 0 and coalesce(od.price,0) > 0 then od.price " + ;
1267 " when d.price = 0 and td.poc_cost > 0 then td.poc_cost " + ;
1268 " else d.price end " + ;
1269 " , org_price = case when d.org_price = 0 and coalesce(od.org_price,0) > 0 then od.org_price " + ;
1270 " when d.org_price = 0 and td.org_price > 0 then td.org_price " + ;
1271 " else d.org_price end " + ;
1272 " , retail1 = case when d.retail1 = 0 and coalesce(od.Retail1,0) > 0 then od.Retail1 " + ;
1273 " when d.retail1 = 0 and td.POC_Price > 0 then td.POC_Price " + ;
1274 " else d.retail1 end " + ;
1275 " , retail2 = case when d.retail2 = 0 and coalesce(od.Retail2,0) > 0 then od.Retail2 " + ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1276 " when d.retail2 = 0 and td.POC_Retail2 > 0 then td.POC_Retail2 " + ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1277 " else d.retail2 end " + ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1278 " FROM " + pcZzoordrd_update + " d " + ;
1279 " INNER JOIN " + pcZzoordrh_update + " h ON h.pkey = d.fkey " + ;
1280 " INNER JOIN zzoordrh oh (nolock) ON oh.po_num = h.po_num and oh.customer = h.customer " + ;
1281 " LEFT OUTER JOIN zzoordrd od (nolock) ON od.fkey = oh.pkey and d.style = od.style " + ;
1282 " and d.color_code = od.color_code and d.lbl_code = od.lbl_code " + ;
1283 " and d.dimension = od.dimension " + ;
1284 " INNER JOIN " + pcZzeipctd + " td ON td.ord_num = d.ord_num " + ;
1285 " and td.style = d.style and td.color_code = d.color_code and td.lbl_code = d.lbl_code " + ;
1286 " and td.dimension = d.dimension " + ;
1287 " and (td.qualifier in ('QI','AI') OR (td.qualifier = 'RZ' and td.qty_change > 0 ))" + ;
1288 " INNER JOIN zzeipccr r ON r.customer = h.customer and r.division = h.division " + ;
1289 " and r.new_order = 'Y' "
1290
1291 llRetVal = llRetVal and v_sqlexec(lcSQL)
1292
1293 Select(lnOldSelect)
1294 Return llRetVal
1295
1296 Endproc
1297
1298*-----------------------------------------------------------------------------------------
1299
1300 PROCEDURE SetLineSeq(pcZzoordrd_update)
1301
1302 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcline_seq
1303 llRetVal = .T.
1304 lnOldSelect = Select()
1305 lcline_seq = "#line_seq" + SYS(2015)
1306 *--- create table with ord_num and max line seq
1307 *--- create table with ord_num, style, color_code, lbl_code, dimension, line_seq_I
1308 *--- Tejas's idea to take out offset from identity column to get order level line sequence
1309 *--- For cancel line item line seq will not change from open order line seq and
1310 *--- line seq can be duplicated in cancel stage
1311
1312 lcSQL = " select d.fkey, d.pkey, s.line_seq " + ;
1313 " into " + lcline_seq + " from " + pcZzoordrd_update + " d inner join " + ;
1314 " ( select fkey, max(line_seq) + 1 line_seq from " + pcZzoordrd_update + ;
1315 " group by fkey) s " + ;
1316 " on d.fkey = s.fkey " + ;
1317 " where d.sql_action = 'I' and d.line_status <> 'C' " + ;
1318 " order by d.fkey "
1319 llRetVal = llRetVal and v_sqlexec(lcSQL)
1320
1321 lcSQL = "alter table " + lcline_seq + " add line_seq_I int identity(1,1) NOT NULL"
1322 llRetVal = llRetVal and v_sqlexec(lcSQL)
1323
1324 lcSqlLnSeq = " select l.fkey, l.pkey, " + ;
1325 " line_seq + (l.line_seq_I - o.line_seq_offset) as line_seq" + ;
1326 " from " + lcline_seq + " l inner join " + ;
1327 " (select fkey, min(line_seq_I) as line_seq_offset from " + lcline_seq + ;
1328 " group by fkey) o " + ;
1329 " on l.fkey = o.fkey "
1330
1331 lcSQL = "UPDATE d SET line_seq = l.line_seq FROM " + pcZzoordrd_update + " d INNER JOIN (" + ;
1332 lcSqlLnSeq + ") l ON l.pkey = d.pkey"
1333 llRetVal = llRetVal and v_sqlexec(lcSQL)
1334
1335 Select(lnOldSelect)
1336 Return llRetVal
1337
1338 Endproc
1339
1340*-----------------------------------------------------------------------------------------
1341
1342 *- 1048785 FH 08/16/10 - set next_line in header to max(line_seq) of DTL +1
1343 PROCEDURE UpdateNextLine(pcZzoordrh_update,pcZzoordrd_update)
1344
1345 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lcNextLine
1346 llRetVal = .T.
1347 lnOldSelect = Select()
1348 lcNextLine = "#line" + SYS(2015)
1349
1350 lcSQL = " select fkey, MAX(line_seq) + 1 as line_seq into " + lcNextLine + ;
1351 " from " + pcZzoordrd_update + " where line_status = 'O'" +;
1352 " group by fkey "
1353
1354 llRetVal = llRetVal and v_sqlexec(lcSQL)
1355
1356 lcSQL = " update h set h.next_line = l.line_seq from "+ pcZzoordrh_update +" h" +;
1357 " inner join "+ lcNextLine + " l on h.pkey = l.fkey"
1358
1359 llRetVal = llRetVal and v_sqlexec(lcSQL)
1360
1361 Select(lnOldSelect)
1362 Return llRetVal
1363
1364 Endproc
1365
1366*-----------------------------------------------------------------------------------------
1367
1368 PROCEDURE SetCancelNumber(pcZzoordrh_Update)
1369
1370 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1371 llRetVal = .T.
1372 lnOldSelect = Select()
1373
1374 lcSQL = "Update h SET cncl_num = h.ord_num from " + pcZzoordrh_Update + " h where SQL_action = 'I'" + ;
1375 " and h.ord_status = 'C'"
1376
1377 llRetVal = llRetVal and v_sqlExec(lcSQL)
1378
1379 Select(lnOldSelect)
1380 Return llRetVal
1381
1382 Endproc
1383
1384*-----------------------------------------------------------------------------------------
1385
1386 PROCEDURE SetCancelReasonAndType(pcZzoordrh_Update,pcZzoordrd_update)
1387
1388 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1389 llRetVal = .T.
1390 lnOldSelect = Select()
1391
1392 lcSQL = " Update d SET cncl_rsn = r.cncl_rsn, cncl_type = r.cncl_type, " + ;
1393 " cncl_date = convert(datetime,convert(char,getdate(),101)) from " + pcZzoordrd_Update + " d " + ;
1394 " INNER JOIN " + pcZzoordrh_Update + " h ON h.ord_num = d.ord_num " + ;
1395 " INNER JOIN zzeipccr r ON r.customer = h.customer and r.division = h.division " + ;
1396 " Where d.SQL_action in ('I', 'U') and d.line_status = 'C'"
1397
1398 llRetVal = llRetVal and v_sqlExec(lcSQL)
1399
1400 Select(lnOldSelect)
1401 Return llRetVal
1402
1403 Endproc
1404
1405*-----------------------------------------------------------------------------------------
1406
1407 PROCEDURE SetFkeyValuesToDtl(pcZzoordrh_Update,pcZzoordrd_update)
1408
1409 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1410 llRetVal = .T.
1411 lnOldSelect = Select()
1412
1413 lcSQL = "UPDATE d SET fkey = H.PKEY FROM " + pcZzoordrd_update + " d INNER JOIN " + pcZzoordrh_Update + " h on h.ord_num = d.ord_num and h.ord_status = d.line_status " + ;
1414 " and h.sql_action = 'U' and d.fkey = 0 "
1415 llRetVal = llRetVal and v_sqlexec(lcSQL)
1416
1417 Select(lnOldSelect)
1418 Return llRetVal
1419
1420 Endproc
1421
1422*-----------------------------------------------------------------------------------------
1423
1424 PROCEDURE SetOrderHdrPkey(pcZzoordrh_Update,pcZzoordrd_update)
1425
1426 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1427 llRetVal = .T.
1428 lnOldSelect = Select()
1429
1430 DECLARE laOrdDtls[1,4]
1431 laOrdDtls[1,1] = pcZzoordrd_update
1432 laOrdDtls[1,2] = "fkey" && update field of detail table
1433 laOrdDtls[1,3] = "ord_num,line_status" && relation field of Detail table
1434 laOrdDtls[1,4] = "ord_num,ord_status" && relation field of Header table
1435
1436 lcSQL = "SELECT count(*) newCount from " + pcZzoordrh_Update + " where sql_action = 'I'"
1437 llRetVal = llRetVal and v_sqlexec(lcSQL,"HdrRecord")
1438 IF llRetVal AND HdrRecord.newCount > 0
1439 lnMaxPkey = v_nextPkey("ZZOORDRH",HdrRecord.newCount)
1440 *llRetVal = llRetVal and loCopyUtil.HdrDtlNumKeyFldUpdate(lcInsertOrder , "pkey", @laOrdDtls, lnMaxPkeyH, lnHdrCount, "pkey_I", "")
1441 llRetVal = llRetVal and this.oCopyUtil.HdrDtlNumKeyFldUpdate(pcZzoordrh_Update,"pkey",@laOrdDtls,lnMaxPkey,HdrRecord.newCount,;
1442 "pkey_I", "h.SQL_action = 'I'","ord_num,ord_status","ord_num,ord_status")
1443
1444 ENDIF
1445
1446 *--- update fkey for new detail cancel line when cancel header already exists
1447 lcSql = " UPDATE d SET fkey = h.pkey FROM " + pcZzoordrh_Update + " h INNER JOIN " + pcZzoordrd_update + " d " + ;
1448 " ON d.ord_num = h.ord_num and d.line_status = h.ord_status and h.sql_action = 'U' AND d.sql_action = 'I'"
1449 llRetVal = llRetVal and v_sqlexec(lcSQL)
1450
1451 Select(lnOldSelect)
1452 Return llRetVal
1453
1454 Endproc
1455
1456*-----------------------------------------------------------------------------------------
1457
1458 PROCEDURE Set860TransHdrPkey(pcZzeipcth_Update,pcZzeipctd_Update)
1459
1460 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1461 llRetVal = .T.
1462 lnOldSelect = Select()
1463
1464 DECLARE laOrdDtls[1,4]
1465 laOrdDtls[1,1] = pcZzeipctd_Update
1466 laOrdDtls[1,2] = "fkey" && update field of detail table
1467 laOrdDtls[1,3] = "ord_num" && relation field of Detail table
1468 laOrdDtls[1,4] = "ord_num" && relation field of Header table
1469
1470 lcSQL = "SELECT count(*) newCount from " + pcZzeipcth_Update
1471 llRetVal = llRetVal and v_sqlexec(lcSQL,"HdrRecord")
1472 IF llRetVal AND HdrRecord.newCount > 0
1473 lnMaxPkey = v_nextPkey("ZZEIPCTH",HdrRecord.newCount)
1474 llRetVal = llRetVal and this.oCopyUtil.HdrDtlNumKeyFldUpdate(pcZzeipcth_Update,"pkey",@laOrdDtls,lnMaxPkey,HdrRecord.newCount,;
1475 "pkey_I", "","ord_num","ord_num")
1476
1477 ENDIF
1478
1479 Select(lnOldSelect)
1480 Return llRetVal
1481
1482 Endproc
1483
1484*-----------------------------------------------------------------------------------------
1485
1486 PROCEDURE SetOrderDtlPkey(pcZzoordrd_update)
1487
1488 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lnMaxPkey
1489 llRetVal = .T.
1490 lnOldSelect = Select()
1491 lnMaxPkey = 0
1492
1493 lcSQL = "SELECT count(*) newCount from " + pcZzoordrd_update + " where sql_action = 'I'"
1494 llRetVal = llRetVal AND v_SqlExec(lcSQL,"DtlRecord")
1495 *--- consider sql_action in joining between temp pkey table and pcZzoordrd_update
1496 IF llRetVal AND DtlRecord.newCount > 0
1497 lnMaxPkey = v_NextPKey("ZZOORDRD",DtlRecord.newCount)
1498
1499 *--- TR 1036066 NH
1500 LOCAL lcBaseTblKeyFlds, lcLinkTblKeyFlds
1501 IF EMPTY(this.c860SODetailAddMatchCriteria)
1502 *--- TR 1053720 5-Sep-2011 Goutam. Added LINE_SEQ
1503 lcBaseTblKeyFlds = "ORD_NUM,LINE_STATUS,DIVISION,STYLE,COLOR_CODE,LBL_CODE,DIMENSION,SQL_ACTION,LINE_SEQ"
1504 lcLinkTblKeyFlds = lcBaseTblKeyFlds
1505 ELSE
1506 *--- TR 1053720 5-Sep-2011 Goutam. Added LINE_SEQ
1507 lcBaseTblKeyFlds = "ORD_NUM,LINE_STATUS,DIVISION,STYLE,COLOR_CODE,LBL_CODE,DIMENSION," + TRIM(this.c860SODetailAddMatchCriteria) + ",SQL_ACTION,LINE_SEQ"
1508 lcLinkTblKeyFlds = lcBaseTblKeyFlds
1509 ENDIF
1510
1511 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(pcZzoordrd_update, "pkey", lnMaxPkey, DtlRecord.newCount, ;
1512 "pkey_I", "sql_action = 'I'",lcBaseTblKeyFlds,lcLinkTblKeyFlds)
1513 *=== TR 1036066 NH
1514
1515 ENDIF
1516
1517 Select(lnOldSelect)
1518 Return llRetVal
1519
1520 Endproc
1521
1522*-----------------------------------------------------------------------------------------
1523
1524 PROCEDURE Set860TransDtlPkey(pcZzeipctd_Update)
1525
1526 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lnMaxPkey
1527 llRetVal = .T.
1528 lnOldSelect = Select()
1529 lnMaxPkey = 0
1530 lcSQL = "SELECT count(*) newCount from " + pcZzeipctd_Update
1531 llRetVal = llRetVal AND v_SqlExec(lcSQL,"DtlRecord")
1532
1533 IF llRetVal AND DtlRecord.newCount > 0
1534 lnMaxPkey = v_NextPKey("ZZEIPCTD",DtlRecord.newCount)
1535 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(pcZzeipctd_Update, "pkey", lnMaxPkey, DtlRecord.newCount, ;
1536 "pkey_I", "","ORD_NUM,LINE_SEQ,DIVISION,STYLE,COLOR_CODE,LBL_CODE,DIMENSION,LIND_ID",;
1537 "ORD_NUM,LINE_SEQ,DIVISION,STYLE,COLOR_CODE,LBL_CODE,DIMENSION,LIND_ID")
1538 ENDIF
1539
1540 Select(lnOldSelect)
1541 Return llRetVal
1542
1543 Endproc
1544
1545*-----------------------------------------------------------------------------------------
1546
1547 PROCEDURE SetOrderSpPkey(pcZzoordsp_update)
1548
1549 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lnMaxPkey
1550 llRetVal = .T.
1551 lnOldSelect = Select()
1552 lnMaxPkey = 0
1553 lcSQL = "SELECT count(*) newCount from " + pcZzoordsp_update + " where sql_action = 'I'"
1554 llRetVal = llRetVal AND v_SqlExec(lcSQL,"SpRecord")
1555
1556 IF llRetVal AND SpRecord.newCount > 0
1557 lnMaxPkey = v_NextPKey("ZZOORDSP",SpRecord.newCount)
1558 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(pcZzoordSp_update, "pkey", lnMaxPkey, SpRecord.newCount, ;
1559 "pkey_I", "sql_action = 'I'","ORD_NUM","ORD_NUM")
1560 ENDIF
1561
1562 Select(lnOldSelect)
1563 Return llRetVal
1564
1565 Endproc
1566
1567*-----------------------------------------------------------------------------------------
1568
1569 PROCEDURE GoodTransRecordCount(pcZzeipcth,pcZzeipctd, pnRefIpcth, pnRefIpctd)
1570
1571 Local llRetVal, lnOldSelect,lcUnique, lcSQL
1572 llRetVal = .T.
1573 lnOldSelect = Select()
1574 lcSQL = "select COUNT(*) Ipcth_count from " + pcZzeipcth
1575 llRetVal = llRetVal and v_SQLexec(lcSQL,"IpcthCount")
1576
1577 IF llRetVal AND USED("IpcthCount")
1578 pnRefIpcth = IpcthCount.Ipcth_count
1579 USE IN IpcthCount
1580 ENDIF
1581
1582 lcSQL = "select COUNT(*) Ipctd_count from " + pcZzeipctd
1583 llRetVal = llRetVal and v_SQLexec(lcSQL,"IpctdCount")
1584
1585 IF llRetVal AND USED("IpctdCount")
1586 pnRefIpctd = IpctdCount.Ipctd_count
1587 USE IN IpctdCount
1588 ENDIF
1589
1590 Select(lnOldSelect)
1591 Return llRetVal
1592
1593 Endproc
1594
1595*-----------------------------------------------------------------------------------------
1596
1597 Procedure SetActualQuantityToUpdateForAllItems(pcZzeipcth,pcZzeipctd,pcZzoordrh_orig,pcZzoordrd_orig,pcZzoordrdv_orig,;
1598 pcZzoordrh_update,pcZzoordrd_update, pcZzoordrdv_update, pcZzoordsp_update)
1599
1600 Local llRetVal, lnOldSelect, lcSQL,lnThermoCnt
1601 lnOldSelect = Select()
1602 llRetVal = .T.
1603 lnThermoCnt = 0
1604
1605 *--- All quantity in pcZzoordrh_update, pcZzoordrdv_update has only the quantity that needs to be added (we have negative number set for decrease items)
1606 *--- order that has zero values needs to be SQL_action = 'D' in pcZzoordrh_update, pcZzoordrdv_update
1607
1608 *--- order header - for both open order and cancel order
1609 this.InitThermoWithCaption(lnThermoCnt,10,"Setting actual quantity for order detail.")
1610
1611 lcSQL = "UPDATE h SET ord_qty = oh.ord_qty + h.ord_qty FROM " + pcZzoordrh_orig + " oh INNER JOIN " + ;
1612 pcZzoordrh_update + " h ON h.ord_num = oh.ord_num and h.ord_status = oh.ord_status " + ;
1613 " AND h.SQL_action = 'U' AND h.POC_PURP <> '01'"
1614 llRetVal = llRetVal And v_SQLExec(lcSQL)
1615 this.LogEntry("Update order header qantity " + IIF(llRetVal,"completed.","failed."))
1616 this.AdvanceThermoPlus(@lnThermoCnt)
1617
1618 *---- order detail
1619*!* lcSQL = "UPDATE d SET size_qty = od.size_qty + d.size_qty FROM " + pcZzoordrdv_orig + " od INNER JOIN " + ;
1620*!* pcZzoordrdv_update + " d ON d.ord_num = od.ord_num and d.line_status = od.line_status " + ;
1621*!* " AND d.division = od.division and d.style = od.style and d.color_code = od.color_code and d.lbl_code = od.lbl_code " + ;
1622*!* " AND d.dimension = od.dimension and d.sizebucket = od.sizebucket AND d.SQL_action in ( 'U','I') "
1623*!* llRetVal = llRetVal And v_SQLExec(lcSQL)
1624
1625 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
1626*!* llRetVal = llRetVal And This.MakeOrderDetailHorizontal(pcZzoordrh_update, pcZzoordrdv_update, pcZzoordrd_orig, pcZzoordrd_update,@lnThermoCnt)
1627 llRetVal = llRetVal And This.MakeOrderDetailHorizontal(pcZzoordrh_update, pcZzoordrdv_update, pcZzoordrd_orig, pcZzoordrd_update,@lnThermoCnt,pcZzeipcth) && VKK 1067224
1628 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1629
1630 *--- Add
1631 llRetVal = llRetVal And This.CreateOrderForTransHeaderWithNoDetail(pcZzeipcth,pcZzeipctd,pcZzoordrh_update,pcZzoordrd_update, pcZzoordrh_orig, pcZzoordrd_orig, @lnThermoCnt)
1632
1633 Select(lnOldSelect)
1634 Return llRetVal
1635
1636 Endproc
1637
1638*-----------------------------------------------------------------------------------------
1639
1640 PROCEDURE CreateOrderForTransHeaderWithNoDetail(pcZzeipcth,pcZzeipctd,pcZzoordrh_update, pcZzoordrd_update, pcZzoordrh_orig, pcZzoordrd_orig, pnThermoCnt)
1641
1642 Local llRetVal, lnOldSelect,lcUnique, lcSQL,Zzoordrd_update
1643 llRetVal = .T.
1644 lnOldSelect = Select()
1645
1646 lcFlds = ""
1647 lcValues = ""
1648 lcExcludeFlds = "'SQL_action'"
1649 lcCalFlds = "SQL_action"
1650 lcCalFldsValues = "'U'"
1651
1652*!* llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update, pcZzoordrd_orig, ;
1653*!* lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'od')
1654
1655*!* lcSQL = " INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) SELECT " + lcValues + ;
1656*!* " FROM " + pcZzeipcth + " th INNER JOIN " + pcZzoordrh_orig + " oh ON oh.ord_num = th.ord_num and oh.ord_status = 'O' " + ;
1657*!* " INNER JOIN " + pcZzoordrd_orig + " od ON oh.pkey = od.fkey " + ;
1658*!* " WHERE th.poc_purp <> '01' AND NOT EXISTS (SELECT * FROM " + pcZzeipctd + " td WHERE td.fkey = th.pkey ) " + ;
1659*!* " AND NOT EXISTS (SELECT * FROM " + pcZzoordrh_update + " uh WHERE uh.ord_num = oh.ord_num " + ;
1660*!* " and uh.ord_status = oh.ord_status )"
1661*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
1662*!* this.LogEntry("Order detail created for transaction with no detail " + IIF(llRetVal,"completed.","failed."))
1663*!* this.AdvanceThermoPlus(@pnThermoCnt)
1664
1665 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, pcZzoordrh_orig, ;
1666 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'oh')
1667
1668 lcSQL = " INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) SELECT " + lcValues + ;
1669 " FROM " + pcZzeipcth + " th INNER JOIN " + pcZzoordrh_orig + " oh ON oh.ord_num = th.ord_num and oh.ord_status = 'O' " + ;
1670 " WHERE th.poc_purp <> '01' AND NOT EXISTS (SELECT * FROM " + pcZzeipctd + " td WHERE td.fkey = th.pkey ) " + ;
1671 " AND NOT EXISTS (SELECT * FROM " + pcZzoordrh_update + " uh WHERE uh.ord_num = oh.ord_num " + ;
1672 " and uh.ord_status = oh.ord_status )"
1673
1674 llRetVal = llRetVal and v_sqlexec(lcSQL)
1675 this.LogEntry("Order header created for transaction with no detail " + IIF(llRetVal,"completed.","failed."))
1676 this.AdvanceThermoPlus(@pnThermoCnt)
1677
1678 Select(lnOldSelect)
1679 Return llRetVal
1680
1681 Endproc
1682
1683*-----------------------------------------------------------------------------------------
1684
1685 Procedure MakeOrderDetailHorizontal(pcZzoordrh_update, pcZzoordrdv_update, pcZzoordrd_orig, pcZzoordrd_update,pnThermoCnt, pczzeipcth)
1686 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy === Added Param pczzeipcth
1687
1688 Local llRetVal, lnOldSelect,lcUnique, lcSQL,Zzoordrd_update
1689 llRetVal = .T.
1690 lnOldSelect = Select()
1691 lcUnique = Sys(2015)
1692
1693 *lcZzoordrd_update = "#Zzoordrd_update" + lcUnique
1694 lcZzoordrd_horizon = "#Zzoordrd_horizon" + lcUnique
1695 lcZzoordrd_horizonUniq = "#Zzoordrd_horizonUniq" + lcUnique
1696
1697 *--- TR 1034532 NH
1698 LOCAL lcAddJoin, lcAddFlds
1699 IF EMPTY(this.c860SODetailAddMatchCriteria)
1700 lcAddJoin = ""
1701 lcAddFlds = ""
1702 ELSE
1703 lcAddJoin = " and dh." + THIS.c860SODetailAddMatchCriteria + " = od." + THIS.c860SODetailAddMatchCriteria
1704 lcAddFlds = THIS.c860SODetailAddMatchCriteria + ", "
1705 ENDIF
1706 *=== TR 1034532 NH
1707
1708 *- 1041968 08/26/10 YIK
1709 *- Add Implosion
1710 lcAddFlds = lcAddFlds + 'Implosion, '
1711
1712 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
1713&& VKK 1067224
1714 lcAddFlds = lcAddFlds + " Case When cr.template = 'SEARS CANADA 4030' Then Price Else 0 end As price, cr.template, "
1715 lcAddJoin = lcAddJoin + " And dh.Price = Case when dh.template = 'SEARS CANADA 4030' And dh.Price > 0 THEN od.price ELSE dh.price end "
1716&& VKK 1067224
1717 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1718
1719 *--- make horizonal sizes
1720 *--- consider cncl_rsn and cncl_type
1721 *--- rng_style, rng_color, rng_lbl,rng_pack - 1032030
1722 *--- TR 1034532 NH : Added lcAddFlds
1723 &&--- TechRec 1067224 19-Mar-2013 vkrishnamurthy === Select fields Alias
1724 *--- TR 1072221 27-Jun-14 SK Added field 'edipo4udf1' in the select list ===
1725 lcSQL = " select dv.ord_num, dv.division, dv.style, dv.color_code, dv.lbl_code, dv.dimension, dv.SQL_action, dv.line_status, " + ;
1726 " dv.cncl_rsn, dv.cncl_type, MIN(dv.line_seq) as line_seq, " + ;
1727 lcAddFlds + " dv.rng_style, dv.rng_color, dv.rng_lbl,dv.rng_pack, " + ;
1728 "sum(case when sizebucket = 1 then size_qty else 0 end) as size01_qty, " + ;
1729 "sum(case when sizebucket = 2 then size_qty else 0 end) as size02_qty, " + ;
1730 "sum(case when sizebucket = 3 then size_qty else 0 end) as size03_qty, " + ;
1731 "sum(case when sizebucket = 4 then size_qty else 0 end) as size04_qty, " + ;
1732 "sum(case when sizebucket = 5 then size_qty else 0 end) as size05_qty, " + ;
1733 "sum(case when sizebucket = 6 then size_qty else 0 end) as size06_qty, " + ;
1734 "sum(case when sizebucket = 7 then size_qty else 0 end) as size07_qty, " + ;
1735 "sum(case when sizebucket = 8 then size_qty else 0 end) as size08_qty, " + ;
1736 "sum(case when sizebucket = 9 then size_qty else 0 end) as size09_qty, " + ;
1737 "sum(case when sizebucket = 10 then size_qty else 0 end) as size10_qty, " + ;
1738 "sum(case when sizebucket = 11 then size_qty else 0 end) as size11_qty, " + ;
1739 "sum(case when sizebucket = 12 then size_qty else 0 end) as size12_qty, " + ;
1740 "sum(case when sizebucket = 13 then size_qty else 0 end) as size13_qty, " + ;
1741 "sum(case when sizebucket = 14 then size_qty else 0 end) as size14_qty, " + ;
1742 "sum(case when sizebucket = 15 then size_qty else 0 end) as size15_qty, " + ;
1743 "sum(case when sizebucket = 16 then size_qty else 0 end) as size16_qty, " + ;
1744 "sum(case when sizebucket = 17 then size_qty else 0 end) as size17_qty, " + ;
1745 "sum(case when sizebucket = 18 then size_qty else 0 end) as size18_qty, " + ;
1746 "sum(case when sizebucket = 19 then size_qty else 0 end) as size19_qty, " + ;
1747 "sum(case when sizebucket = 20 then size_qty else 0 end) as size20_qty, " + ;
1748 "sum(case when sizebucket = 21 then size_qty else 0 end) as size21_qty, " + ;
1749 "sum(case when sizebucket = 22 then size_qty else 0 end) as size22_qty, " + ;
1750 "sum(case when sizebucket = 23 then size_qty else 0 end) as size23_qty, " + ;
1751 "sum(case when sizebucket = 24 then size_qty else 0 end) as size24_qty, " + ;
1752 "sum(size_qty) as total_qty, MIN(EDIPO4UDF1) as EDIPO4UDF1 " + ;
1753 " into " + lcZzoordrd_horizon + " FROM " + pcZzoordrdv_update + " dv " + ;
1754 " JOIN " + pczzeipcth + " th ON th.ord_num = dv.ord_num " + ; && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1755 " join zzeipccr cr on cr.pkey = th.cr_pkey " + ; && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1756 " WHERE not exists (select * from " + pcZzoordrh_update + " h WHERE h.ord_num = dv.ord_num AND h.ord_status = dv.line_status " + ;
1757 " AND h.poc_purp = 'O1') " + ;
1758 " AND (dv.line_status = 'O' or (dv.line_status = 'C' and dv.sql_action = 'I')) " + ;
1759 " GROUP BY dv.ord_num, dv.division, dv.style, dv.color_code, dv.lbl_code, dv.dimension, " + STRTRAN(lcAddFlds,"As price","") + " dv.rng_style, dv.rng_color, dv.rng_lbl,dv.rng_pack, SQL_action, dv.line_status, dv.cncl_rsn, dv.cncl_type " && 1032030 &--- TR 104532 NH && && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1760
1761 llRetVal = llRetVal And v_SQLExec(lcSQL)
1762 this.LogEntry("Transform vertical order detail to horizontal order detail " + IIF(llRetVal,"completed.","failed."))
1763 this.AdvanceThermoPlus(@pnThermoCnt)
1764 *--- change sql_action to 'U' when SKU exists after detail is horizontal
1765 lcSQL = "UPDATE dh SET sql_action = 'U', line_seq = od.line_seq FROM " + lcZzoordrd_horizon + " dh INNER JOIN " +;
1766 pcZzoordrd_orig + " od ON dh.ord_num = od.ord_num " + ;
1767 " and dh.division = od.division and dh.style = od.style and dh.color_code = od.color_code " +;
1768 " and dh.lbl_code = od.lbl_code and dh.dimension = od.dimension and dh.line_status = od.line_status " + ;
1769 " and dh.cncl_rsn = od.cncl_rsn and dh.cncl_type = od.cncl_type and od.line_status <> 'C' " + lcAddJoin &&--- TR 1034532 NH
1770 llRetVal = llRetVal And v_SQLExec(lcSQL)
1771 this.AdvanceThermoPlus(@pnThermoCnt)
1772
1773 *--- set cancel order line seq same as open order
1774 lcSQL = "UPDATE dh SET line_seq = od.line_seq FROM " + lcZzoordrd_horizon + " dh INNER JOIN " +;
1775 pcZzoordrd_orig + " od ON dh.ord_num = od.ord_num " + ;
1776 " and dh.division = od.division and dh.style = od.style and dh.color_code = od.color_code " +;
1777 " and dh.lbl_code = od.lbl_code and dh.dimension = od.dimension and dh.line_status = 'C' " + ;
1778 " and od.line_status = 'O' " + lcAddJoin &&--- TR 1034532 NH
1779 llRetVal = llRetVal And v_SQLExec(lcSQL)
1780 this.AdvanceThermoPlus(@pnThermoCnt)
1781
1782 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
1783 && && VKK 1067224
1784 lcAddFlds = STRTRAN(lcAddFlds," Case When cr.template = 'SEARS CANADA 4030' Then Price Else 0 end As price, cr.template, ", " price, template,")
1785 && && VKK 1067224
1786 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1787
1788 *--- TR 1032030 NH
1789 *--- sum up again for sql_action has changed.
1790 *--- TR 1034532 NH : Added lcAddFlds
1791 *--- TR 1072221 18-Jul-13 SK Added field 'edipo4udf1' in the select list ===
1792 lcSQL = " select ord_num, division, style, color_code, lbl_code, dimension, SQL_action, line_status, line_seq, cncl_rsn, cncl_type " + ;
1793 " ," + lcAddFlds + " rng_style, rng_color, rng_lbl,rng_pack " + ;
1794 " ,SUM(size01_qty) as size01_qty, SUM(size02_qty) as size02_qty, SUM(size03_qty) as size03_qty, SUM(size04_qty) as size04_qty " + ;
1795 " ,SUM(size05_qty) as size05_qty, SUM(size06_qty) as size06_qty, SUM(size07_qty) as size07_qty, SUM(size08_qty) as size08_qty " + ;
1796 " ,SUM(size09_qty) as size09_qty, SUM(size10_qty) as size10_qty " + ;
1797 " ,SUM(size11_qty) as size11_qty, SUM(size12_qty) as size12_qty, SUM(size13_qty) as size13_qty, SUM(size14_qty) as size14_qty " + ;
1798 " ,SUM(size15_qty) as size15_qty, SUM(size16_qty) as size16_qty, SUM(size17_qty) as size17_qty, SUM(size18_qty) as size18_qty " + ;
1799 " ,SUM(size19_qty) as size19_qty, SUM(size20_qty) as size20_qty " + ;
1800 " ,SUM(size21_qty) as size21_qty, SUM(size22_qty) as size22_qty, SUM(size23_qty) as size23_qty, SUM(size24_qty) as size24_qty " + ;
1801 " ,sum(total_qty) as total_qty , 'N' Line_Seq_Resolved, MIN(EDIPO4UDF1) as EDIPO4UDF1 " + ; && && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
1802 " INTO " + lcZzoordrd_horizonUniq + " FROM " + lcZzoordrd_horizon + " d " + ;
1803 " GROUP BY ord_num, division, style, color_code, lbl_code, dimension, rng_style, rng_color, rng_lbl,rng_pack, " + lcAddFlds + ;
1804 " SQL_action, line_status, line_seq, cncl_rsn, cncl_type "
1805 llRetVal = llRetVal and v_sqlexec(lcSQL)
1806
1807 llRetVal = llRetVal and this.ResetLineSeqForSqlUpdate(lcZzoordrd_horizonUniq)
1808
1809 *----
1810 lcFlds = ""
1811 lcValues = ""
1812
1813 *--- TechRec 1085945 20-Aug-2015 vkrishnamurthy ---
1814*!* lcExcludeFlds = "'size01_qty','size02_qty','size03_qty','size04_qty','size05_qty','size06_qty','size07_qty','size08_qty','size09_qty','size10_qty','size11_qty'," +;
1815*!* "'size12_qty','size13_qty','size14_qty','size15_qty','size16_qty','size17_qty','size18_qty','size19_qty','size20_qty','size21_qty','size22_qty','size23_qty','size24_qty'," + ;
1816*!* "'total_Qty','SQL_action','line_status','bulk_red'"
1817
1818*!* lcCalFlds = "size01_qty,size02_qty,size03_qty,size04_qty,size05_qty,size06_qty,size07_qty,size08_qty,size09_qty,size10_qty,size11_qty," +;
1819*!* "size12_qty,size13_qty,size14_qty,size15_qty,size16_qty,size17_qty,size18_qty,size19_qty,size20_qty,size21_qty,size22_qty,size23_qty,size24_qty," + ;
1820*!* "total_Qty, SQL_action,line_status,bulk_red"
1821
1822 lcExcludeFlds = "'size01_qty','size02_qty','size03_qty','size04_qty','size05_qty','size06_qty','size07_qty','size08_qty','size09_qty','size10_qty','size11_qty'," +;
1823 "'size12_qty','size13_qty','size14_qty','size15_qty','size16_qty','size17_qty','size18_qty','size19_qty','size20_qty','size21_qty','size22_qty','size23_qty','size24_qty'," + ;
1824 "'total_Qty','SQL_action','line_status','bulk_red','bulk_resolved'"
1825
1826 lcCalFlds = "size01_qty,size02_qty,size03_qty,size04_qty,size05_qty,size06_qty,size07_qty,size08_qty,size09_qty,size10_qty,size11_qty," +;
1827 "size12_qty,size13_qty,size14_qty,size15_qty,size16_qty,size17_qty,size18_qty,size19_qty,size20_qty,size21_qty,size22_qty,size23_qty,size24_qty," + ;
1828 "total_Qty, SQL_action,line_status,bulk_red,bulk_resolved"
1829 *=== TechRec 1085945 20-Aug-2015 vkrishnamurthy ===
1830
1831
1832 *- TR 1072045 FH 7/01/13 - replace 'N' with od.bulk_red - Orders that existed before that use to have 'Y' as bulk reduction gets turned to 'N'
1833 &&--- TechRec 1085945 20-Aug-2015 vkrishnamurthy ===Added od.bulk_resolved
1834 lcCalFldsValues = "od.size01_qty + dh.size01_qty,od.size02_qty + dh.size02_qty,od.size03_qty + dh.size03_qty,od.size04_qty + dh.size04_qty,od.size05_qty + dh.size05_qty,od.size06_qty + dh.size06_qty,od.size07_qty + dh.size07_qty,od.size08_qty + dh.size08_qty," + ;
1835 "od.size09_qty + dh.size09_qty,od.size10_qty + dh.size10_qty,od.size11_qty + dh.size11_qty, od.size12_qty + dh.size12_qty, od.size13_qty + dh.size13_qty, od.size14_qty + dh.size14_qty, od.size15_qty + dh.size15_qty, od.size16_qty + dh.size16_qty, " + ;
1836 "od.size17_qty + dh.size17_qty, od.size18_qty + dh.size18_qty,od.size19_qty + dh.size19_qty,od.size20_qty + dh.size20_qty,od.size21_qty + dh.size21_qty, od.size22_qty + dh.size22_qty, od.size23_qty + dh.size23_qty, od.size24_qty + dh.size24_qty," + ;
1837 "od.total_qty + dh.total_qty,dh.SQL_action,dh.line_status, od.bulk_red,od.bulk_resolved "
1838
1839 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update , pcZzoordrd_orig , ;
1840 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'od')
1841 this.AdvanceThermoPlus(@pnThermoCnt)
1842
1843 *--- exclude cancel orders
1844 TEXT TO lcSQL NOSHOW
1845 SELECT od.* FROM #Zzoordrd_orig od INNER JOIN #Zzoordrd_horizon dh ON od.ord_num = dh.ord_num AND
1846 od.division = dh.division and od.style = dh.style and od.color_code = dh.color_code
1847 and od.lbl_code = dh.lbl_code and od.dimension = dh.dimension and od.line_status = dh.line_status
1848 and od.cncl_rsn = dh.cncl_rsn and od.cncl_type = dh.cncl_type and od.line_seq = dh.line_seq
1849 ENDTEXT
1850
1851 lcSQL = Strtran(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
1852 lcSQL = Strtran(lcSQL,"#Zzoordrd_horizon",lcZzoordrd_horizonUniq )
1853 lcSQL = Strtran(lcSQL,"od.*",lcValues)
1854 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
1855 llRetVal = llRetVal And v_SQLExec(lcSQL)
1856
1857 this.LogEntry("Add order detail previous quantity with new change quantity " + IIF(llRetVal,"completed.","failed."))
1858 this.AdvanceThermoPlus(@pnThermoCnt)
1859
1860 *--- add new cancel line
1861*!* lcExcludeFlds = "'size01_qty','size02_qty','size03_qty','size04_qty','size05_qty','size06_qty','size07_qty','size08_qty','size09_qty','size10_qty','size11_qty'," +;
1862*!* "'size12_qty','size13_qty','size14_qty','size15_qty','size16_qty','size17_qty','size18_qty','size19_qty','size20_qty','size21_qty','size22_qty','size23_qty','size24_qty'," + ;
1863*!* "'total_Qty','SQL_action','line_status','bulk_red'"
1864
1865*!* lcCalFlds = "size01_qty,size02_qty,size03_qty,size04_qty,size05_qty,size06_qty,size07_qty,size08_qty,size09_qty,size10_qty,size11_qty," +;
1866*!* "size12_qty,size13_qty,size14_qty,size15_qty,size16_qty,size17_qty,size18_qty,size19_qty,size20_qty,size21_qty,size22_qty,size23_qty,size24_qty," + ;
1867*!* "total_Qty, SQL_action,line_status,bulk_red"
1868
1869*!* lcCalFldsValues = "dh.size01_qty,dh.size02_qty,dh.size03_qty,dh.size04_qty,dh.size05_qty,dh.size06_qty,dh.size07_qty,dh.size08_qty," + ;
1870*!* "dh.size09_qty,dh.size10_qty,dh.size11_qty,dh.size12_qty,dh.size13_qty,dh.size14_qty,dh.size15_qty,dh.size16_qty, " + ;
1871*!* "dh.size17_qty,dh.size18_qty,dh.size19_qty,dh.size20_qty,dh.size21_qty,dh.size22_qty,dh.size23_qty,dh.size24_qty," + ;
1872*!* "dh.total_qty,dh.SQL_action,dh.line_status,'N'"
1873
1874*!* llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update , pcZzoordrd_orig , ;
1875*!* lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'od')
1876*!* this.AdvanceThermoPlus(@pnThermoCnt)
1877
1878*!*
1879*!* TEXT TO lcSQL NOSHOW
1880*!* SELECT od.* FROM #Zzoordrd_orig od INNER JOIN #Zzoordrd_horizon dh ON od.ord_num = dh.ord_num AND
1881*!* od.division = dh.division and od.style = dh.style and od.color_code = dh.color_code
1882*!* and od.lbl_code = dh.lbl_code and od.dimension = dh.dimension and od.line_seq = dh.line_seq
1883*!* and dh.line_status = 'C' and od.line_status = 'O'
1884*!* ENDTEXT
1885
1886*!* lcSQL = Strtran(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
1887*!* lcSQL = Strtran(lcSQL,"#Zzoordrd_horizon",lcZzoordrd_horizonUniq )
1888*!* lcSQL = Strtran(lcSQL,"od.*",lcValues)
1889*!* lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
1890*!* llRetVal = llRetVal And v_SQLExec(lcSQL)
1891
1892 *---- New order lines
1893 *--- except cancel lines
1894 lcFlds = ""
1895 lcValues = ""
1896 lcExcludeFlds = "'line_seq'"
1897 lcCalFlds = "line_seq"
1898 lcCalFldsValues = "CASE WHEN dh.line_status = 'C' THEN dh.line_seq ELSE 0 END"
1899
1900 DECLARE laDuplicateFields[1]
1901 ACOPY(this.oMainProcess.aDuplicateFields, laDuplicateFields)
1902 llRetVal = llRetVal and This.GetHdrCascadeFlds(@laDuplicateFields,@lcExcludeFlds,@lcCalFlds,@lcCalFldsValues,"h")
1903
1904 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update, lcZzoordrd_horizon, ;
1905 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'dh')
1906 this.AdvanceThermoPlus(@pnThermoCnt)
1907 lcSQL = "Select " + lcValues + " from " + lcZzoordrd_horizonUniq + " dh " + ;
1908 "INNER JOIN " + pcZzoordrh_update + " h " + ;
1909 "ON dh.ord_num = h.ord_num and dh.line_status = h.ord_status " + ;
1910 " and dh.sql_action = 'I' and h.poc_purp <> '01' "
1911 lcSQL = "Insert into " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
1912 llRetVal = llRetVal and v_sqlexec(lcSql)
1913 this.LogEntry("" + IIF(llRetVal,"completed.","failed."))
1914 this.AdvanceThermoPlus(@pnThermoCnt)
1915
1916 *--- TechRec 1085945 24-Aug-2015 vkrishnamurthy ---
1917 lcSQL = " update d set bulk_resolved = case when d.bulk_resolved = '' then od.bulk_resolved else d.bulk_resolved end " + ;
1918 " from " + pcZzoordrd_update + " d" + ;
1919 " join "+ pcZzoordrd_update+ " od "+ ;
1920 " on d.ord_num = od.ord_num and d.line_seq = od.line_seq where d.bulk_resolved = ''"
1921 llRetVal = llRetVal and v_sqlexec(lcSql)
1922 *=== TechRec 1085945 24-Aug-2015 vkrishnamurthy ===
1923
1924 this.LogEntry("Cascade data from order header to new order detail lines " + IIF(llRetVal,"completed.","failed."))
1925
1926 *--- add lines that are not affected by 860 change
1927 lcFlds = ""
1928 lcValues = ""
1929 *--- TechRec 1085945 24-Aug-2015 vkrishnamurthy ---
1930*!* lcExcludeFlds = "'SQL_action'"
1931*!* lcCalFlds = "SQL_action"
1932*!* lcCalFldsValues = "'U'"
1933
1934 lcExcludeFlds = "'SQL_action','bulk_resolved'"
1935 lcCalFlds = "SQL_action,bulk_resolved"
1936 lcCalFldsValues = "'U',od.bulk_resolved"
1937 *=== TechRec 1085945 24-Aug-2015 vkrishnamurthy ===
1938
1939 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update , pcZzoordrd_orig , ;
1940 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'od')
1941
1942 *--- TR 1053720 23-May-2011 Goutam. Added condition and od.line_status <> 'C'. Why should we consider cancel item for not matching record ;
1943 with SO detail and 860 transaction detail and insert it in detail.
1944 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) select " + lcValues + " from " + pcZzoordrd_orig + " od " +;
1945 " WHERE not exists (select * from " + lcZzoordrd_horizonUniq + " dh WHERE od.ord_num = dh.ord_num " + ;
1946 " AND od.division = dh.division and od.style = dh.style and od.color_code = dh.color_code " + ;
1947 " and od.lbl_code = dh.lbl_code and od.dimension = dh.dimension and od.line_status = dh.line_status) " + ;
1948 " and od.line_status <> 'C' " + ;
1949 " and not exists (select * from " + pcZzoordrh_update + " h WHERE h.poc_purp = '01' AND h.ord_num = od.ord_num " + ;
1950 " and h.ord_status = od.line_status ) "
1951
1952 llRetVal = llRetVal And v_SQLExec(lcSQL)
1953 *this.LogEntry("" + IIF(llRetVal,"completed.","failed."))
1954
1955
1956 *--- TechRec 1067224 04-Apr-2013 vkrishnamurthy ---
1957 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) select " + lcValues + " from " + pcZzoordrd_orig + " od " +;
1958 " WHERE not exists (select * from " + lcZzoordrd_horizonUniq + " dh WHERE od.ord_num = dh.ord_num " + ;
1959 " AND dh.line_Seq_resolved <> 'Y' and dh.line_seq = od.line_seq )" + ;
1960 " and exists ( select * from " + lcZzoordrd_horizonUniq + " dh WHERE od.ord_num = dh.ord_num "+ ;
1961 " and dh.template = 'SEARS CANADA 4030' and dh.price >0 and dh.line_Seq_resolved <> 'Y' ) " + ;
1962 " and od.line_status <> 'C' " + ;
1963 " and not exists (select * from " + pcZzoordrh_update + " h WHERE h.poc_purp = '01' AND h.ord_num = od.ord_num " + ;
1964 " and h.ord_status = od.line_status ) "
1965
1966 llRetVal = llRetVal And v_SQLExec(lcSQL)
1967 *=== TechRec 1067224 04-Apr-2013 vkrishnamurthy ===
1968
1969 this.AdvanceThermoPlus(@pnThermoCnt)
1970
1971 *--- add cancel lines that has matching sku but needs to be in seperate cancel line.
1972 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) select " + lcValues + " from " + pcZzoordrd_orig + " od " +;
1973 " WHERE exists (select * from " + lcZzoordrd_horizonUniq + " dh WHERE od.ord_num = dh.ord_num " + ;
1974 " AND od.division = dh.division and od.style = dh.style and od.color_code = dh.color_code " + ;
1975 " and od.lbl_code = dh.lbl_code and od.dimension = dh.dimension and od.line_status = dh.line_status " + ;
1976 " and dh.line_status = 'C') " + ;
1977 " and not exists (select * from " + pcZzoordrh_update + " h WHERE h.poc_purp = '01' AND h.ord_num = od.ord_num " + ;
1978 " and h.ord_status = od.line_status ) "
1979
1980 llRetVal = llRetVal And v_SQLExec(lcSQL)
1981 *this.LogEntry("" + IIF(llRetVal,"completed.","failed."))
1982 this.AdvanceThermoPlus(@pnThermoCnt)
1983
1984 v_sqlexec("drop table " + lcZzoordrd_horizonUniq)
1985 v_sqlexec("drop table " + lcZzoordrd_horizon)
1986
1987 *--- correct
1988 *--- add existing cancel order update is pcZzoordrd_update
1989 *--- correct cancel order ord_qty pcZzoordrd_update
1990
1991 *--- TR 1053720 23-May-2011 Goutam
1992 lcSql = " Update od set od.cncl_type = '', od.cncl_rsn = '', od.cncl_date = '' from " + pcZzoordrd_update + " od where od.line_status = 'O'"
1993 llRetVal = llRetVal and v_sqlexec(lcSql)
1994 *=== TR 1053720 23-May-2011 Goutam
1995
1996 *--- set up other values - Bulk_red
1997 *--- TR 1061541 05/21/12 ATHIRUNAVU Default Bluk_red ='Y' for new lines instead of 'Y'
1998 *lcSql = "Update d Set Bulk_red = case when bulk_red = '' then 'N' else bulk_red end from " + pcZzoordrd_update + " d "
1999 lcSql = "Update d Set Bulk_red = case when bulk_red = '' then 'Y' else bulk_red end from " + pcZzoordrd_update + " d "
2000 llRetVal = llRetVal and v_sqlexec(lcSql)
2001
2002 *--- set price, retail1 values from open order detail
2003 lcSql = "Update d Set price = case when d.price = 0.0 then od.price else d.price end " + ;
2004 " , retail1 = case when d.retail1 = 0.0 then od.retail1 else d.retail1 end " + ;
2005 " , retail2 = case when d.retail2 = 0.0 then od.retail2 else d.retail2 end " + ;
2006 " , sent_855f = '', FACT_STATUS = '', DECL_RSN = '' " + ;
2007 " FROM " + pcZzoordrd_update + " d " + ;
2008 " INNER JOIN " + pcZzoordrd_orig + " od ON d.ord_num = d.ord_num and d.division = od.division " + ;
2009 " and d.style = od.style and d.color_code = od.color_code and d.lbl_code = od.lbl_code " + ;
2010 " and d.dimension = od.dimension and d.line_status = 'C' and od.line_status = 'O' "
2011
2012 llRetVal = llRetVal and v_sqlexec(lcSql)
2013
2014 *--- update new store order qty
2015 lcSQL = " UPDATE uh SET ord_qty = ud.ord_qty FROM " + pcZzoordrh_update + " uh INNER JOIN " + ;
2016 " (select d.ord_num, d.line_status, SUM(d.total_qty) as ord_qty FROM " + pcZzoordrd_update + " d " + ;
2017 " INNER JOIN " + pcZzoordrh_update + " h ON d.ord_num = h.ord_num and d.line_status = h.ord_status " + ;
2018 " WHERE d.sql_action = 'I' and h.ord_qty = 0 and h.sql_action = 'I' GROUP BY d.ord_num, line_status ) ud " + ;
2019 " ON ud.ord_num = uh.ord_num and ud.line_status = uh.ord_status WHERE uh.ord_qty = 0 and uh.sql_action = 'I'"
2020
2021 llRetVal = llRetVal And v_SQLExec(lcSQL)
2022 *this.LogEntry("" + IIF(llRetVal,"completed.","failed."))
2023
2024 this.AdvanceThermoPlus(@pnThermoCnt)
2025
2026 Select(lnOldSelect)
2027 Return llRetVal
2028
2029 Endproc
2030
2031*-----------------------------------------------------------------------------------------
2032
2033 PROCEDURE ResetLineSeqForSqlUpdate(pcZzoordrd_horizonUniq)
2034
2035 LOCAL llRetVal, lnOldSelect, lcSql
2036 llRetVal = .t.
2037 lnOldSelect = SELECT()
2038
2039 *--- TR 1034532 NH
2040 LOCAL lcAddJoin, lcMsg_add,lcAddJoinLineSEq
2041 IF EMPTY(this.c860SODetailAddMatchCriteria)
2042 lcAddJoin = ""
2043 ELSE
2044 lcAddJoin = " and od." + THIS.c860SODetailAddMatchCriteria + " = d." + THIS.c860SODetailAddMatchCriteria
2045 ENDIF
2046 *=== TR 1034532 NH
2047
2048 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
2049 && VKK 1067224
2050 lcAddJoinLineSEq = " And d.Price = Case when d.template = 'SEARS CANADA 4030' And d.Price > 0 THEN od.price ELSE d.price end "
2051 && VKK 1067224
2052 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
2053 lcSql = " UPDATE d SET line_seq = od.line_seq, line_Seq_resolved = 'Y',sql_action = 'U' FROM " + pcZzoordrd_horizonUniq + " d " + ; && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
2054 " INNER JOIN zzoordrd od (nolock) ON d.ord_num = od.ord_num and d.line_status = od.line_status " + ;
2055 " and d.division = od.division and d.style = od.style and d.color_code = od.color_code " + ;
2056 " and d.lbl_code = od.lbl_code and d.dimension = od.dimension " + lcAddJoin + lcAddJoinLineSEq + ; &&--- TR 1034532 NH && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
2057 " WHERE od.line_status in ( 'O','C') "
2058
2059 llRetVal = llRetVal and v_sqlexec(lcSql)
2060
2061 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
2062 && VKK 1067224
2063 lcSql = " UPDATE d SET line_seq = od.line_seq, line_Seq_resolved = 'Y',sql_action = 'U' FROM " + pcZzoordrd_horizonUniq + " d " + ; && VKK 1067224
2064 " INNER JOIN zzoordrd od (nolock) ON d.ord_num = od.ord_num and d.line_status = od.line_status " + ;
2065 " and d.division = od.division and d.style = od.style and d.color_code = od.color_code " + ;
2066 " and d.lbl_code = od.lbl_code and d.dimension = od.dimension " + lcAddJoin + ; &&--- TR 1034532 NH
2067 " WHERE od.line_status in ( 'O','C') And line_Seq_resolved <> 'Y' and d.template <> 'SEARS CANADA 4030' "
2068
2069 llRetVal = llRetVal and v_sqlexec(lcSql)
2070
2071 *--- TechRec 1067224 04-Apr-2013 vkrishnamurthy ---
2072 lcSql = " UPDATE d SET line_seq = 0 FROM " + pcZzoordrd_horizonUniq + " d " + ;
2073 " INNER JOIN zzoordrd od (nolock) ON d.ord_num = od.ord_num and d.line_status = od.line_status " + ;
2074 " and d.division = od.division and d.style = od.style and d.color_code = od.color_code " + ;
2075 " and d.lbl_code = od.lbl_code and d.dimension = od.dimension " + lcAddJoin + ;
2076 " WHERE od.line_status in ( 'O','C') And d.line_Seq_resolved <> 'Y' and d.template = 'SEARS CANADA 4030' and d.price >0 "
2077
2078 llRetVal = llRetVal and v_sqlexec(lcSql)
2079
2080 lcSql = " UPDATE d SET line_seq = ml.line_seq FROM " + pcZzoordrd_horizonUniq + " d " + ;
2081 " Join ( select MIN(dtl.line_seq) line_seq , dtl.ord_num, dtl.division,dtl.style, dtl.color_code, dtl.lbl_code, dtl.dimension " + ;
2082 " from zzoordrd dtl (nolock) " + ;
2083 " Join " + pcZzoordrd_horizonUniq + " d " +;
2084 " on dtl.ord_num = d.ord_num and dtl.line_status = d.line_status " + ;
2085 " and dtl.division = d.division and dtl.style = d.style and dtl.color_code = d.color_code " + ;
2086 " and dtl.lbl_code = d.lbl_code and dtl.dimension = d.dimension " + ;
2087 " group by dtl.ord_num, dtl.division,dtl.style, dtl.color_code, dtl.lbl_code, dtl.dimension ) ml " + ;
2088 " ON d.ord_num = ml.ord_num " + ;
2089 " and d.division = ml.division and d.style = ml.style and d.color_code = ml.color_code " + ;
2090 " and d.lbl_code = ml.lbl_code and d.dimension = ml.dimension " + ;
2091 " INNER JOIN zzoordrd od (nolock) ON d.ord_num = od.ord_num and d.line_status = od.line_status " + ;
2092 " and d.division = od.division and d.style = od.style and d.color_code = od.color_code " + ;
2093 " and d.lbl_code = od.lbl_code and d.dimension = od.dimension " + lcAddJoin + ;
2094 " WHERE od.line_status in ( 'O','C') And d.line_Seq_resolved = 'Y' and d.template = 'SEARS CANADA 4030' and d.price =0 and od.line_seq = ml.line_seq "
2095
2096 llRetVal = llRetVal and v_sqlexec(lcSql)
2097
2098
2099 *=== TechRec 1067224 04-Apr-2013 vkrishnamurthy ===
2100
2101 && VKK 1067224
2102 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
2103
2104 Select(lnOldSelect)
2105 Return llRetVal
2106
2107 Endproc
2108
2109 *-----------------------------------------------------------------------------------------
2110
2111 PROCEDURE GetHdrCascadeFlds(paDuplicateFields,pcExcludeFlds,pcCalFlds,pcCalFldsValues,pcHdrAlias)
2112
2113 Local llRetVal, lnOldSelect,lcUnique, lcSQL, lnCnt, lcExcludeFlds,lcCalFlds,lcCalFldsValues,lcHdrAlias
2114 llRetVal = .T.
2115 lnOldSelect = Select()
2116 lcHdrAlias = ALLTRIM(pcHdrAlias)
2117 lcHdrAlias = lcHdrAlias + IIF(right(lcHdrAlias,1) == ".","",".")
2118 lcExcludeFlds = ALLTRIM(pcExcludeFlds)
2119 lcCalFlds = ALLTRIM(pcCalFlds)
2120 lcCalFldsValues = ALLTRIM(pcCalFldsValues)
2121
2122 lcExcludeFlds = lcExcludeFlds + IIF(RIGHT(lcExcludeFlds,1) == ",","",",")
2123 lcCalFlds = lcCalFlds + IIF(RIGHT(lcCalFlds,1) == ",","",",")
2124 lcCalFldsValues = lcCalFldsValues + IIF(RIGHT(lcCalFldsValues,1) == ",","",",")
2125
2126 For lnCnt = 1 To Alen(paDuplicateFields)
2127 If !Empty(paDuplicateFields[lnCnt])
2128 lcExcludeFlds = lcExcludeFlds + "'" + ALLTRIM(paDuplicateFields[lnCnt]) + "',"
2129 lcCalFlds = lcCalFlds + ALLTRIM(paDuplicateFields[lnCnt]) + ","
2130 lcCalFldsValues = lcCalFldsValues + lcHdrAlias + ALLTRIM(paDuplicateFields[lnCnt]) + ","
2131 Endif
2132 Endfor
2133
2134 pcExcludeFlds = this.oCopyUtil.RemoveLastChar(lcExcludeFlds,",")
2135 pcCalFlds = this.oCopyUtil.RemoveLastChar(lcCalFlds,",")
2136 pcCalFldsValues = this.oCopyUtil.RemoveLastChar(lcCalFldsValues,",")
2137
2138 Select(lnOldSelect)
2139 Return llRetVal
2140
2141 Endproc
2142
2143*-----------------------------------------------------------------------------------------
2144
2145 Procedure PrepareOrderToDeleteForZeroQuantity(pcZzoordrh_update, pcZzoordrd_update, pcZzoordsp_update)
2146
2147 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2148 lnOldSelect = Select()
2149 llRetVal = .T.
2150
2151 *---TR 1043351 NOV-19-2009 BR - ADDED and h.conf_type = 'A'
2152 *--- Previous SQL would delete fully distributed bulks
2153 lcSQL = "UPDATE h SET SQL_action = 'D' FROM " + pcZzoordrh_update + " h WHERE ord_qty = 0 and h.conf_type = 'A' "
2154 llRetVal = llRetVal And v_SQLExec(lcSQL)
2155
2156 *---TR 1043351 NOV-19-2009 BR - ADDED and d.conf_type_cascaded = 'A'
2157 *--- Previous SQL would delete fully distributed bulks
2158 lcSQL = "UPDATE d SET SQL_action = 'D' FROM " + pcZzoordrd_update + " d WHERE total_qty = 0 and d.conf_type_cascaded = 'A' "
2159 llRetVal = llRetVal And v_SQLExec(lcSQL)
2160
2161 lcFlds = ""
2162 lcValues = ""
2163 lcExcludeFlds = "'SQL_action'"
2164 lcCalFlds = "SQL_action"
2165 lcCalFldsValues = "'D'"
2166
2167 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordsp_update , "zzoordsp" , ;
2168 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'sp')
2169
2170 lcSQL = "INSERT INTO " + pcZzoordsp_update + " ( " + lcFlds + " ) select " + lcValues + " from zzoordsp sp (nolock) " + ;
2171 " INNER JOIN " + pcZzoordrh_update + " h ON h.ord_num = sp.ord_num and h.pick_num = sp.pick_num " + ;
2172 " and h.inv_num = sp.inv_num WHERE h.ord_qty = 0 "
2173
2174 llRetVal = llRetVal And v_SQLExec(lcSQL)
2175
2176 Select(lnOldSelect)
2177 Return llRetVal
2178
2179 Endproc
2180
2181*-----------------------------------------------------------------------------------------
2182
2183 Procedure Get860TransTables(tcRefZzeipcth,tcRefZzeipctd,tcFilterCriteria)
2184
2185 this.LogEntry("Prepare 860 temporary transaction tables.")
2186 this.InitThermoWithCaption(0,1,"Prepare 860 temporary transaction tables.")
2187
2188 Local llRetVal, lnOldSelect,lcUnique
2189 lnOldSelect = Select()
2190 llRetVal = .T.
2191 lcUnique = Sys(2015)
2192 lcZzeipcth = "#zzeipcth" + lcUnique
2193 lcZzeipctd = "#zzeipctd" + lcUnique
2194 lcSQL = "Select * into " + lcZzeipcth + " from zzeipcth h " + Iif(Empty(tcFilterCriteria),""," Where " + tcFilterCriteria)
2195 llRetVal = llRetVal And v_SQLExec(lcSQL)
2196
2197 lcSQL = "Select d.*, h.ord_num into " + lcZzeipctd + " from zzeipcth h inner join zzeipctd d on d.fkey = h.pkey " + ;
2198 IIF(Empty(tcFilterCriteria),""," Where " + tcFilterCriteria)
2199 llRetVal = llRetVal And v_SQLExec(lcSQL)
2200 lcSql = "SELECT COUNT(*) ToProcess from " + lcZzeipcth
2201
2202 IF USED("tcToProcess")
2203 USE IN tcToProcess
2204 ENDIF
2205
2206 llRetVal = llRetVal and v_sqlexec(lcSQL,'tcToProcess')
2207
2208 IF USED("tcToProcess")
2209 this.oMainProcess.nToProcess = tcToProcess.ToProcess
2210 USE IN tcToProcess
2211 ENDIF
2212 *--- update out param
2213 tcRefZzeipcth = lcZzeipcth
2214 tcRefZzeipctd = lcZzeipctd
2215 this.Advancethermoplus(1)
2216 Select(lnOldSelect)
2217 Return llRetVal
2218
2219 Endproc
2220
2221 *-----------------------------------------------------------------------------------------
2222
2223 Procedure GetSalesOrdersToChange(tcZzeipcth, tcZzeipctd, tcRefZzoordrh_orig, tcRefZzoordrd_orig, tcRefZzoordsp_orig)
2224
2225 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2226 lnOldSelect = Select()
2227 llRetVal = .T.
2228 lcUnique = Sys(2015)
2229 lcZzoordrh_orig = "#zzoordrh_orig" + lcUnique
2230 lcZzoordrd_orig = "#zzoordrd_orig" + lcUnique
2231 lcZzoordsp_orig = "#zzoordsp_orig" + lcUnique
2232
2233 *--- TR 1062197 10-Sep-2012 Goutam. changed condition th.store = h.store to case
2234 lcSQL = "SELECT h.* into " + lcZzoordrh_orig + " from Zzoordrh h inner join " + tcZzeipcth + " th on th.po_num = h.po_num " + ;
2235 " and th.customer = h.customer and th.store = case when th.poc_purp = '04' and th.poc_store > '' then th.store else h.store end and th.division = h.division "
2236 llRetVal = llRetVal And v_SQLExec(lcSQL)
2237
2238 lcSQL = "SELECT d.* into " + lcZzoordrd_orig + " from Zzoordrd d inner join " + lcZzoordrh_orig + " h on h.pkey = d.fkey "
2239 llRetVal = llRetVal And v_SQLExec(lcSQL)
2240
2241 lcSQL = "SELECT sp.* into " + lcZzoordsp_orig + " from zzoordsp sp inner join " + lcZzoordrh_orig + " h on h.ord_num = sp.ord_num and h.pick_num = sp.pick_num and h.inv_num = sp.inv_num "
2242 llRetVal = llRetVal And v_SQLExec(lcSQL)
2243
2244 tcRefZzoordrh_orig = lcZzoordrh_orig
2245 tcRefZzoordrd_orig = lcZzoordrd_orig
2246 tcRefZzoordsp_orig = lcZzoordsp_orig
2247
2248 Select(lnOldSelect)
2249 Return llRetVal
2250
2251 Endproc
2252
2253*-----------------------------------------------------------------------------------------
2254
2255 Procedure GetVerticalOpenOrder(pcZzoordrd_orig,pcRefZzoordrdv_Orig)
2256
2257 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2258 lnOldSelect = Select()
2259 llRetVal = .T.
2260 lcUnique = Sys(2015)
2261 lcZzoordrdv_orig = "#Zzoordrdv_orig" + lcUnique
2262
2263 *--- need to consider cncl_rsn, cncl_type
2264 *--- need to add rng_style, rng_color, rng_lbl, rng_pack to handle range style - 1032030
2265 *--- TR 1034532 NH - c860SODetailAddMatchCriteria
2266 LOCAL lcAddFlds
2267 IF !EMPTY(this.c860SODetailAddMatchCriteria)
2268 lcAddFlds = " d." + this.c860SODetailAddMatchCriteria + ", "
2269 ELSE
2270 lcAddFlds = ""
2271 ENDIF
2272
2273 *- 1041968 08/26/10 YIK
2274 *- Add Implosion
2275 lcAddFlds = lcAddFlds + 'Implosion, '
2276
2277 *--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ---
2278 && VKK 1067224
2279 lcAddFlds = lcAddFlds + 'Price, '
2280 && VKK 1067224
2281
2282 *- TR 1072045 FH 07/01/13
2283 lcAddFlds = lcAddFlds + 'Bulk_Red, Comm_calc, '
2284 lcAddFlds = lcAddFlds + 'bulk_resolved, ' &&--- TechRec 1085945 20-Aug-2015 vkrishnamurthy ===
2285 *- TR 1072045 FH 07/01/13
2286
2287 *=== TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
2288
2289 *--- TR 1072221 27-Jun-14 SK Added field 'edipo4udf1' in the select list ===
2290 *--- added lcAddFlds
2291 TEXT TO lcSQL NOSHOW
2292 select fkey, ord_num, pick_num, inv_num, line_seq, line_status, division, style, color_code, lbl_code, dimension, rng_style, rng_color, rng_lbl, rng_pack,
2293 b.size_num as sizebucket, cncl_rsn, cncl_type, lcAddFlds
2294 d.size01_qty * b.sz01 + d.size02_qty * b.sz02 + d.size03_qty * b.sz03 + d.size04_qty * b.sz04 + d.size05_qty * b.sz05 +
2295 d.size06_qty * b.sz06 + d.size07_qty * b.sz07 + d.size08_qty * b.sz08 + d.size09_qty * b.sz09 + d.size10_qty * b.sz10 +
2296 d.size11_qty * b.sz11 + d.size12_qty * b.sz12 + d.size13_qty * b.sz13 + d.size14_qty * b.sz14 + d.size15_qty * b.sz15 +
2297 d.size16_qty * b.sz16 + d.size17_qty * b.sz17 + d.size18_qty * b.sz18 + d.size19_qty * b.sz19 + d.size20_qty * b.sz20 +
2298 d.size21_qty * b.sz21 + d.size22_qty * b.sz22 + d.size23_qty * b.sz23 + d.size24_qty * b.sz24
2299 as size_qty, edipo4udf1
2300 into #Zzoordrdv_orig
2301 from #zzoordrd_orig d cross join zzxbuckt b
2302 where
2303 d.size01_qty * b.sz01 + d.size02_qty * b.sz02 + d.size03_qty * b.sz03 + d.size04_qty * b.sz04 + d.size05_qty * b.sz05 +
2304 d.size06_qty * b.sz06 + d.size07_qty * b.sz07 + d.size08_qty * b.sz08 + d.size09_qty * b.sz09 + d.size10_qty * b.sz10 +
2305 d.size11_qty * b.sz11 + d.size12_qty * b.sz12 + d.size13_qty * b.sz13 + d.size14_qty * b.sz14 + d.size15_qty * b.sz15 +
2306 d.size16_qty * b.sz16 + d.size17_qty * b.sz17 + d.size18_qty * b.sz18 + d.size19_qty * b.sz19 + d.size20_qty * b.sz20 +
2307 d.size21_qty * b.sz21 + d.size22_qty * b.sz22 + d.size23_qty * b.sz23 + d.size24_qty * b.sz24 > 0
2308 ENDTEXT
2309
2310 lcSql = STRTRAN(lcSql,"lcAddFlds",lcAddFlds)
2311 *=== TR 1034532 NH
2312
2313 lcSQL = Strtran(lcSQL,"#zzoordrd_orig",pcZzoordrd_orig)
2314 lcSQL = Strtran(lcSQL,"#Zzoordrdv_orig",lcZzoordrdv_orig)
2315 llRetVal = llRetVal And v_SQLExec(lcSQL)
2316
2317 pcRefZzoordrdv_orig = lcZzoordrdv_orig
2318 Select(lnOldSelect)
2319 Return llRetVal
2320
2321 Endproc
2322
2323*-----------------------------------------------------------------------------------------
2324
2325 *--- pcZzoordrdv - is vartical open order
2326 Procedure FirstLevelValidation(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig)
2327
2328 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2329 lnOldSelect = Select()
2330 llRetVal = .T.
2331
2332 *--- order must exists - exclude cancel orders
2333 llRetVal = llRetVal And This.CheckForExistingOrder(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig)
2334 llRetVal = llRetVal And This.CheckForExistingCarton(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig)
2335 llRetVal = llRetVal And This.CheckForExistingHardLink(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig)
2336
2337 Select(lnOldSelect)
2338 Return llRetVal
2339
2340 Endproc
2341
2342*-----------------------------------------------------------------------------------------
2343
2344 Procedure SetValue_Ord_num(pcZzeipcth, pcZzeipctd)
2345
2346 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2347 lnOldSelect = Select()
2348 llRetVal = .T.
2349
2350 *--- TechRec 1051992 15-Feb-2011 TShenbagavalli added condition 1 = case when th.conf_type = 'B' and th.ord_qty > 0 then 1 else 2 end ---
2351 *--- TR 1072834 20-Aug-2013 Goutam. Added condition and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))
2352 TEXT TO lcSQL NOSHOW
2353 update th set ord_num = h.ord_num from #zzeipcth th inner join zzoordrh h with (nolock)
2354 on th.po_num = h.po_num and th.customer = h.customer and th.store = h.store and th.division = h.division
2355 and 1 = case when h.conf_type = 'B' and h.ord_qty > 0 then 1 else 2 end
2356 where h.ord_status = 'O' AND th.errs_flg_h <> 'Y' AND (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))
2357 ENDTEXT
2358
2359 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2360 llRetVal = llRetVal And v_SQLExec(lcSQL)
2361
2362 *--- add ord_num field to zzeipctd
2363*!* lcSQL = "alter table " + pcZzeipctd + " add ord_num int "
2364*!* llRetVal = llRetVal And v_SQLExec(lcSQL)
2365
2366 TEXT TO lcSQL NOSHOW
2367 update td set ord_num = th.ord_num from #zzeipcth th inner join #zzeipctd td on th.pkey = td.fkey
2368 ENDTEXT
2369
2370 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2371 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2372 llRetVal = llRetVal And v_SQLExec(lcSQL)
2373
2374 Select(lnOldSelect)
2375 Return llRetVal
2376
2377 Endproc
2378
2379*-----------------------------------------------------------------------------------------
2380
2381 Procedure SecondLevelValidation(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrd_orig)
2382
2383 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2384 lnOldSelect = Select()
2385 llRetVal = .T.
2386
2387 *--- TR 1034532 NH : check order quantity
2388 LOCAL lcAddJoin, lcMsg_add
2389 IF EMPTY(this.c860SODetailAddMatchCriteria)
2390 lcAddJoin = ""
2391 lcMsg_add = ""
2392 ELSE
2393 lcAddJoin = " and td.LINE_ID = d." + THIS.c860SODetailAddMatchCriteria
2394 lcMsg_add = " + ' For CMS ID ' + td.LINE_ID"
2395 ENDIF
2396
2397 TEXT TO lcSQL NOSHOW
2398 Update td set errs_flg_d = 'Y' , errs_msg_d = cast(errs_msg_d as varchar(2000)) +
2399 'Order quantity is less than reduction quantity.' lcMsg_add + char(13) + char(10)
2400 from #zzeipctd td inner join #zzoordrdv_orig d on td.ord_num = d.ord_num and td.style = d.style and td.color_code = d.color_code
2401 and td.lbl_code = d.lbl_code and td.dimension = d.dimension and td.sizebucket = d.sizebucket
2402 and d.line_status = 'O' lcAddJoin
2403 WHERE td.qualifier = 'QD' and d.size_qty - td.qty_change < 0
2404 ENDTEXT
2405
2406 lcSQL = STRTRAN(lcSql,"lcAddJoin",lcAddJoin)
2407 lcSQL = STRTRAN(lcSql,"lcMsg_add",lcMsg_add)
2408 *=== TR 1034532 NH
2409
2410 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2411 lcSQL = Strtran(lcSQL,"#zzoordrdv_orig",pcZzoordrdv_orig)
2412 llRetVal = llRetVal And v_SQLExec(lcSQL)
2413
2414 *---- QD with zero qty.
2415 *--- TR 1034532 NH - Added contion - lcAddJoin
2416 TEXT TO lcSQL NOSHOW
2417 Update td set errs_flg_d = 'Y' , errs_msg_d = cast(errs_msg_d as varchar(2000)) +
2418 'Quantity must be more than zero for qualifier QD.' lcMsg_add + char(13) + char(10)
2419 from #zzeipctd td inner join #zzoordrdv_orig d on td.ord_num = d.ord_num and td.style = d.style and td.color_code = d.color_code
2420 and td.lbl_code = d.lbl_code and td.dimension = d.dimension and td.sizebucket = d.sizebucket
2421 and d.line_status = 'O' lcAddJoin
2422 WHERE td.qualifier = 'QD' and td.qty_change < 1
2423 ENDTEXT
2424
2425 lcSQL = STRTRAN(lcSql,"lcAddJoin",lcAddJoin) &&--- TR 1034532 NH
2426 lcSQL = STRTRAN(lcSql,"lcMsg_add",lcMsg_add) &&--- TR 1034532 NH
2427
2428 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2429 lcSQL = Strtran(lcSQL,"#zzoordrdv_orig",pcZzoordrdv_orig)
2430 llRetVal = llRetVal And v_SQLExec(lcSQL)
2431
2432 *--- date validation
2433 *--- if transaction start data is later than order end date we error it out
2434 *--- if transaction end data is earlier than order start date then we error it out
2435 llRetVal = llRetVal and this.DateChangeValidation(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrd_orig)
2436
2437 Select(lnOldSelect)
2438 Return llRetVal
2439 Endproc
2440
2441*-----------------------------------------------------------------------------------------
2442
2443 PROCEDURE DateChangeValidation(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrd_orig)
2444
2445 Local llRetVal, lnOldSelect, lcUnique, lcSQL
2446 lnOldSelect = Select()
2447 llRetVal = .T.
2448
2449 *--- Transaction end_Date should be later than start date
2450 lcSql = " UPDATE th SET errs_flg_h = 'Y', errs_msg_h = CAST(errs_msg_h as varchar(2000)) + " + ;
2451 " 'Transaction start date ' + convert(varchar(19), th.start_date,1) + " + ;
2452 " ' is later than Transaction end date' + convert(varchar(19),th.end_date,1) + '.' + char(13) + char(10) " + ;
2453 " FROM " + pcZzeipcth + " th " + ;
2454 " WHERE th.start_date > {ts '1900-01-01 00:00:00.000'} " + ;
2455 " and th.end_date > {ts '1900-01-01 00:00:00.000'} " + ;
2456 " and th.start_date > th.end_date "
2457
2458 llRetVal = llRetVal and v_sqlexec(lcSQL)
2459
2460 *--- Transaction detail end_Date should be later than start date
2461
2462 lcSql = " UPDATE td SET errs_flg_d = 'Y', errs_msg_d = CAST(errs_msg_d as varchar(2000)) + " + ;
2463 " 'Transaction start date ' + convert(varchar(19), td.start_date,1) + " + ;
2464 " ' is later than Transaction end date' + convert(varchar(19),td.end_date,1) + '.' + char(13) + char(10) " + ;
2465 " FROM " + pcZzeipctd + " td " + ;
2466 " WHERE td.start_date > {ts '1900-01-01 00:00:00.000'} " + ;
2467 " and td.end_date > {ts '1900-01-01 00:00:00.000'} " + ;
2468 " and td.start_date > td.end_date "
2469
2470 llRetVal = llRetVal and v_sqlexec(lcSQL)
2471
2472
2473 *--- detail validation - start date
2474 *--- check order quantity
2475 *--- TR 1034532 NH
2476 LOCAL lcAddJoin, lcMsg_add
2477 IF EMPTY(this.c860SODetailAddMatchCriteria)
2478 lcAddJoin = ""
2479 lcMsg_add = ""
2480 ELSE
2481 lcAddJoin = " And td.LINE_ID = od." + THIS.c860SODetailAddMatchCriteria
2482 lcMsg_add = " + ' For CMS ID ' + td.LINE_ID"
2483 ENDIF
2484
2485 lcSQL = " UPDATE td SET errs_flg_d = 'Y', errs_msg_d = CAST(errs_msg_d as varchar(2000)) + " + ;
2486 " 'Transaction detail start date ' + convert(varchar(19), td.start_date,1) + " + ;
2487 " ' is later than order end date ' + convert(varchar(19), od.end_date,1) + '.' " + lcMsg_add + ; &&--- TR 1034532 NH
2488 " + char(13) + char(10) " + ;
2489 " FROM " + pcZzeipctd + " td INNER JOIN " + pcZzoordrd_orig + " od ON od.ord_num = td.ord_num " + ;
2490 " and od.division = td.division and od.style = td.style and od.color_code = td.color_code " + ;
2491 " and od.lbl_code = td.lbl_code and od.dimension = td.dimension and od.line_status = 'O' " + ;
2492 " and td.qualifier = 'CT' AND td.start_date > od.end_date " + ;
2493 " and td.start_date > od.end_date " + ;
2494 " and td.end_date = {ts '1900-01-01 00:00:00.000'} " + lcAddJoin &&--- TR 1034532 NH
2495
2496 llRetVal = llRetVal and v_sqlexec(lcSQL)
2497
2498 *--- detail validation - end date
2499 *- TR 1063688 FH - reversed td.end_date > od.start_date to "td.end_date < od.start_date"
2500 lcSQL = " UPDATE td SET errs_flg_d = 'Y', errs_msg_d = CAST(errs_msg_d as varchar(2000)) + " + ;
2501 " 'Transaction detail end date ' + convert(varchar(19), td.end_date,1) + " + ;
2502 " ' is earlier than order start date ' + convert(varchar(19), od.start_date,1) + '.' " + lcMsg_add +;
2503 " + char(13) + char(10) " + ;
2504 " FROM " + pcZzeipctd + " td INNER JOIN " + pcZzoordrd_orig + " od ON od.ord_num = td.ord_num " + ;
2505 " and od.division = td.division and od.style = td.style and od.color_code = td.color_code " + ;
2506 " and od.lbl_code = td.lbl_code and od.dimension = td.dimension and od.line_status = 'O' " + ;
2507 " and td.qualifier = 'CT' AND td.end_date < od.start_date " + lcAddJoin &&--- TR 1034532 NH
2508
2509
2510 llRetVal = llRetVal and v_sqlexec(lcSQL)
2511
2512 *--- header validation - start date : check if order end is also getting updated by trans end date
2513 lcSQL = " UPDATE th SET errs_flg_h = 'Y', errs_msg_h = CAST(errs_msg_h as varchar(2000)) + " + ;
2514 " 'Transaction start date ' + convert(varchar(19), th.start_date,1) + " + ;
2515 " ' is later than order end date' + convert(varchar(19),oh.end_date,1) + '.' + char(13) + char(10) " + ;
2516 " FROM " + pcZzeipcth + " th INNER JOIN " + pcZzoordrh_orig + " oh ON oh.ord_num = th.ord_num and oh.ord_status = 'O'" + ;
2517 " WHERE th.start_date > {ts '1900-01-01 00:00:00.000'} and th.start_date > oh.end_date " + ;
2518 " and th.end_date = {ts '1900-01-01 00:00:00.000'} "
2519
2520 llRetVal = llRetVal and v_sqlexec(lcSQL)
2521
2522 *--- header validation - end date
2523 lcSQL = " UPDATE th SET errs_flg_h = 'Y', errs_msg_h = CAST(errs_msg_h as varchar(2000)) + " + ;
2524 " 'Transaction end data ' + convert(varchar(19), th.end_date, 1) + " + ;
2525 " ' is earlier than order start date' + convert(varchar(19), oh.start_date,1) + '.' + char(13) + char(10) " + ;
2526 " FROM " + pcZzeipcth + " th INNER JOIN " + pcZzoordrh_orig + " oh ON oh.ord_num = th.ord_num and oh.ord_status = 'O'" + ;
2527 " WHERE th.end_date > {ts '1900-01-01 00:00:00.000'} and th.end_date < oh.start_date " + ;
2528 " and th.start_date = {ts '1900-01-01 00:00:00.000'} "
2529
2530 llRetVal = llRetVal and v_sqlexec(lcSQL)
2531
2532 Select(lnOldSelect)
2533 Return llRetVal
2534 Endproc
2535
2536*-----------------------------------------------------------------------------------------
2537
2538 Procedure FlagHeaderForDetailError(pcZzeipcth, pcZzeipctd)
2539
2540 Local llRetVal, lnOldSelect, lcSQL
2541 lnOldSelect = Select()
2542 llRetVal = .T.
2543 *--- FLAG header for detail error
2544 lcSQL = "UPDATE th SET errs_flg_h = 'Y', errs_msg_h = 'Error in Detail' FROM " + pcZzeipcth + " th INNER JOIN " + pcZzeipctd + ;
2545 " td ON th.pkey = td.fkey where td.errs_flg_d = 'Y' AND th.errs_flg_h <> 'Y'"
2546 llRetVal = llRetVal And v_SQLExec(lcSQL)
2547
2548 Select(lnOldSelect)
2549 Return llRetVal
2550 Endproc
2551
2552*-----------------------------------------------------------------------------------------
2553
2554 Procedure CheckForExistingCarton(pcZzeipcth, pcZzeipctd, pcZzoordrdv)
2555 Local llRetVal, lnOldSelect
2556 lnOldSelect = Select()
2557 llRetVal = .T.
2558
2559 *--- order has been cartonized
2560 TEXT TO lcSQL NOSHOW
2561 update th set errs_flg_h = 'Y', errs_msg_h = cast(errs_msg_h as varchar(2000)) + 'Sales Order detail line is partially or fully cartonized.' + char(13) + char(10)
2562 FROM zzoctnpd d WITH (NOLOCK)
2563 INNER JOIN zzoctnph h WITH (NOLOCK) ON h.pkey = d.fkey
2564 INNER JOIN zzoordsp s WITH (NOLOCK) ON s.pkey = h.fkey
2565 INNER JOIN zzoordrh oh WITH (NOLOCK) ON oh.ord_num = s.ord_num and oh.pick_num = s.pick_num and oh.inv_num = s.inv_num
2566 INNER JOIN #zzeipcth th on th.po_num = oh.po_num and th.customer = oh.customer and th.store = oh.store and th.division = oh.division
2567 ENDTEXT
2568
2569 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2570 llRetVal = llRetVal And v_SQLExec(lcSQL)
2571 Select(lnOldSelect)
2572 Return llRetVal
2573
2574 Endproc
2575
2576*-----------------------------------------------------------------------------------------
2577
2578 Procedure CheckForExistingOrder(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig)
2579
2580 Local llRetVal, lnOldSelect
2581 lnOldSelect = Select()
2582 llRetVal = .T.
2583 *--- TR 1048865 17-Mar-2011 Goutam. REmoved ith.customer = r.customer and ith.division = r.division and made it ith.cr_pkey = r.pkey
2584 *--- TR 1053720 18-May-2011 Goutam. Added #zzeipctd and where condition and h.ord_status <> 'C' OR (itd.qualifier = 'AI' OR (itd.qualifier = 'RZ' and itd.qty_change > 0) ;
2585 Added zzeipccr in the main sql. Removed h.ord_status <> 'C' from the join
2586
2587 *--- TR 1063610 12-Nov-2012 BNarayanan modified in where clause itd.qualifier = 'AI' to itd.qualifier in ('AI' , 'QI')
2588 TEXT TO lcSQL NOSHOW
2589 update th set errs_flg_h =
2590 CASE WHEN h.pkey is null then 'Y'
2591 WHEN h.ord_status = 'P' then 'Y'
2592 WHEN ih.ord_status = 'I' then 'Y'
2593 ELSE errs_flg_h END
2594 , errs_msg_h = cast( th.errs_msg_h as varchar(2000)) +
2595 CASE WHEN h.pkey is null then 'Corresponding sales order not found.' + char(13) + char(10)
2596 WHEN h.ord_status = 'P' then 'Corresponding pick order found.' + char(13) + char(10)
2597 WHEN ih.ord_status = 'I' then 'Corresponding invoice found.' + char(13) + char(10)
2598 ELSE '' end
2599 from #zzeipcth th
2600 join #zzeipctd itd
2601 on itd.fkey = th.pkey
2602 join zzeipccr c on c.pkey = th.cr_pkey
2603 left outer join zzoordrh h (nolock) on h.po_num = th.po_num and h.customer = th.customer
2604 /* and h.store = th.store -- TR 1062197 10-Sep-2012 Goutam*/
2605 and (th.store = case when (poc_purp = '04' and poc_store > '') then th.store else h.store end) -- TR 1062197 10-Sep-2012 Goutam
2606 and h.division = th.division
2607 /* and h.ord_status <> 'C' */
2608 left outer join zzoshprh ih (nolock) on ih.po_num = th.po_num and ih.customer = th.customer and ih.store = th.store and ih.division = th.division
2609 WHERE not exists (select * from #zzeipcth ith inner join #zzeipctd td on ith.pkey = td.fkey and (td.qualifier in ('AI' , 'QI') OR (td.qualifier = 'RZ' and td.qty_change > 0 ))
2610 inner join zzoordrh h (nolock) on h.po_num = ith.po_num and h.customer = ith.customer
2611 inner join zzeipccr r on /*ith.customer = r.customer and ith.division = r.division*/ ith.cr_pkey = r.pkey and r.new_order = 'Y'
2612 where ith.pkey = th.pkey and h.ord_status <> 'C')
2613 and h.ord_status <> 'C' OR Not ((itd.qualifier in ('AI' , 'QI') OR (itd.qualifier = 'RZ' and itd.qty_change > 0)) and c.new_order = 'Y')
2614 ENDTEXT
2615*
2616 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2617 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2618 llRetVal = llRetVal And v_SQLExec(lcSQL)
2619
2620 *--- order detail must exists
2621 *--- do not error out when it qualifier is RZ with quantity increase or AI
2622*!* TEXT TO lcSQL NOSHOW
2623*!* update td set errs_flg_d = CASE WHEN d.ord_num is null and td.qualifier not in ('AI') then 'Y' else errs_flg_d end
2624*!* , errs_msg_d = cast( td.errs_msg_d as varchar(2000)) +
2625*!* CASE WHEN d.ord_num is null and td.qualifier not in ('AI') then 'Corresponding sales order line item (size bucket) not found.' + char(13) + char(10)
2626*!* ELSE '' end
2627*!* from #zzeipctd td inner join #zzeipcth th on th.pkey = td.fkey and th.errs_flg_h <> 'Y' AND th.poc_purp <> '01'
2628*!* left outer join zzoordrh h (nolock) on h.po_num = th.po_num and h.customer = th.customer and h.store = th.store and h.division = th.division
2629*!* and h.ord_status = 'O'
2630*!* left outer join #zzoordrdv_orig d on h.pkey = d.fkey and d.style = td.style and d.color_code = td.color_code and d.lbl_code = td.lbl_code
2631*!* and d.dimension = td.dimension and d.sizebucket = td.sizebucket
2632*!* WHERE not exists (select * from #zzeipcth ith inner join #zzeipctd itd on ith.pkey = itd.fkey and (itd.qualifier in ('AI' , 'QI') OR (itd.qualifier = 'RZ' and itd.qty_change > 0 ))
2633*!* inner join zzoordrh ih (nolock) on ih.po_num = ith.po_num and ih.customer = ith.customer
2634*!* inner join zzeipccr r on ith.customer = r.customer and ith.division = r.division and r.new_order = 'Y'
2635*!* where itd.pkey = td.pkey)
2636
2637*!* ENDTEXT
2638
2639 *--- TR 1034532 NH
2640 LOCAL lcAddJoin, lcAddMsg
2641 IF EMPTY(this.c860SODetailAddMatchCriteria)
2642 lcAddJoin = ""
2643 lcAddMsg = " + '.' "
2644 lcAddCase_flg = ""
2645 lcAddCase_msg = ""
2646 ELSE
2647 lcAddJoin = " and td.line_id = d." + this.c860SODetailAddMatchCriteria
2648 lcAddMsg = " + case when td.line_id = '' then '.' else ' for CMS ID ' + td.line_id + '.' end "
2649 lcAddCase_flg = " when h.ord_num is NOT null /* order is found */ and d.ord_num is null /* order line not found */ " + ;
2650 " and (td.qualifier <> 'AI' and td.LINE_ID > '') then 'Y' "
2651 lcAddCase_msg = " when h.ord_num is NOT null /* order is found */ and d.ord_num is null /* order line not found */ " + ;
2652 " and (td.qualifier <> 'AI' and td.LINE_ID > '') then 'Corresponding sales order line item (size bucket) not found.' " + ;
2653 lcAddMsg + " + char(13) + char(10) "
2654 ENDIF
2655
2656
2657*!* TEXT TO lcSQL NOSHOW
2658*!* update td set errs_flg_d = CASE WHEN d.ord_num is null and NOT (td.qualifier = 'AI' OR (td.qualifier = 'RZ' and td.qty_change > 0 )) then 'Y' else errs_flg_d end
2659*!* , errs_msg_d = cast( td.errs_msg_d as varchar(2000)) +
2660*!* CASE WHEN d.ord_num is null and NOT (td.qualifier = 'AI' OR (td.qualifier = 'RZ' and td.qty_change > 0 ))
2661*!* then 'Corresponding sales order line item (size bucket) not found.' lcAddMsg + char(13) + char(10)
2662*!* ELSE '' end
2663*!* from #zzeipctd td inner join #zzeipcth th on th.pkey = td.fkey and th.errs_flg_h <> 'Y' AND th.poc_purp <> '01'
2664*!* left outer join zzoordrh h (nolock) on h.po_num = th.po_num and h.customer = th.customer and h.store = th.store and h.division = th.division
2665*!* and h.ord_status = 'O'
2666*!* left outer join #zzoordrdv_orig d on h.pkey = d.fkey and d.style = td.style and d.color_code = td.color_code and d.lbl_code = td.lbl_code
2667*!* and d.dimension = td.dimension and d.sizebucket = td.sizebucket lcAddJoin
2668*!* WHERE not exists (select * from #zzeipcth ith inner join #zzeipctd itd on ith.pkey = itd.fkey and (itd.qualifier in ('AI' , 'QI') OR (itd.qualifier = 'RZ' and itd.qty_change > 0 ))
2669*!* inner join zzoordrh ih (nolock) on ih.po_num = ith.po_num and ih.customer = ith.customer
2670*!* inner join zzeipccr r on ith.customer = r.customer and ith.division = r.division and r.new_order = 'Y'
2671*!* where itd.pkey = td.pkey)
2672*!* ENDTEXT
2673
2674 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = th.customer and r.division = th.division and added r.pkey = th.cr_pkey
2675 *--- TR 1053720 18-May-2011 Goutam. Added or ((td.qualifier = 'AI' or (td.qualifier = 'RZ' and td.qty_change > 0)) and r.new_order = 'Y')) ;
2676 and moved zzeipccr join to top after #zzeipcth join
2677 TEXT TO lcSql noshow
2678 update td set
2679 errs_flg_d = CASE WHEN h.ord_num is null /* order not found */ and d.ord_num is null /* order line not found */
2680 and NOT ((td.qualifier in ( 'AI', 'QI') OR (td.qualifier = 'RZ' and td.qty_change > 0 )) and r.new_order = 'Y')
2681 then 'Y'
2682 WHEN h.ord_num is NOT null /* order is found */ and d.ord_num is null /* order line not found */
2683 and NOT (td.qualifier in ( 'AI', 'QI') /*--- TR 1050485 OR (td.qualifier = 'RZ' and td.qty_change > 0)*/) And td.qualifier = 'RZ' /*=== TR 1050485*/
2684 then 'Y'
2685 lcAddCase_flg
2686 else td.errs_flg_d end
2687 , errs_msg_d = cast( td.errs_msg_d as varchar(2000)) +
2688 CASE WHEN h.ord_num is null /* order not found */ and d.ord_num is null /* order line not found */
2689 and NOT ((td.qualifier in ( 'AI', 'QI') OR (td.qualifier = 'RZ' and td.qty_change > 0 )) and r.new_order = 'Y')
2690 then 'Corresponding sales order line item (size bucket) not found' lcAddMsg + char(13) + char(10)
2691 WHEN h.ord_num is NOT null /* order is found */ and d.ord_num is null /* order line not found */
2692 and NOT (td.qualifier in ( 'AI', 'QI') /*--- TR 1050485 OR (td.qualifier = 'RZ' and td.qty_change > 0)*/) And td.qualifier = 'RZ' /*=== TR 1050485*/
2693 then 'Corresponding sales order line item (size bucket) not found' lcAddMsg + char(13) + char(10)
2694 lcAddCase_msg
2695 else '' end
2696 from #zzeipctd td inner join #zzeipcth th on th.pkey = td.fkey AND th.poc_purp <> '01'
2697 inner join zzeipccr r on r.pkey = th.cr_pkey
2698 left outer join zzoordrh h (nolock) on h.po_num = th.po_num and h.customer = th.customer and h.store = th.store and h.division = th.division
2699 and (h.ord_status = 'O' or ((td.qualifier = 'AI' or (td.qualifier = 'RZ' and td.qty_change > 0)) and r.new_order = 'Y'))
2700 left outer join #zzoordrdv_orig d on th.ord_num = d.ord_num and d.style = td.style and d.color_code = td.color_code and d.lbl_code = td.lbl_code
2701 and d.dimension = td.dimension and d.sizebucket = td.sizebucket AND d.line_status = 'O' lcAddJoin
2702 /*inner join zzeipccr r on /*r.customer = th.customer and r.division = th.division */ r.pkey = th.cr_pkey*/
2703 ENDTEXT
2704
2705 lcSql = STRTRAN(lcSql,"lcAddJoin",lcAddJoin)
2706 lcSql = STRTRAN(lcSql,"lcAddMsg",lcAddMsg)
2707 lcSql = STRTRAN(lcSql,"lcAddCase_flg",lcAddCase_flg)
2708 lcSql = STRTRAN(lcSql,"lcAddCase_msg",lcAddCase_msg)
2709 *=== TR 1034532 NH
2710
2711 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2712 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2713 lcSQL = Strtran(lcSQL,"#zzoordrdv_orig",pcZzoordrdv_orig)
2714 llRetVal = llRetVal And v_SQLExec(lcSQL)
2715
2716 *--- TechRec 1067224 18-Mar-2013 vkrishnamurthy ---
2717 && To validate ZZEIPCTD Division, STyle,Color_code, lbl_code, dimension , sizebucket for qualifier = 'DI' ,'QI' or 'QD'
2718 lcSQL = "update td "+;
2719 " set errs_flg_d = 'Y'"+;
2720 " , errs_msg_d = cast( td.errs_msg_d as varchar(2000)) + 'Item not found.' + char(13) + char(10) "+;
2721 " from " + pcZzeipctd + " td "+;
2722 " inner join " + pcZzeipcth+ " th "+;
2723 " on th.pkey = td.fkey "+;
2724 " and th.poc_purp <> '01' "+;
2725 " inner join zzeipccr r "+;
2726 " on r.pkey = th.cr_pkey "+;
2727 " left outer join zzoordrh h (nolock) "+;
2728 " on h.po_num = th.po_num "+;
2729 " and h.customer = th.customer "+;
2730 " and h.store = th.store "+;
2731 " and h.division = th.division "+;
2732 " and h.ord_status = 'O' "+;
2733 " left outer join Zveupcnr U "+;
2734 " on U.Upc = td.upc "+;
2735 " left outer join "+ pcZzoordrdv_orig + " d "+;
2736 " on th.ord_num = d.ord_num "+;
2737 " and d.style = u.style "+;
2738 " and d.color_code = u.color_code "+;
2739 " and d.lbl_code = u.lbl_code "+;
2740 " and d.dimension = u.dimension "+;
2741 " and d.sizebucket = u.sizebucket "+;
2742 " and d.line_status = 'O' "+;
2743 " where ( U.Upc is Null Or d.ord_num is Null )"+ ;
2744 " and r.template = "+ SQLFormatChar('SEARS CANADA 4030') + ;
2745 " and (td.qualifier = 'DI' or td.qualifier ='QI' or td.qualifier ='QD') "
2746
2747 llRetVal = llRetVal And v_SQLExec(lcSQL)
2748 *=== TechRec 1067224 18-Mar-2013 vkrishnamurthy ===
2749
2750 *--- TR 1072834 19-Aug-2013 Goutam
2751 lcSQL = "update td "+;
2752 " set warn_flg_d = 'Y'"+;
2753 " , warn_msg_d = cast( td.warn_msg_d as varchar(2000)) + 'Corresponding sales order line item not found.' + char(13) + char(10) "+;
2754 " from " + pcZzeipctd + " td "+;
2755 " inner join " + pcZzeipcth+ " th "+;
2756 " on th.pkey = td.fkey "+;
2757 " and th.poc_purp <> '01' "+;
2758 " inner join zzeipccr r "+;
2759 " on r.pkey = th.cr_pkey "+;
2760 " left outer join zzoordrh h (nolock) "+;
2761 " on h.po_num = th.po_num "+;
2762 " and h.customer = th.customer "+;
2763 " and h.store = th.store "+;
2764 " and h.division = th.division "+;
2765 " and h.ord_status = 'O' "+;
2766 " left outer join Zveupcnr U "+;
2767 " on U.Upc = td.upc "+;
2768 " left outer join "+ pcZzoordrdv_orig + " d "+;
2769 " on th.ord_num = d.ord_num "+;
2770 " and d.style = u.style "+;
2771 " and d.color_code = u.color_code "+;
2772 " and d.lbl_code = u.lbl_code "+;
2773 " and d.dimension = u.dimension "+;
2774 " and d.sizebucket = u.sizebucket "+;
2775 " and d.line_status = 'O' "+;
2776 " where ( U.Upc is Null Or d.ord_num is Null )"+ ;
2777 " and th.ignore_warn = 'N'" + ;
2778 " and r.template <> " + SQLFormatChar('SEARS CANADA 4030') + ;
2779 " and (td.qualifier = 'DI' or td.qualifier ='QI' or td.qualifier ='QD')"
2780
2781 llRetVal = llRetVal And v_SQLExec(lcSQL)
2782 *=== TR 1072834 19-Aug-2013 Goutam
2783
2784 Select(lnOldSelect)
2785 Return llRetVal
2786
2787 Endproc
2788
2789*-----------------------------------------------------------------------------------------
2790
2791 Procedure CheckForExistingHardLink(pcZzeipcth, pcZzeipctd, pcZzoordrdv)
2792
2793 Local llRetVal, lnOldSelect
2794 lnOldSelect = Select()
2795 llRetVal = .T.
2796
2797 *--- Sales Order detail line is hardlinked to a production order.
2798 *--- added "and ud.prod_num > 0 and ud.Open_seq > 0" to avoid error out for production order hand link when there is no production order number present
2799 *--- TR 1034532 NH : check this only for DI - delete item
2800 LOCAL lcAddJoin
2801
2802 *- 1044846 01/13/10 YIK
2803 *- If zzxcompr.hrdlnk_ok = 'Y' and zzeipccr is set to restrict hard link updates (check_hdlk = 'Y') - error out.
2804 IF EMPTY(this.c860SODetailAddMatchCriteria)
2805 lcAddJoin = ""
2806 lcAddFilter = "where cm.hrdlnk_ok = 'Y' AND r.check_hdlk = 'Y'"
2807 ELSE
2808 lcAddJoin = " and td.LINE_ID = od." + THIS.c860SODetailAddMatchCriteria
2809 lcAddFilter = " where cm.hrdlnk_ok = 'Y' AND r.check_hdlk = 'Y' AND (td.qualifier = 'DI' OR (td.qualifier = 'RZ' and td.qty_change = od.size_qty))"
2810 ENDIF
2811
2812 *- 1044846 01/13/10 YIK
2813 *- Added JOIN zzxcompr cm on 1 = 1
2814 *- JOIN zzeipccr r ON r.customer = oh.customer and r.division = oh.division
2815 *--- TR 1039961 MAY-29-2009 BR - ADDED join to zzeipccr to account for check_hdlk flag being 'Y', shouldnt error out if set to 'N'
2816 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = oh.customer and r.division = oh.division and added r.pkey = th.cr_pkey
2817 TEXT TO lcSQL NOSHOW
2818 update td set errs_flg_d = 'Y', errs_msg_d = cast(errs_msg_d as varchar(2000)) + 'Sales Order detail line is hardlinked to a production order.'
2819 from #zzeipctd td inner join #zzeipcth th on th.pkey = td.fkey
2820 Inner join zzoordrh oh with (nolock) on th.po_num = oh.po_num and th.customer = oh.customer and th.store = oh.store and th.division = oh.division
2821 inner join #zzoordrdv od with (nolock) on oh.pkey = od.fkey and td.style = od.style and td.color_code = od.color_code and td.lbl_code = od.lbl_code
2822 and td.dimension = od.dimension and od.line_status = 'O' and od.sizebucket = td.sizebucket lcAddJoin
2823 inner join zzoordud ud on ud.ord_num = od.ord_num and ud.line_seq = od.line_seq and ud.prod_num > 0 and ud.Open_seq > 0
2824 JOIN zzxcompr cm on 1 = 1
2825 JOIN zzeipccr r ON /*r.customer = oh.customer and r.division = oh.division */ r.pkey = th.cr_pkey
2826 lcAddFilter
2827 ENDTEXT
2828
2829 lcSql = STRTRAN(lcSql,"lcAddJoin",lcAddJoin)
2830 lcSql = STRTRAN(lcSql,"lcAddFilter",lcAddFilter)
2831 lcSql = STRTRAN(lcSql,"#zzoordrdv",pcZzoordrdv)
2832 *=== TR 1034532 NH
2833
2834 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
2835 lcSQL = Strtran(lcSQL,"#zzeipctd",pcZzeipctd)
2836 llRetVal = llRetVal And v_SQLExec(lcSQL)
2837 Select(lnOldSelect)
2838 Return llRetVal
2839
2840 Endproc
2841
2842*-----------------------------------------------------------------------------------------
2843
2844 PROCEDURE UpdateDelvCodeAtServerTempTable(pcZzoordrd_update,pcZzoordrd_cur)
2845
2846 Local llRetVal, lnOldSelect
2847
2848 lnOldSelect = Select()
2849 llRetVal = .T.
2850
2851 this.cSQLTempTable = ""
2852 llRetVal = llRetVal and this.GenerateSQLTempTable(pcZzoordrd_cur)
2853 IF RECCOUNT(pcZzoordrd_cur) > 0 &&--- 1035297 NH 08/14/08
2854 llRetVal = llRetVal and this.PopulateSQLTempTable(pcZzoordrd_cur)
2855
2856 lcSQL = " UPDATE d SET delv_code = td.delv_code FROM " + pcZzoordrd_update + ;
2857 " d INNER JOIN " + this.cSQLTempTable + " td ON td.pkey = d.pkey "
2858 llRetVal = llRetVal and v_sqlexec(lcSQL)
2859 ENDIF &&--- 1035297 NH 08/14/08
2860
2861 Select(lnOldSelect)
2862 Return llRetVal
2863
2864 Endproc
2865
2866*-----------------------------------------------------------------------------------------
2867
2868 Procedure SetDelvCodeForQualifierAI(pcZzoordrh_update,pcZzoordrd_update,pcZzeipctd)
2869
2870 Local llRetVal, lnOldSelect
2871 lnOldSelect = Select()
2872 llRetVal = .T.
2873
2874 IF NOT this.oMainProcess.lResl_Delv
2875 RETURN .t.
2876 ENDIF
2877
2878 LOCAL lcZzoordrh_cur, lcZzoordrd_cur, loZzoordrh, lcUnique
2879 lcUnique = SYS(2015)
2880 lcZzoordrh_cur = "zzoordrh" + lcUnique
2881 lcZzoordrd_cur = "zzoordrd" + lcUnique
2882 *--- pcZzoordrd_update must have the new order lines (AI)
2883 llRetVal = llRetVal and this.CreateSoCursorForDelvCode(pcZzoordrh_update,pcZzoordrd_update, pcZzeipctd,lcZzoordrh_cur, lcZzoordrd_cur)
2884 llRetVal = llRetVal and this.ResolveDelvCode(lcZzoordrh_cur,lcZzoordrd_cur)
2885 llRetVal = llRetVal and this.UpdateDelvCodeAtServerTempTable(pcZzoordrd_update,lcZzoordrd_cur)
2886 this.LogEntry("Update order detail delivery code " + IIF(llRetVal,"completed.","failed."))
2887
2888 Select(lnOldSelect)
2889 Return llRetVal
2890
2891 Endproc
2892
2893*-----------------------------------------------------------------------------------------
2894
2895 PROCEDURE CreateSoCursorForDelvCode(pcZzoordrh_update,pcZzoordrd_update, pcZzeipctd, pcZzoordrh_cur, pcZzoordrd_cur)
2896
2897 Local llRetVal, lnOldSelect
2898 lnOldSelect = Select()
2899 llRetVal = .T.
2900
2901 lcSQL = " SELECT d.* FROM " + pcZzoordrd_update + " d " + ;
2902 " where exists (select * from " + pcZzeipctd + " td " + ;
2903 " where td.ord_num = d.ord_num and td.style = d.style " + ;
2904 " and td.color_code = d.color_code and td.lbl_code = d.lbl_code " + ;
2905 " and td.dimension = d.dimension and td.qualifier = 'AI' " + ;
2906 " and d.line_status = 'O') "
2907
2908 llRetVal = llRetVal and v_sqlexec(lcSQL,pcZzoordrd_cur)
2909
2910
2911 &&--- TechRec 1075895/1073591 20-Mar-2014 vkrishnamurthy === added this.GetSOFieldListWithoutUDF("h.", "zzoordrh")
2912 lcSQL = " SELECT "+ this.GetSOFieldListWithoutUDF("h.", "zzoordrh")+ " FROM " + pcZzoordrh_update + " h " + ;
2913 " where exists " + ;
2914 " (SELECT * FROM " + pcZzoordrd_update + " d " + ;
2915 " where exists (select * from " + pcZzeipctd + " td " + ;
2916 " where td.ord_num = d.ord_num and td.style = d.style " + ;
2917 " and td.color_code = d.color_code and td.lbl_code = d.lbl_code " + ;
2918 " and td.dimension = d.dimension and td.qualifier = 'AI' and d.line_status = 'O') " + ;
2919 " and h.pkey = d.fkey ) "
2920
2921 llRetVal = llRetVal and v_sqlexec(lcSQL,pcZzoordrh_cur)
2922
2923 IF llRetVal
2924 SELECT(pcZzoordrd_cur)
2925 INDEX on fkey TAG fkey
2926
2927 SELECT(pcZzoordrh_cur)
2928 INDEX on pkey TAG pkey
2929
2930 ENDIF
2931 Select(lnOldSelect)
2932 Return llRetVal
2933
2934 Endproc
2935
2936*-----------------------------------------------------------------------------------------
2937
2938 PROCEDURE ResolveDelvCode(pcZzoordrh_cur,pcZzoordrd_cur)
2939
2940 Local llRetVal, lnOldSelect,loZzoordrh
2941 lnOldSelect = Select()
2942 llRetVal = .T.
2943
2944 SELECT (pcZzoordrd_cur)
2945 SET ORDER TO fkey
2946
2947 SELECT (pcZzoordrh_cur)
2948 SET ORDER TO pkey
2949
2950 SCAN
2951 SCATTER FIELDS pkey NAME loZzoordrh
2952 IF SEEK(loZzoordrh.pkey,pcZzoordrd_cur,"fkey")
2953 SELECT(pcZzoordrd_cur)
2954 SCAN WHILE fkey = loZzoordrh.pkey
2955 IF NOT this.oMainProcess.oBPOSalesOrder.ResolveDelvCode2(pcZzoordrh_cur, pcZzoordrd_cur)
2956 THIS.LogEntry("Delivery Code not resolved for PO# " + ;
2957 EVALUATE(pcZzoordrh_cur + ".Po_num") + ", customer " + EVALUATE(pcZzoordrh_cur + ".customer"))
2958 ENDIF
2959 ENDSCAN
2960 ENDIF
2961 ENDSCAN
2962
2963 Select(lnOldSelect)
2964 Return llRetVal
2965
2966 Endproc
2967
2968*-----------------------------------------------------------------------------------------
2969
2970 PROCEDURE GetOrderInsertSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, pcRefInsertSQL_zzoordrh, pcRefInsertSQL_zzoordrd, pcRefInsertSQL_zzoordSP)
2971
2972 Local llRetVal, lnOldSelect
2973 lnOldSelect = Select()
2974 llRetVal = .T.
2975 LOCAL lcInsertSQL_zzoordrh, lcInsertSQL_zzoordrd, lcInsertSQL_zzoordSP
2976 STORE "" TO lcInsertSQL_zzoordrh, lcInsertSQL_zzoordrd, lcInsertSQL_zzoordSP
2977
2978 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
2979 lnOldSelect = Select()
2980 llRetVal = .T.
2981
2982 lcFlds = ""
2983 lcValues = ""
2984 lcExcludeFlds = ""
2985 lcCalFlds = ""
2986 lcCalFldsValues = ""
2987
2988 *--- Order Header insert
2989 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzoordrh", pcZzoordrh_update, ;
2990 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h.")
2991
2992 lcInsertSQL_zzoordrh = " INSERT INTO zzoordrh (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzoordrh_Update + " h WHERE h.sql_action = 'I'"
2993
2994 *--- Order Detail insert
2995 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzoordrd", pcZzoordrd_update, ;
2996 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"d.")
2997
2998 lcInsertSQL_zzoordrd = " INSERT INTO zzoordrd (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzoordrd_Update + " d WHERE d.sql_action = 'I'"
2999
3000 *--- Order sp insert
3001 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzoordsp", pcZzoordsp_update, ;
3002 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"sp.")
3003
3004 lcInsertSQL_zzoordsp = " INSERT INTO zzoordsp (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzoordsp_Update + " sp WHERE sp.sql_action = 'I'"
3005
3006 pcRefInsertSQL_zzoordrh = lcInsertSQL_zzoordrh
3007 pcRefInsertSQL_zzoordrd = lcInsertSQL_zzoordrd
3008 pcRefInsertSQL_zzoordSP = lcInsertSQL_zzoordSP
3009
3010 Select(lnOldSelect)
3011 Return llRetVal
3012
3013 Endproc
3014
3015*-----------------------------------------------------------------------------------------
3016
3017 PROCEDURE GetOrderUpdateSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, pcRefUpdateSQL_zzoordrh, pcRefUpdateSQL_zzoordrd, pcRefUpdateSQL_zzoordSP)
3018
3019 Local llRetVal, lnOldSelect
3020 lnOldSelect = Select()
3021 llRetVal = .T.
3022
3023 LOCAL lcUpdateSQL_zzoordrh,lcUpdateSQL_zzoordrd, lcUpdateSQL_zzoordSP
3024 STORE "" to lcUpdateSQL_zzoordrh,lcUpdateSQL_zzoordrd, lcUpdateSQL_zzoordSP
3025
3026 LOCAL lcUpdateAllFields
3027 lcUpdateAllFields = ""
3028 llRetVal = llRetVal and this.oCopyUtil.GetFldsValuesForUpdate(@lcUpdateAllFields, "zzoordrh", pcZzoordrh_Update,"","","","uh")
3029 lcUpdateSQL_zzoordrh = "UPDATE h SET " + lcUpdateAllFields + " FROM zzoordrh h INNER JOIN " + pcZzoordrh_Update + " uh ON uh.pkey = h.pkey " + ;
3030 " WHERE uh.SQL_action = 'U'"
3031
3032 lcUpdateAllFields = ""
3033 llRetVal = llRetVal and this.oCopyUtil.GetFldsValuesForUpdate(@lcUpdateAllFields, "zzoordrd", pcZzoordrd_Update,"","","","ud")
3034 lcUpdateSQL_zzoordrd = "UPDATE d SET " + lcUpdateAllFields + " FROM zzoordrd d INNER JOIN " + pcZzoordrd_Update + " ud ON ud.pkey = d.pkey " + ;
3035 " WHERE ud.SQL_action = 'U'"
3036
3037 pcRefUpdateSQL_zzoordrh = lcUpdateSQL_zzoordrh
3038 pcRefUpdateSQL_zzoordrd = lcUpdateSQL_zzoordrd
3039 pcRefUpdateSQL_zzoordSP = lcUpdateSQL_zzoordSP
3040 Select(lnOldSelect)
3041 Return llRetVal
3042
3043 Endproc
3044
3045*-----------------------------------------------------------------------------------------
3046
3047 PROCEDURE Get860TransInsertSQL(pcZzeipcth_Update, pcZzeipctd_update, pcRefInsertSQL_zzeipcth, pcRefInsertSQL_zzeipctd)
3048
3049 Local llRetVal, lnOldSelect
3050 lnOldSelect = Select()
3051 llRetVal = .T.
3052 LOCAL lcInsertSQL_zzeipcth, lcInsertSQL_zzeipctd, lcInsertSQL_zzoordSP
3053 STORE "" TO lcInsertSQL_zzeipcth, lcInsertSQL_zzeipctd, lcInsertSQL_zzoordSP
3054
3055 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
3056 lnOldSelect = Select()
3057 llRetVal = .T.
3058
3059 lcFlds = ""
3060 lcValues = ""
3061 lcExcludeFlds = ""
3062 lcCalFlds = ""
3063 lcCalFldsValues = ""
3064
3065 *--- 860 Transaction Header insert
3066 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzeipcth", pcZzeipcth_Update, ;
3067 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h.")
3068
3069 lcInsertSQL_zzeipcth = " INSERT INTO zzeipcth (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzeipcth_Update + " h "
3070
3071 *--- 860 Transaction Detail insert
3072 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzeipctd", pcZzeipctd_update, ;
3073 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"d.")
3074
3075 lcInsertSQL_zzeipctd = " INSERT INTO zzeipctd (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzeipctd_update + " d "
3076
3077 pcRefInsertSQL_zzeipcth = lcInsertSQL_zzeipcth
3078 pcRefInsertSQL_zzeipctd = lcInsertSQL_zzeipctd
3079
3080 Select(lnOldSelect)
3081 Return llRetVal
3082
3083 Endproc
3084
3085*-----------------------------------------------------------------------------------------
3086
3087 PROCEDURE GetOrderDeleteSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, pcRefDeleteSQL_zzoordrh, pcRefDeleteSQL_zzoordrd, pcRefDeleteSQL_zzoordSP)
3088
3089 Local llRetVal, lnOldSelect
3090 lnOldSelect = Select()
3091 llRetVal = .T.
3092
3093 LOCAL lcDeleteSQL_zzoordrh, lcDeleteSQL_zzoordrd, lcDeleteSQL_zzoordSP
3094 STORE "" TO lcDeleteSQL_zzoordrh, lcDeleteSQL_zzoordrd, lcDeleteSQL_zzoordSP
3095
3096 lcDeleteSQL_zzoordrh = "DELETE h FROM zzoordrh h INNER JOIN " + pcZzoordrh_Update + " dh ON h.pkey = dh.pkey where dh.SQL_action = 'D'"
3097 lcDeleteSQL_zzoordrd = "DELETE d FROM zzoordrd d INNER JOIN " + pcZzoordrd_Update + " dd ON d.pkey = dd.pkey where dd.SQL_action = 'D'"
3098 lcDeleteSQL_zzoordsp = "DELETE sp FROM zzoordsp sp INNER JOIN " + pcZzoordrh_Update + " dh " + ;
3099 " ON sp.ord_num = dh.ord_num " + ;
3100 " and sp.pick_num = dh.pick_num and sp.inv_num = dh.inv_num " + ;
3101 " where dh.SQL_action = 'D'"
3102
3103 pcRefDeleteSQL_zzoordrh = lcDeleteSQL_zzoordrh
3104 pcRefDeleteSQL_zzoordrd = lcDeleteSQL_zzoordrd
3105 pcRefDeleteSQL_zzoordSP = lcDeleteSQL_zzoordSP
3106
3107 Select(lnOldSelect)
3108 Return llRetVal
3109
3110 Endproc
3111
3112*-----------------------------------------------------------------------------------------
3113
3114 PROCEDURE GetTransDeleteSQL(pcZzeipcth, pcZzeipctd, pcRefDeleteSQL_zzeipcth, pcRefDeleteSQL_zzeipctd)
3115
3116 Local llRetVal, lnOldSelect
3117 lnOldSelect = Select()
3118 llRetVal = .T.
3119
3120 LOCAL lcDeleteSQL_zzeipcth, lcDeleteSQL_zzeipctd
3121 lcDeleteSQL_zzeipcth = "Delete h from zzeipcth h inner join " + pcZzeipcth + " th on h.pkey = th.pkey"
3122 lcDeleteSQL_zzeipctd = "Delete d From zzeipctd d inner join " + pcZzeipctd + " td on d.pkey = td.pkey"
3123 pcRefDeleteSQL_zzeipcth = lcDeleteSQL_zzeipcth
3124 pcRefDeleteSQL_zzeipctd = lcDeleteSQL_zzeipctd
3125
3126 Select(lnOldSelect)
3127 Return llRetVal
3128 Endproc
3129
3130*-----------------------------------------------------------------------------------------
3131
3132 PROCEDURE GetAllocUpdateSQL(pcZzoordrd_update,pcUpdateSQL_Alloc)
3133
3134 Local llRetVal, lnOldSelect
3135 lnOldSelect = Select()
3136 llRetVal = .T.
3137
3138*!* lcSQLString = "UPDATE zzaavalr " + ;
3139*!* " SET touch_ok = 'Y', " + ;
3140*!* " worst_nsr = " + SQLfnConcat("'?' + worst_nsr ") + ;
3141*!* " WHERE ord_num = " + STR(&lcDetailView..Ord_Num) + ;
3142*!* " AND line_seq = " + STR(&lcDetailView..Line_Seq) + ;
3143*!* " AND touch_ok <> 'Y'"
3144
3145 *--- d.line_status = 'C' is used because zzaavalr should change only when some order has decreased in quantity and
3146 *--- line_status value will be 'C' if there is any quantity decrease.
3147
3148 pcUpdateSQL_Alloc = " UPDATE a SET touch_ok = 'Y', worst_nsr = '?' + worst_nsr " + ;
3149 " FROM zzaavalr a INNER JOIN " + pcZzoordrd_update + " d " + ;
3150 " ON a.ord_num = d.ord_num AND a.line_seq = d.line_seq " + ;
3151 " WHERE a.touch_ok <> 'Y' and d.line_status = 'C' and d.Sql_action = 'U' "
3152
3153 Select(lnOldSelect)
3154 Return llRetVal
3155 Endproc
3156
3157*-----------------------------------------------------------------------------------------
3158
3159 PROCEDURE GetNumberOfRecProcessed(pcZzoordrh_Update, pcZzoordrd_Update)
3160
3161 Local llRetVal, lnOldSelect
3162 lnOldSelect = Select()
3163 llRetVal = .T.
3164 IF USED("tcOrderProcessed")
3165 USE IN tcOrderProcessed
3166 ENDIF
3167 llRetVal = llRetVal and v_sqlexec("select COUNT(*) nProcessed from " + pcZzoordrh_Update + " WHERE ord_status = 'O'","tcOrderProcessed")
3168 IF USED("tcOrderProcessed")
3169 *this.oMainProcess.nProcessed = tcOrderProcessed.nProcessed
3170 this.nProcessed = tcOrderProcessed.nProcessed
3171 USE IN tcOrderProcessed
3172 ENDIF
3173
3174*!* *--- TR 1032802 - When only PC there is no header record exists in pcZzoordrh_Update
3175*!* *--- - So need to count pcZzoordrd_Update records that no corresponding header record in pcZzoordrh_Update
3176*!* LOCAL lcSql
3177*!* lcSql = " select COUNT(*) nProcessed from ( " + ;
3178*!* " Select d.ord_num from " + pcZzoordrd_Update + " d " + ;
3179*!* " where not exists (select h.pkey from " + pcZzoordrh_Update + " h where h.ord_num = d.ord_num and h.ord_status = d.line_status) " + ;
3180*!* " and d.line_status = 'O' " + ;
3181*!* " group by d.ord_num ) a "
3182
3183*!* llRetVal = llRetVal and v_sqlexec(lcSql,"tcAdditionalOrder")
3184*!* IF llRetVal and USED("tcAdditionalOrder")
3185*!* this.nProcessed = this.nProcessed + tcAdditionalOrder.nProcessed
3186*!* USE IN tcAdditionalOrder
3187*!* ENDIF
3188*!* *=== TR 1032802
3189
3190 Select(lnOldSelect)
3191 Return llRetVal
3192 Endproc
3193
3194*-----------------------------------------------------------------------------------------
3195
3196 PROCEDURE GetTransNotesDeleteSQL(pcZzeipcth_nt, pcZzeipctd_nt,pcDeleteSQL_Zzeipcth_nt,pcDeleteSQL_Zzeipctd_nt)
3197
3198 Local llRetVal, lnOldSelect
3199 lnOldSelect = Select()
3200 llRetVal = .T.
3201
3202 LOCAL lcDeleteSQL_zzeipcth_nt, lcDeleteSQL_zzeipctd_nt
3203 lcDeleteSQL_zzeipcth_nt = "Delete h from sysnotes h inner join " + pcZzeipcth_nt + " th on h.pkey = th.pkey and h.table_name = 'ZZEIPCTH' "
3204 lcDeleteSQL_zzeipctd_nt = "Delete d From sysnotes d inner join " + pcZzeipctd_nt + " td on d.pkey = td.pkey and d.table_name = 'ZZEIPCTD'"
3205 pcDeleteSQL_Zzeipcth_nt = lcDeleteSQL_zzeipcth_nt
3206 pcDeleteSQL_Zzeipctd_nt = lcDeleteSQL_zzeipctd_nt
3207
3208 Select(lnOldSelect)
3209 Return llRetVal
3210 Endproc
3211
3212*-----------------------------------------------------------------------------------------
3213
3214 PROCEDURE GetOrderNotesInsertSQL(pcZzoordrh_nt_Update,pcZzoordrd_nt_Update,pcInsertSQL_Zzoordrh_nt,pcInsertSQL_Zzoordrd_nt)
3215
3216 Local llRetVal, lnOldSelect
3217 lnOldSelect = Select()
3218 llRetVal = .T.
3219 LOCAL lcInsertSQL_Zzoordrh_nt,lcInsertSQL_Zzoordrd_nt
3220 STORE " " TO lcInsertSQL_Zzoordrh_nt,lcInsertSQL_Zzoordrd_nt
3221 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
3222 lnOldSelect = Select()
3223 llRetVal = .T.
3224
3225 lcFlds = ""
3226 lcValues = ""
3227 lcExcludeFlds = ""
3228 lcCalFlds = ""
3229 lcCalFldsValues = ""
3230
3231 *--- Order header Notes insert
3232 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "sysnotes", pcZzoordrh_nt_Update, ;
3233 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h.")
3234
3235 lcInsertSQL_Zzoordrh_nt = " INSERT INTO sysnotes (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzoordrh_nt_Update + " h WHERE h.sql_action = 'I'"
3236
3237 *--- Order Detail Notes insert
3238 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "sysnotes", pcZzoordrd_nt_Update, ;
3239 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"d.")
3240
3241 lcInsertSQL_Zzoordrd_nt = " INSERT INTO sysnotes (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzoordrd_nt_Update + " d WHERE d.sql_action = 'I'"
3242
3243 pcInsertSQL_Zzoordrh_nt = lcInsertSQL_Zzoordrh_nt
3244 pcInsertSQL_Zzoordrd_nt = lcInsertSQL_Zzoordrd_nt
3245
3246 Select(lnOldSelect)
3247 Return llRetVal
3248 Endproc
3249
3250*-----------------------------------------------------------------------------------------
3251
3252 PROCEDURE GetOrderNotesUpdateSQL(pcZzoordrh_nt_Update,pcZzoordrd_nt_Update,pcUpdateSQL_Zzoordrh_nt,pcUpdateSQL_Zzoordrd_nt)
3253
3254 Local llRetVal, lnOldSelect
3255 lnOldSelect = Select()
3256 llRetVal = .T.
3257
3258 LOCAL lcUpdateSQL_Zzoordrh_nt,lcUpdateSQL_Zzoordrd_nt
3259 STORE "" to lcUpdateSQL_Zzoordrh_nt,lcUpdateSQL_Zzoordrd_nt
3260
3261 LOCAL lcUpdateAllFields
3262 lcUpdateAllFields = ""
3263 llRetVal = llRetVal and this.oCopyUtil.GetFldsValuesForUpdate(@lcUpdateAllFields, "sysnotes", pcZzoordrh_nt_Update,"'pkey'","","","uh")
3264 lcUpdateSQL_zzoordrh_nt = "UPDATE h SET " + lcUpdateAllFields + " FROM sysnotes h INNER JOIN " + pcZzoordrh_nt_Update + " uh ON uh.ORD_NUM = h.ORD_NUM " + ;
3265 " and uh.SQL_action = 'U' and h.table_name = 'ZZOORDRH' and h.line_seq = 0 "
3266
3267 lcUpdateAllFields = ""
3268 llRetVal = llRetVal and this.oCopyUtil.GetFldsValuesForUpdate(@lcUpdateAllFields, "sysnotes", pcZzoordrd_nt_Update,"'pkey','fkey'","","","ud")
3269 lcUpdateSQL_zzoordrd_nt = "UPDATE d SET " + lcUpdateAllFields + " FROM sysnotes d INNER JOIN " + pcZzoordrd_nt_Update + " ud ON ud.ord_num = d.ord_num " + ;
3270 " and ud.SQL_action = 'U' and d.table_name = 'ZZOORDRD' and d.line_seq = ud.line_seq "
3271
3272 pcUpdateSQL_Zzoordrh_nt = lcUpdateSQL_Zzoordrh_nt
3273 pcUpdateSQL_Zzoordrd_nt = lcUpdateSQL_Zzoordrd_nt
3274
3275 Select(lnOldSelect)
3276 Return llRetVal
3277 Endproc
3278
3279 *-----------------------------------------------------------------------------------------
3280
3281 Procedure UpdateAllTables(pcZzeipcth, pcZzeipctd, pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, pcAlloc;
3282 ,pcZzeipcth_nt,pcZzeipctd_nt, pcZzoordrh_nt_Update, pcZzoordrd_nt_Update,;
3283 pcZzeipcth_total, pcZzeipctd_total,pcZzoordrh_new,pczzeipohd_update, pcZzeipchs_Insert)
3284 &&--- TechRec 1040484 19-Jun-2009 vkrishnamurthy === Added pczzeipohd_update
3285
3286 Local llRetVal, lnOldSelect
3287 lnOldSelect = Select()
3288 llRetVal = .T.
3289
3290 *--- if pcZzeipcth has record that does not exists in 860 server transaction table
3291 *--- add lcSQL_ipcth_insert
3292 *--- add lcSQL_ipctd_insert
3293
3294 *--- order/cancel (Hdr/dtl) prepare insert statements
3295 Local lcInsertSQL_zzoordrh, lcInsertSQL_zzoordrd, lcInsertSQL_zzoordSP
3296 Local lcUpdateSQL_zzoordrh, lcUpdateSQL_zzoordrd, lcUpdateSQL_zzoordSP
3297 Local lcDeleteSQL_zzoordrh, lcDeleteSQL_zzoordrd, lcDeleteSQL_zzoordSP
3298 LOCAL lcDeleteSQL_zzeipcth, lcDeleteSQL_zzeipctd, lcUpdateSQL_Alloc
3299 LOCAL lcDeleteSQL_Zzeipcth_nt,lcDeleteSQL_Zzeipctd_nt
3300 LOCAL lcInsertSQL_Zzoordrh_nt,lcInsertSQL_Zzoordrd_nt
3301 LOCAL lcUpdateSQL_Zzoordrh_nt,lcUpdateSQL_Zzoordrd_nt
3302 LOCAL lcInsertSQL_zzeipcth,lcInsertSQL_zzeipctd,lcZzeipcth_new
3303
3304 *--- TechRec 1040484 19-Jun-2009 vkrishnamurthy ---
3305 LOCAL lcUpdateSQL_Zzeipohd
3306 lcUpdateSQL_Zzeipohd = ''
3307 *=== TechRec 1040484 19-Jun-2009 vkrishnamurthy ===
3308
3309 * --- TR 1047609 7/7/10 CM
3310 LOCAL lcInsertSQL_Zzeipchs
3311 lcInsertSQL_Zzeipchs = ""
3312 * === TR 1047609 7/7/10 CM
3313
3314 Store "" To lcInsertSQL_zzoordrh, lcInsertSQL_zzoordrd, lcInsertSQL_zzoordSP
3315 Store "" To lcUpdateSQL_zzoordrh, lcUpdateSQL_zzoordrd, lcUpdateSQL_zzoordSP
3316 Store "" To lcDeleteSQL_zzoordrh, lcDeleteSQL_zzoordrd, lcDeleteSQL_zzoordSP
3317 STORE "" TO lcDeleteSQL_zzeipcth, lcDeleteSQL_zzeipctd, lcUpdateSQL_Alloc
3318 STORE "" TO lcDeleteSQL_Zzeipcth_nt,lcDeleteSQL_Zzeipctd_nt
3319 STORE " " TO lcInsertSQL_Zzoordrh_nt,lcInsertSQL_Zzoordrd_nt
3320 STORE " " TO lcUpdateSQL_Zzoordrh_nt,lcUpdateSQL_Zzoordrd_nt
3321 STORE " " TO lcInsertSQL_zzeipcth,lcInsertSQL_zzeipctd,lcZzeipcth_new
3322
3323 *--- TechRec 1085945 28-May-2015 vkrishnamurthy ---
3324 llRetVal = llRetVal And This.CreateBulkNibblerTempTables()
3325
3326 lcUnique = SYS(2015)
3327 this.cOrdHdrOld = "#zzoordrh" + lcUnique
3328 this.cOrdDtlOld = "#zzoordrd" + lcUnique
3329
3330 this.cOpenCnclHdr = "#zzoordrh_opn" + lcUnique
3331 this.cUniqueHdr = "#zzoordrh_cncl" + lcUnique
3332
3333 llRetVal = llRetVal And this.GetOrdersEligibleForBulkAdjustment(pcZzeipcth,pcZzeipctd,this.cOrdHdrOld,this.cOrdDtlOld)
3334 this.RegisterTable(this.cOrdHdrOld )
3335 this.RegisterTable(this.cOrdDtlOld )
3336
3337 this.cCnclDtlOld = "#zzoordrd_cncl" + lcUnique
3338 lcSQL = " Select d.ord_num , d.pkey into "+ This.cCnclDtlOld + ;
3339 " from zzoordrd d join "+ this.cOrdDtlOld + " c on d.ord_num = c.ord_num and d.line_status = 'C' "
3340 llRetVal = llRetVal and v_sqlexec(lcSql)
3341 this.RegisterTable(this.cCnclDtlOld )
3342
3343 this.NibBatchNum = this.NibBatchNum + 1
3344 llRetVal = llRetVal And this.PopulateNibblerRecord('ZZO','BULK','A')
3345
3346 *=== TechRec 1085945 28-May-2015 vkrishnamurthy ===
3347
3348
3349 llRetVal = llRetVal And this.GetOrderInsertSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, @lcInsertSQL_zzoordrh, @lcInsertSQL_zzoordrd, @lcInsertSQL_zzoordSP)
3350 llRetVal = llRetVal And this.GetOrderUpdateSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, @lcUpdateSQL_zzoordrh, @lcUpdateSQL_zzoordrd, @lcUpdateSQL_zzoordSP)
3351 llRetVal = llRetVal And this.GetOrderDeleteSQL(pcZzoordrh_Update, pcZzoordrd_update, pcZzoordsp_update, @lcDeleteSQL_zzoordrh, @lcDeleteSQL_zzoordrd, @lcDeleteSQL_zzoordSP)
3352 llRetVal = llRetVal And this.GetTransDeleteSQL(pcZzeipcth, pcZzeipctd, @lcDeleteSQL_zzeipcth, @lcDeleteSQL_zzeipctd)
3353 llRetVal = llRetVal and this.GetTransNotesDeleteSQL(pcZzeipcth_nt, pcZzeipctd_nt,@lcDeleteSQL_Zzeipcth_nt,@lcDeleteSQL_Zzeipctd_nt)
3354 llRetVal = llRetVal and this.GetAllocUpdateSQL(pcZzoordrd_update,@lcUpdateSQL_Alloc)
3355 llRetVal = llRetVal and this.GetOrderNotesInsertSQL(pcZzoordrh_nt_Update,pcZzoordrd_nt_Update,@lcInsertSQL_Zzoordrh_nt,@lcInsertSQL_Zzoordrd_nt)
3356 llRetVal = llRetVal and this.GetOrderNotesUpdateSQL(pcZzoordrh_nt_Update,pcZzoordrd_nt_Update,@lcUpdateSQL_Zzoordrh_nt,@lcUpdateSQL_Zzoordrd_nt)
3357 llRetVal = llRetVal and this.GetNumberOfRecProcessed(pcZzoordrh_Update,pcZzoordrd_update)
3358
3359 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
3360 llRetVal = llRetVal and this.Get850HDUpdateSQL(pcZzeipohd_Update,@lcUpdateSQL_Zzeipohd)
3361 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
3362
3363 * --- TR 1047609 7/7/10 CM
3364 llRetVal = llRetVal And this.GetSLNHistInsertSQL(pcZzeipchs_Insert, @lcInsertSQL_Zzeipchs)
3365 * === TR 1047609 7/7/10 CM
3366
3367 *--- Adjust duplicate PO transaction for new store
3368 llRetVal = llRetVal and this.AdjustDuplicatePoForNewStore(pcZzeipcth_total, pcZzeipctd_total, pcZzoordrh_new, @lcZzeipcth_new, @lcInsertSQL_zzeipcth,@lcInsertSQL_zzeipctd)
3369
3370 *--- order/cancel (Hdr/dtl) prepare update statements
3371 *--- order/cancel (Hdr/dtl) prepare delete statements
3372 *---
3373
3374 *--- TR 1066871 13-May-2013 Goutam
3375 llRetVal = llRetVal And this.GetNoErrorRecordInCursor(pcZzeipcth)
3376 *=== TR 1066871 13-May-2013 Goutam
3377
3378 Local llBeganTransaction,lnTranErrCount,lcTranFailedMsg
3379 llBeganTransaction = This.BeginTransaction()
3380 lnTranErrCount = 0
3381 lcTranFailedMsg = ""
3382 If llBeganTransaction And llRetVal
3383
3384 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzoordrh)
3385 If lnTranErrCount = 0 And Not llRetVal
3386 lcTranFailedMsg = "Create Order header failed."
3387 lnTranErrCount = 1
3388 Endif
3389
3390 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzoordrd)
3391 If lnTranErrCount = 0 And Not llRetVal
3392 lcTranFailedMsg = "Create order detail failed."
3393 lnTranErrCount = 1
3394 Endif
3395
3396 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzoordSP)
3397 If lnTranErrCount = 0 And Not llRetVal
3398 lcTranFailedMsg = "Create order carton link records creation failed."
3399 lnTranErrCount = 1
3400 Endif
3401
3402 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_Zzoordrh_nt)
3403 If lnTranErrCount = 0 And Not llRetVal
3404 lcTranFailedMsg = "Create Order header notes failed."
3405 lnTranErrCount = 1
3406 Endif
3407
3408 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_Zzoordrd_nt)
3409 If lnTranErrCount = 0 And Not llRetVal
3410 lcTranFailedMsg = "Create order detail notes failed."
3411 lnTranErrCount = 1
3412 Endif
3413
3414 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_zzoordrh)
3415 If lnTranErrCount = 0 And Not llRetVal
3416 lcTranFailedMsg = "Update Order header failed."
3417 lnTranErrCount = 1
3418 Endif
3419
3420 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_zzoordrd)
3421 If lnTranErrCount = 0 And Not llRetVal
3422 lcTranFailedMsg = "Update order detail failed."
3423 lnTranErrCount = 1
3424 Endif
3425
3426 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_Zzoordrh_nt)
3427 If lnTranErrCount = 0 And Not llRetVal
3428 lcTranFailedMsg = "Update Order header notes failed."
3429 lnTranErrCount = 1
3430 Endif
3431
3432 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_Zzoordrd_nt)
3433 If lnTranErrCount = 0 And Not llRetVal
3434 lcTranFailedMsg = "Update order detail notes failed."
3435 lnTranErrCount = 1
3436 Endif
3437
3438 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_zzoordrd)
3439 If lnTranErrCount = 0 And Not llRetVal
3440 lcTranFailedMsg = "Delete order detail failed."
3441 lnTranErrCount = 1
3442 Endif
3443
3444 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_zzoordSP)
3445 If lnTranErrCount = 0 And Not llRetVal
3446 lcTranFailedMsg = "Delete order carton link records creation failed."
3447 lnTranErrCount = 1
3448 Endif
3449
3450 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_zzoordrh)
3451 If lnTranErrCount = 0 And Not llRetVal
3452 lcTranFailedMsg = "Delete Order header failed."
3453 lnTranErrCount = 1
3454 ENDIF
3455
3456 *--- TechRec 1085945 23-Jun-2015 vkrishnamurthy ---
3457 llRetVal = llRetVal And This.PopulateBulkNibblerRecord(pcZzeipcth,pcZzeipctd)
3458 If lnTranErrCount = 0 And Not llRetVal
3459 lcTranFailedMsg = "Insert Nibbler failed..."
3460 lnTranErrCount = 1
3461 ENDIF
3462 *=== TechRec 1085945 23-Jun-2015 vkrishnamurthy ===
3463
3464 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_Zzeipctd_nt)
3465 If lnTranErrCount = 0 And Not llRetVal
3466 lcTranFailedMsg = "Delete transaction detail notes failed."
3467 lnTranErrCount = 1
3468 Endif
3469
3470 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_zzeipctd)
3471 If lnTranErrCount = 0 And Not llRetVal
3472 lcTranFailedMsg = "Delete transaction detail failed."
3473 lnTranErrCount = 1
3474 Endif
3475
3476 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_Zzeipcth_nt)
3477 If lnTranErrCount = 0 And Not llRetVal
3478 lcTranFailedMsg = "Delete transaction notes failed."
3479 lnTranErrCount = 1
3480 Endif
3481
3482 llRetVal = llRetVal And v_SQLExec(lcDeleteSQL_zzeipcth)
3483 If lnTranErrCount = 0 And Not llRetVal
3484 lcTranFailedMsg = "Delete transaction header failed."
3485 lnTranErrCount = 1
3486 Endif
3487
3488 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_Alloc)
3489 If lnTranErrCount = 0 And Not llRetVal
3490 lcTranFailedMsg = "Update alloction failed."
3491 lnTranErrCount = 1
3492 ENDIF
3493
3494 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
3495 llRetVal = llRetVal And v_SQLExec(lcUpdateSQL_Zzeipohd)
3496 If lnTranErrCount = 0 And Not llRetVal
3497 lcTranFailedMsg = "Update Zzeipohd failed."
3498 lnTranErrCount = 1
3499 ENDIF
3500 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
3501
3502 llRetVal = llRetVal and v_sqlexec(lcInsertSQL_zzeipcth)
3503 If lnTranErrCount = 0 And Not llRetVal
3504 lcTranFailedMsg = "Insert new store 860 transaction header adjustment failed."
3505 lnTranErrCount = 1
3506 Endif
3507
3508 llRetVal = llRetVal and v_sqlexec(lcInsertSQL_zzeipctd)
3509 If lnTranErrCount = 0 And Not llRetVal
3510 lcTranFailedMsg = "Insert new store 860 transaction detail adjustment failed."
3511 lnTranErrCount = 1
3512 Endif
3513
3514 * --- TR 1047609 7/7/10 CM
3515 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_Zzeipchs)
3516 If lnTranErrCount = 0 And Not llRetVal
3517 lcTranFailedMsg = "Insert SLN History failed."
3518 lnTranErrCount = 1
3519 Endif
3520 * === TR 1047609 7/7/10 CM
3521
3522 If llRetVal
3523 This.EndTransaction()
3524 This.LogEntry("Transaction successful.")
3525 *--- increase toProcess vaulue for new transaction records.
3526 this.IncreaseToProcessCount(lcZzeipcth_new)
3527 Else
3528 This.RollbackTransaction()
3529 This.LogEntry("---------------------------------------------")
3530 This.LogEntry(lcTranFailedMsg)
3531 This.LogEntry("Transaction rolled back.")
3532 This.LogEntry("=============================================")
3533 Endif
3534 Else
3535 If llRetVal && and not llBeganTransaction
3536 *--- LogEntry : unable to open Transaction
3537 This.LogEntry("Fatal error : Fail to open transaction.")
3538 Endif
3539 Endif
3540
3541 Select(lnOldSelect)
3542 Return llRetVal
3543
3544 Endproc
3545
3546*-----------------------------------------------------------------------------------------
3547
3548 PROCEDURE IncreaseToProcessCount(pczzeipcth_new)
3549
3550 Local llRetVal, lnOldSelect, lcUnique
3551 lnOldSelect = Select()
3552 llRetVal = .T.
3553
3554 llRetVal = llRetVal and v_sqlexec("select COUNT(*) as NewRecCount from " + pczzeipcth_new, "NewRecCount")
3555
3556 IF llRetVal AND USED("NewRecCount")
3557 this.oMainProcess.nToProcess = this.oMainProcess.nToProcess + NewRecCount.NewRecCount
3558 USE IN NewRecCount
3559 ENDIF
3560
3561 Select(lnOldSelect)
3562 Return llRetVal
3563
3564 Endproc
3565
3566*-----------------------------------------------------------------------------------------
3567
3568 PROCEDURE AdjustDuplicatePoForNewStore(pcZzeipcth_total, pcZzeipctd_total, pcZzoordrh_new, pcRefZzeipcth_NewStore, pcInsertSQL_zzeipoth, pcInsertSQL_zzeipotd)
3569
3570 Local llRetVal, lnOldSelect, lcUnique
3571 lnOldSelect = Select()
3572 llRetVal = .T.
3573 lcUnique = SYS(2015)
3574
3575 LOCAL lcZzeipcth_AllStore, lcZzeipctd_AllStore, lcZzeipcth_NewStore, lcZzeipctd_NewStore
3576 STORE " " TO lcZzeipcth_AllStore, lcZzeipctd_AllStore, lcZzeipcth_NewStore, lcZzeipctd_NewStore
3577 lcZzeipcth_AllStore = "#Zzeipcth_AllStore" + lcUnique
3578 lcZzeipctd_AllStore = "#Zzeipctd_AllStore" + lcUnique
3579 lcZzeipcth_NewStore = "#Zzeipcth_NewStore" + lcUnique
3580 lcZzeipctd_NewStore = "#Zzeipctd_NewStore" + lcUnique
3581
3582 *--- header change
3583 *--- Get records with ForAllStore = 'Y'
3584 llRetVal = llRetVal and this.GetTransRecordForAllStore(pcZzeipcth_total, pcZzeipctd_total, lcZzeipcth_AllStore, lcZzeipctd_AllStore)
3585 llRetVal = llRetVal and this.AddNewStoreForPoChange(lcZzeipcth_AllStore, lcZzeipctd_AllStore,pcZzoordrh_new, lcZzeipcth_NewStore, ;
3586 lcZzeipctd_NewStore)
3587 llRetVal = llRetVal and this.Get860TransInsertSQL(lcZzeipcth_NewStore, lcZzeipctd_NewStore, @pcInsertSQL_zzeipoth, ;
3588 @pcInsertSQL_zzeipotd)
3589
3590 *--- add to the local 860 temp tables
3591 llRetVal = llRetVal and this.AddNewStoreRecordsToTempTransTable(pcZzeipcth_total, pcZzeipctd_total, lcZzeipcth_NewStore, lcZzeipctd_NewStore)
3592
3593 pcRefZzeipcth_NewStore = lcZzeipcth_NewStore
3594 IF llRetVal
3595 v_sqlexec("drop table " + lcZzeipcth_AllStore)
3596 v_sqlexec("drop table " + lcZzeipctd_AllStore)
3597 ENDIF
3598
3599 Select(lnOldSelect)
3600 Return llRetVal
3601
3602 Endproc
3603
3604*-----------------------------------------------------------------------------------------
3605
3606 PROCEDURE AddNewStoreRecordsToTempTransTable(pcZzeipcth_total, pcZzeipctd_total, pcZzeipcth_NewStore, pcZzeipctd_NewStore)
3607
3608 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3609 lnOldSelect = Select()
3610 llRetVal = .T.
3611
3612 lcSQL = "INSERT INTO " + pcZzeipcth_total + " SELECT * FROM " + pcZzeipcth_NewStore
3613 llRetVal = llRetVal and v_sqlexec(lcSQL)
3614
3615 lcSQL = "INSERT INTO " + pcZzeipctd_total + " SELECT * FROM " + pcZzeipctd_NewStore
3616 llRetVal = llRetVal and v_sqlexec(lcSQL)
3617
3618 Select(lnOldSelect)
3619 Return llRetVal
3620
3621 Endproc
3622
3623*-----------------------------------------------------------------------------------------
3624
3625 PROCEDURE GetTransRecordForAllStore(pcZzeipcth_total, pcZzeipctd_total, lcZzeipcth_AllStore, lcZzeipctd_AllStore)
3626
3627 Local llRetVal, lnOldSelect, lcUnique
3628 lnOldSelect = Select()
3629 llRetVal = .T.
3630 LOCAL lcSQL
3631
3632 lcSQL = "SELECT * INTO " + lcZzeipcth_AllStore + " FROM " + pcZzeipcth_total + " h WHERE h.ForAllStore = 'Y'"
3633 llRetVal = llRetVal and v_sqlexec(lcSQL)
3634
3635 lcSQL = "SELECT d.* INTO " + lcZzeipctd_AllStore + " FROM " + pcZzeipcth_total + " h INNER JOIN " + pcZzeipctd_total ;
3636 + " d ON d.fkey = h.pkey WHERE h.ForAllStore = 'Y'"
3637 llRetVal = llRetVal and v_sqlexec(lcSQL)
3638
3639 Select(lnOldSelect)
3640 Return llRetVal
3641
3642 Endproc
3643
3644*-----------------------------------------------------------------------------------------
3645
3646 PROCEDURE AddNewStoreForPoChange(pcZzeipcth_AllStore, pcZzeipctd_AllStore,pcZzoordrh_new, pcZzeipcth_NewStore, pcZzeipctd_NewStore)
3647
3648 Local llRetVal, lnOldSelect, lcUnique, lcSQL, lcZzeipcth_NewStore
3649 lnOldSelect = Select()
3650 llRetVal = .T.
3651 lcUnique = SYS(2015)
3652 lcZzeipcth_NewStore = "#Zzeipcth_NewStore" + lcUnique
3653 lcZzeipctd_NewStore = "#Zzeipctd_NewStore" + lcUnique
3654
3655 *--- create new header
3656 lcSQL = " SELECT h.* FROM " + pcZzeipcth_AllStore + " h " + ;
3657 " WHERE exists ( select customer,po_num, division FROM " + ;
3658 pcZzeipcth_AllStore + " ih GROUP BY customer,po_num, division HAVING MIN(pkey) = h.pkey) "
3659
3660 lcSQL = " SELECT th.*, h.store as newStore, h.edi_store as newEdi_store, h.ord_num as new_ord_num INTO " + pcZzeipcth_NewStore + ;
3661 " FROM (" + lcSQL + ") th inner join " + pcZzoordrh_new + " h on h.customer = th.customer AND h.po_num = th.po_num " + ;
3662 " and h.division = th.division "
3663 llRetVal = llRetVal and v_sqlexec(lcSQL)
3664
3665 *--- stamp new store, ord_num
3666 lcSQL = "UPDATE th SET store = newStore, ord_num = new_ord_num, edi_store = newEdi_store FROM " + pcZzeipcth_NewStore + " th "
3667 llRetVal = llRetVal and v_sqlexec(lcSQL)
3668
3669 lcSQL = "ALTER TABLE " + pcZzeipcth_NewStore + " drop column newStore"
3670 llRetVal = llRetVal and v_sqlexec(lcSQL)
3671
3672 lcSQL = "ALTER TABLE " + pcZzeipcth_NewStore + " drop column new_ord_num"
3673 llRetVal = llRetVal and v_sqlexec(lcSQL)
3674
3675 lcSQL = "ALTER TABLE " + pcZzeipcth_NewStore + " drop column newEdi_store"
3676 llRetVal = llRetVal and v_sqlexec(lcSQL)
3677
3678 *--- create new detail
3679 lcSQL = "select d.*, h.ord_num as new_ord_num into " + pcZzeipctd_NewStore + " from " + pcZzeipctd_AllStore + " d inner join " + ;
3680 pcZzeipcth_NewStore + " h on h.pkey = d.fkey "
3681 llRetVal = llRetVal and v_sqlexec(lcSQL)
3682
3683 *--- set new ord_num
3684 lcSQL = "UPDATE td SET ord_num = new_ord_num FROM " + pcZzeipctd_NewStore + " td "
3685 llRetVal = llRetVal and v_sqlexec(lcSQL)
3686
3687 *--- drop temp column new_ord_num
3688 lcSQL = "ALTER TABLE " + pcZzeipctd_NewStore + " drop column new_ord_num"
3689 llRetVal = llRetVal and v_sqlexec(lcSQL)
3690
3691 *--- set header pkey - detail fkey
3692 llRetVal = llRetVal and this.Set860TransHdrPkey(pcZzeipcth_NewStore,pcZzeipctd_NewStore)
3693
3694 *--- set detail pkey
3695 llRetVal = llRetVal and this.Set860TransDtlPkey(pcZzeipctd_NewStore)
3696
3697 Select(lnOldSelect)
3698 Return llRetVal
3699
3700 Endproc
3701
3702*-----------------------------------------------------------------------------------------
3703
3704 Procedure Update860TransctionForError(pcZzeipcth, pcZzeipctd)
3705
3706 Local llRetVal, lnOldSelect, lcUnique,lcSQL,lcSQL_dtl
3707
3708 *--- TR 1072834 19-Aug-2013 Goutam
3709 LOCAL lcWarnSqlHeader, lcWarnSqlDetail
3710 *=== TR 1072834 19-Aug-2013 Goutam
3711
3712 lnOldSelect = Select()
3713 llRetVal = .T.
3714
3715 *--- TR 1072834 19-Aug-2013 Goutam
3716 lcSQL = "Update h set h.warn_flg_h = 'Y', h.warn_msg_h = 'Has warnings in detail.' from " + pcZzeipcth + " h join " + pcZzeipctd + " d " + ;
3717 " on d.fkey = h.pkey where d.warn_flg_d = 'Y' and h.warn_flg_h <> 'Y'"
3718
3719 llRetVal = llRetVal And v_SQLExec(lcSQL)
3720 *=== TR 1072834 19-Aug-2013 Goutam
3721
3722 *--- TechRec 1041233 06-Aug-2009 vkrishnamurthy ---
3723*!* lcSQL = "update h set errs_flg_h = th.errs_flg_h, errs_msg_h = th.errs_msg_h from " + pcZzeipcth + ;
3724*!* " th inner join zzeipcth h on th.pkey = h.pkey where th.errs_flg_h = 'Y'"
3725
3726 lcSQL = "update h set errs_flg_h = th.errs_flg_h, errs_msg_h = th.errs_msg_h,terms = th.terms from " + pcZzeipcth + ;
3727 " th inner join zzeipcth h on th.pkey = h.pkey where th.errs_flg_h = 'Y'"
3728 *=== TechRec 1041233 06-Aug-2009 vkrishnamurthy ===
3729
3730 lcSQL_dtl = "Update d set errs_flg_d = td.errs_flg_d, errs_msg_d = td.errs_msg_d from " + pcZzeipctd + ;
3731 " td inner join zzeipctd d on td.pkey = d.pkey where td.errs_flg_d = 'Y'"
3732
3733 *--- TR 1072834 19-Aug-2013 Goutam
3734 lcWarnSqlHeader = "Update h set warn_flg_h = th.warn_flg_h, warn_msg_h = th.warn_msg_h from " + pcZzeipcth + ;
3735 " th inner join zzeipcth h on th.pkey = h.pkey where th.warn_flg_h = 'Y'"
3736
3737 lcWarnSqlDetail = "Update d set warn_flg_d = td.warn_flg_d, warn_msg_d = td.warn_msg_d from " + pcZzeipctd + ;
3738 " td inner join zzeipctd d on td.pkey = d.pkey where td.warn_flg_d = 'Y'"
3739 *=== TR 1072834 19-Aug-2013 Goutam
3740
3741 Local llBeganTransaction,lcTranMsg
3742 llBeganTransaction = This.BeginTransaction()
3743 lcTranMsg = ""
3744 If llBeganTransaction
3745 llRetVal = llRetVal And v_SQLExec(lcSQL)
3746 lcTranMsg = IIF(not llRetVal and EMPTY(lcTranMsg),"Fail to Update 860 transaction header with error.",lcTranMsg)
3747 llRetVal = llRetVal And v_SQLExec(lcSQL_dtl)
3748 lcTranMsg = IIF(not llRetVal and EMPTY(lcTranMsg),"Fail to Update 860 transaction detail with error.",lcTranMsg)
3749
3750 *--- TR 1072834 19-Aug-2013 Goutam
3751 llRetVal = llRetVal And v_SQLExec(lcWarnSqlHeader)
3752 lcTranMsg = IIF(Not llRetVal and EMPTY(lcTranMsg),"Fail to Update 860 transaction header with error.",lcTranMsg)
3753 llRetVal = llRetVal And v_SQLExec(lcWarnSqlDetail)
3754 lcTranMsg = IIF(Not llRetVal and EMPTY(lcTranMsg),"Fail to Update 860 transaction detail with error.",lcTranMsg)
3755 *=== TR 1072834 19-Aug-2013 Goutam
3756
3757 IF llRetVal
3758 This.EndTransaction()
3759 This.LogEntry("Update 860 Transaction for Error " + IIF(llRetVal,"successfull.","failed."))
3760 Else
3761 This.RollbackTransaction()
3762 This.LogEntry("---------------------------------------------")
3763 This.LogEntry(lcTranMsg)
3764 This.LogEntry("Transaction rolled back.")
3765 This.LogEntry("=============================================")
3766 ENDIF
3767 ENDIF
3768
3769 Select(lnOldSelect)
3770 Return llRetVal
3771
3772 Endproc
3773
3774*-----------------------------------------------------------------------------------------
3775
3776 Procedure DeleteAllRecordsWithErrorFromTempTransTables(pcZzeipcth, pcZzeipctd)
3777
3778 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3779
3780 *--- TR 1072834 20-Aug-2013 Goutam
3781 LOCAL lcWarnCondition
3782 *=== TR 1072834 20-Aug-2013 Goutam
3783
3784 lnOldSelect = Select()
3785 llRetVal = .T.
3786
3787 *--- TR 1072834 20-Aug-2013 Goutam
3788 lcWarnCondition = " or (h.warn_flg_h = 'Y' and h.ignore_warn = 'N')"
3789 *=== TR 1072834 20-Aug-2013 Goutam
3790
3791 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition and ( and ) before and after last condition
3792 lcSQL = "DELETE d FROM " + pcZzeipctd + " d INNER JOIN " + pcZzeipcth + " h on h.pkey = d.fkey where (h.errs_flg_h = 'Y' " + lcWarnCondition + ")"
3793 llRetVal = llRetVal And v_SQLExec(lcSQL)
3794
3795 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition and ( and ) before and after last condition
3796 lcSQL = "DELETE H FROM " + pcZzeipcth + " h where (h.errs_flg_h = 'Y' " + lcWarnCondition + ")"
3797 llRetVal = llRetVal And v_SQLExec(lcSQL)
3798
3799 Select(lnOldSelect)
3800 Return llRetVal
3801
3802 Endproc
3803
3804*-----------------------------------------------------------------------------------------
3805
3806 Procedure Prepare860TransForQuantityChange(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig)
3807
3808 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3809 lnOldSelect = Select()
3810 llRetVal = .T.
3811
3812 *--- change the sign of quantity of 860 transaction detail lines for QD, QI
3813 lcSQL = "UPDATE d SET qty_change = qty_change * (-1) FROM " + pcZzeipctd + " d where qualifier in ('DI', 'QD') "
3814 llRetVal = llRetVal And v_SQLExec(lcSQL)
3815
3816 *--- TR 1034532 NH
3817 LOCAL lcAddJoin
3818 IF EMPTY(this.c860SODetailAddMatchCriteria)
3819 lcAddJoin = ""
3820 ELSE
3821 lcAddJoin = " and d.LINE_ID = dv." + THIS.c860SODetailAddMatchCriteria
3822 ENDIF
3823 *=== TR 1034532 NH
3824
3825 lcSQL = "Update d SET qty_change = d.qty_change - dv.size_qty FROM " + pcZzeipctd + " d " + ;
3826 " inner join " + pcZzoordrdv_orig + " dv " + ;
3827 " on d.ord_num = dv.ord_num and d.division = dv.division " + ;
3828 " and d.style = dv.style and d.color_code = dv.color_code and d.lbl_code = dv.lbl_code " + ;
3829 " and d.dimension = dv.dimension and d.sizebucket = dv.sizebucket " + ;
3830 " where qualifier = 'RZ'" + ;
3831 " and dv.line_status = 'O'" + lcAddJoin &&=== TR 1034532 NH
3832
3833 llRetVal = llRetVal And v_SQLExec(lcSQL)
3834
3835 Select(lnOldSelect)
3836 Return llRetVal
3837
3838 Endproc
3839
3840*-----------------------------------------------------------------------------------------
3841
3842 Procedure CreateCancelOrderToInsert(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
3843
3844 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3845 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
3846 lnOldSelect = Select()
3847 llRetVal = .T.
3848
3849 lcFlds = ""
3850 lcValues = ""
3851 lcExcludeFlds = "'SQL_action', 'ord_status','POC_PURP'"
3852 lcCalFlds = "SQL_action, ord_status, POC_PURP"
3853 lcCalFldsValues = "'I','C',th.poc_purp"
3854 lcFilter = "WHERE (1 = 1)"
3855 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, pcZzoordrh_orig, ;
3856 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h.")
3857
3858 TEXT TO lcSql NOSHOW
3859 SELECT h.* FROM #Zzoordrh_orig h INNER JOIN #zzeipcth th ON H.ORD_NUM = th.ord_num
3860 and h.ord_status = 'O' AND th.poc_purp = '01'
3861 WHERE NOT EXISTS (SELECT * FROM #Zzoordrh_orig ih where ih.ord_num = h.ord_num and ih.ord_status = 'C')
3862 AND NOT EXISTS (SELECT * FROM #zzoordrh_update ih where ih.ord_num = h.ord_num and ih.ord_status = 'C')
3863 ENDTEXT
3864
3865 lcSQL = Strtran(lcSQL,"#zzeipcth",pcZzeipcth)
3866 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
3867 lcSQL = Strtran(lcSQL,"#zzoordrh_update",pcZzoordrh_update)
3868 lcSQL = Strtran(lcSQL,"h.*",lcValues)
3869 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
3870 llRetVal = llRetVal And v_SQLExec(lcSQL)
3871
3872 Select(lnOldSelect)
3873 Return llRetVal
3874
3875 Endproc
3876
3877*-----------------------------------------------------------------------------------------
3878
3879 Procedure CreateCancelOrderToUpdate(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
3880
3881 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3882 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
3883 lnOldSelect = Select()
3884 llRetVal = .T.
3885
3886 lcFlds = ""
3887 lcValues = ""
3888 lcExcludeFlds = "'SQL_action', 'ord_status', 'ord_qty','POC_PURP'"
3889 lcCalFlds = "SQL_action, ord_status,ord_qty,POC_PURP"
3890 lcCalFldsValues = "'U','C', hc.ord_qty + h.ord_qty,th.POC_PURP "
3891 lcFilter = "WHERE (1 = 1)"
3892 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, pcZzoordrh_orig, ;
3893 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"hc")
3894
3895 TEXT TO lcSql NOSHOW
3896 SELECT hc.* FROM #Zzoordrh_orig h INNER JOIN #Zzeipcth th ON H.ORD_NUM = th.ord_num
3897 and h.ord_status = 'O' inner join #Zzoordrh_orig hc on hc.ord_num = th.ord_num and hc.ord_status = 'C'
3898 WHERE th.poc_purp = '01' and NOT EXISTS (SELECT * FROM #zzoordrh_update ih where ih.ord_num = h.ord_num and ih.ord_status = 'C')
3899 ENDTEXT
3900
3901 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
3902 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
3903 lcSQL = Strtran(lcSQL,"#zzoordrh_update",pcZzoordrh_update)
3904 lcSQL = Strtran(lcSQL,"hc.*",lcValues)
3905 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
3906 llRetVal = llRetVal And v_SQLExec(lcSQL)
3907
3908 Select(lnOldSelect)
3909 Return llRetVal
3910
3911 Endproc
3912
3913*-----------------------------------------------------------------------------------------
3914
3915 *Procedure CreateCancelDtlOrderToInsert(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrd_update, pcZzoordrdv_update)
3916 Procedure CreateCancelDtlOrderToInsert(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update)
3917
3918 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3919 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
3920 lnOldSelect = Select()
3921 llRetVal = .T.
3922
3923 *--- Create cancel details
3924 lcFlds = ""
3925 lcValues = ""
3926 lcExcludeFlds = "'SQL_action', 'line_status','POC_PURP','cncl_rsn','cncl_type'"
3927 lcCalFlds = "SQL_action, line_status, POC_PURP,cncl_rsn,cncl_type"
3928 lcCalFldsValues = "'I','C',th.POC_PURP,r.cncl_rsn,r.cncl_type"
3929 lcFilter = "WHERE (1 = 1)"
3930 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update, pcZzoordrd_orig , ;
3931 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"d")
3932
3933 *--- always create new cancel line
3934 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = h.customer and r.division = h.division and added r.pkey = th.cr_pkey
3935 TEXT TO lcSql NOSHOW
3936 SELECT d.* FROM #Zzoordrh_orig h
3937 INNER JOIN #Zzeipcth th ON H.ORD_NUM = th.ord_num and h.ord_status = 'O' AND th.poc_purp = '01'
3938 inner join #Zzoordrd_orig d on h.pkey = d.fkey
3939 inner join zzeipccr r on /*r.customer = h.customer and r.division = h.division*/ r.pkey = th.cr_pkey
3940 ENDTEXT
3941
3942 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
3943 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
3944 lcSQL = STRTRAN(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
3945 lcSQL = Strtran(lcSQL,"#zzoordrh_update",pcZzoordrh_update)
3946
3947 *lcValues = Strtran(lcValues,"h.","dv.")
3948 lcSQL = Strtran(lcSQL,"d.*",lcValues)
3949 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
3950 llRetVal = llRetVal And v_SQLExec(lcSQL)
3951
3952 *--- add existing cancel order for qualifier '01'
3953 lcValues = STRTRAN(lcValues,"'I'","'U'")
3954 lcValues = STRTRAN(lcValues,",r.cncl_rsn,r.cncl_type",",d.cncl_rsn,d.cncl_type")
3955
3956 TEXT TO lcSql noshow
3957 SELECT d.* FROM #Zzoordrh_orig h
3958 INNER JOIN #Zzeipcth th ON H.ORD_NUM = th.ord_num and h.ord_status = 'C' AND th.poc_purp = '01'
3959 inner join #Zzoordrd_orig d on h.pkey = d.fkey
3960 ENDTEXT
3961
3962 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
3963 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
3964 lcSQL = STRTRAN(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
3965
3966 lcSQL = Strtran(lcSQL,"d.*",lcValues)
3967 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
3968 llRetVal = llRetVal And v_SQLExec(lcSQL)
3969
3970 Select(lnOldSelect)
3971 Return llRetVal
3972
3973 Endproc
3974
3975*-----------------------------------------------------------------------------------------
3976
3977 Procedure CreateCancelDtlOrderToUpdate(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update )
3978
3979 Local llRetVal, lnOldSelect, lcUnique, lcSQL
3980 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
3981 lnOldSelect = Select()
3982 llRetVal = .T.
3983
3984 *--- add cancel details for update
3985 *--- cancel quantity is the quantity needs to be added to original order.
3986 lcFlds = ""
3987 lcValues = ""
3988 lcExcludeFlds = "'SQL_action', 'line_status','POC_PURP', 'size01_qty', 'size02_qty', 'size03_qty', 'size04_qty', 'size05_qty','size06_qty','size07_qty'," + ;
3989 "'size08_qty','size09_qty', 'size10_qty','size11_qty', 'size12_qty', 'size13_qty', 'size14_qty', 'size15_qty','size16_qty','size17_qty'," + ;
3990 "'size18_qty','size19_qty', 'size20_qty','size21_qty', 'size22_qty', 'size23_qty', 'size24_qty','total_qty'"
3991
3992 lcCalFlds = "SQL_action, line_status, POC_PURP, size01_qty, size02_qty, size03_qty, size04_qty, size05_qty,size06_qty,size07_qty," + ;
3993 "size08_qty,size09_qty, size10_qty,size11_qty, size12_qty, size13_qty, size14_qty, size15_qty,size16_qty,size17_qty," + ;
3994 "size18_qty,size19_qty, size20_qty,size21_qty, size22_qty, size23_qty, size24_qty, total_qty"
3995
3996 lcCalFldsValues = "'U','C', th.POC_PURP, dc.size01_qty + d.size01_qty, dc.size02_qty + d.size02_qty, dc.size03_qty + d.size03_qty, dc.size04_qty + d.size04_qty, " + ;
3997 " dc.size05_qty + d.size05_qty, dc.size06_qty + d.size06_qty, dc.size07_qty + d.size07_qty," + ;
3998 " dc.size08_qty + d.size08_qty, dc.size09_qty + d.size09_qty, dc.size10_qty + d.size10_qty, dc.size11_qty + d.size11_qty, " + ;
3999 " dc.size12_qty + d.size12_qty, dc.size13_qty + d.size13_qty, dc.size14_qty + d.size14_qty, dc.size15_qty + d.size15_qty," + ;
4000 " dc.size16_qty + d.size16_qty, dc.size17_qty + d.size17_qty, dc.size18_qty + d.size18_qty, dc.size19_qty + d.size19_qty, " + ;
4001 " dc.size20_qty + d.size20_qty, dc.size21_qty + d.size21_qty, dc.size22_qty + d.size22_qty, dc.size23_qty + d.size23_qty, " + ;
4002 " dc.size24_qty + d.size24_qty, dc.total_qty + d.total_qty "
4003
4004 lcFilter = "WHERE (1 = 1)"
4005 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update, pcZzoordrd_orig, ;
4006 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"dc")
4007 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = h.customer and r.division = h.division and added r.pkey = th.cr_pkey
4008 TEXT TO lcSql NOSHOW
4009 SELECT dc.* FROM #Zzoordrh_orig h INNER JOIN #Zzeipcth th ON H.ORD_NUM = th.ord_num
4010 and h.ord_status = 'O' AND th.poc_purp = '01'
4011 inner join #Zzoordrd_orig d on h.ord_num = d.ord_num and d.line_status = 'O'
4012 inner join #Zzoordrd_orig dc on h.ord_num = dc.ord_num and dc.line_status = 'C'
4013 and dc.style = d.style and dc.color_code = d.color_code and dc.lbl_code = d.lbl_code
4014 and dc.dimension = d.dimension
4015 inner join zzeipccr r ON /*r.customer = h.customer and r.division = h.division */ r.pkey = th.cr_pkey
4016 and r.cncl_rsn = dc.cncl_rsn and r.cncl_type = dc.cncl_type
4017 ENDTEXT
4018
4019 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
4020 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4021 lcSQL = Strtran(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
4022
4023 lcSQL = Strtran(lcSQL,"dc.*",lcValues)
4024 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
4025 llRetVal = llRetVal And v_SQLExec(lcSQL)
4026
4027 Select(lnOldSelect)
4028 Return llRetVal
4029
4030 Endproc
4031
4032*-----------------------------------------------------------------------------------------
4033
4034 *Procedure PrepareFor_PoCancel(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrd_update, pcZzoordrdv_update, pcZzoordsp_update)
4035 Procedure PrepareFor_PoCancel(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update, pcZzoordsp_update)
4036 Local llRetVal, lnOldSelect, lcUnique, lcSQL,lnThermoCnt
4037
4038 lnOldSelect = Select()
4039 llRetVal = .T.
4040 lnThermoCnt = 0
4041 this.InitThermoWithCaption(lnThermoCnt,8,"Prepare for PO cancel.")
4042
4043 *---- create new cancel orders
4044 llRetVal = llRetVal And This.CreateCancelOrderToInsert(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
4045 this.LogEntry("Prepare new cancel orders " + IIF(llRetVal,"completed.","failed."))
4046 this.AdvanceThermoPlus(@lnThermoCnt)
4047
4048 llRetVal = llRetVal And This.CreateCancelOrderToUpdate(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
4049 this.LogEntry("Prepare existing cancel order for change " + IIF(llRetVal,"completed.","failed."))
4050 this.AdvanceThermoPlus(@lnThermoCnt)
4051
4052 llRetVal = llRetVal And This.CreateCancelDtlOrderToInsert(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update)
4053 this.LogEntry("Prepare new cancel order detail " + IIF(llRetVal,"completed.","failed."))
4054 this.AdvanceThermoPlus(@lnThermoCnt)
4055
4056 *--- always create new cancel line for following will not be executed.
4057*!* llRetVal = llRetVal And This.CreateCancelDtlOrderToUpdate(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update)
4058*!* this.LogEntry("Prepare exiting cancel order detail for change " + IIF(llRetVal,"completed.","failed."))
4059*!* this.AdvanceThermoPlus(@lnThermoCnt)
4060
4061 *---- create delete open orders
4062 llRetVal = llRetVal And This.CreateOpenOrederToDelete(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
4063 this.LogEntry("Prepare open order to delete " + IIF(llRetVal,"completed.","failed."))
4064 this.AdvanceThermoPlus(@lnThermoCnt)
4065
4066 llRetVal = llRetVal And This.CreateOpenOrederDtlToDelete(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update)
4067 this.LogEntry("Prepare open order detail to delete " + IIF(llRetVal,"completed.","failed."))
4068 this.AdvanceThermoPlus(@lnThermoCnt)
4069
4070 llRetVal = llRetVal And This.CreateOpenOrderSpToDelete(pcZzoordrh_update,pcZzoordsp_update)
4071 this.LogEntry("Prepare open order carton link record to delete " + IIF(llRetVal,"completed.","failed."))
4072 this.AdvanceThermoPlus(@lnThermoCnt)
4073
4074 Select(lnOldSelect)
4075 Return llRetVal
4076
4077 Endproc
4078
4079*-----------------------------------------------------------------------------------------
4080
4081 Procedure CreateOpenOrderSpToDelete(pcZzoordrh_update,pcZzoordsp_update)
4082
4083 Local llRetVal, lnOldSelect, lcUnique, lcSQL
4084
4085 lnOldSelect = Select()
4086 llRetVal = .T.
4087 lcFlds = ""
4088 lcValues = ""
4089 lcExcludeFlds = "'SQL_action'"
4090 lcCalFlds = "SQL_action"
4091 lcCalFldsValues = "'D'"
4092 lcFilter = "WHERE (1 = 1)"
4093 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordsp_update, "zzoordsp", ;
4094 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"sp")
4095
4096 TEXT TO lcSQL NOSHOW
4097 SELECT sp.* FROM #Zzoordrh_update h INNER JOIN zzoordsp sp WITH (NOLOCK) ON h.ord_num = sp.ord_num AND h.pick_num = sp.pick_num AND h.inv_num = sp.inv_num
4098 WHERE h.SQL_action = 'D' AND h.Ord_status = 'O'
4099 ENDTEXT
4100
4101 lcSQL = Strtran(lcSQL,"#Zzoordsp_update",pcZzoordsp_update)
4102 lcSQL = Strtran(lcSQL,"#Zzoordrh_update",pcZzoordrh_Update)
4103 lcSQL = STRTRAN(lcSQL,"sp.*",lcValues)
4104 lcSQL = "INSERT INTO " + pcZzoordsp_update + " ( " + lcFlds + " ) " + lcSql
4105 llRetVal = llRetVal And v_SQLExec(lcSQL)
4106
4107 Select(lnOldSelect)
4108 Return llRetVal
4109
4110 Endproc
4111
4112*-----------------------------------------------------------------------------------------
4113
4114 Procedure CreateOpenOrederToDelete(pcZzeipcth, pcZzoordrh_orig, pcZzoordrh_update)
4115
4116 Local llRetVal, lnOldSelect, lcUnique, lcSQL
4117 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
4118
4119 lnOldSelect = Select()
4120 llRetVal = .T.
4121 lcFlds = ""
4122 lcValues = ""
4123 lcExcludeFlds = "'SQL_action','POC_PURP'"
4124 lcCalFlds = "SQL_action,POC_PURP"
4125 lcCalFldsValues = "'D',TH.POC_PURP"
4126 lcFilter = "WHERE (1 = 1)"
4127 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, pcZzoordrh_orig, ;
4128 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h")
4129
4130 TEXT TO lcSql NOSHOW
4131 SELECT h.* FROM #Zzoordrh_orig h INNER JOIN #Zzeipcth th ON H.ORD_NUM = th.ord_num
4132 and h.ord_status = 'O' AND th.poc_purp = '01'
4133 ENDTEXT
4134
4135 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
4136 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4137 lcSQL = Strtran(lcSQL,"h.*",lcValues)
4138 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
4139 llRetVal = llRetVal And v_SQLExec(lcSQL)
4140
4141 Select(lnOldSelect)
4142 Return llRetVal
4143
4144 Endproc
4145
4146*-----------------------------------------------------------------------------------------
4147
4148 Procedure CreateOpenOrederDtlToDelete(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrd_orig, pcZzoordrh_update, pcZzoordrd_update)
4149
4150 Local llRetVal, lnOldSelect, lcUnique, lcSQL
4151 Local lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues, lcFilter
4152
4153 lnOldSelect = Select()
4154 llRetVal = .T.
4155 lcFlds = ""
4156 lcValues = ""
4157 lcExcludeFlds = "'SQL_action','POC_PURP'"
4158 lcCalFlds = "SQL_action,POC_PURP"
4159 lcCalFldsValues = "'D',TH.POC_PURP"
4160 lcFilter = "WHERE (1 = 1)"
4161 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrd_update, pcZzoordrd_orig, ;
4162 lcExcludeFlds,lcCalFlds,lcCalFldsValues, .f.,"od")
4163
4164 TEXT TO lcSQL NOSHOW
4165 SELECT od.* FROM #Zzoordrd_orig od INNER JOIN #Zzoordrh_orig oh ON oh.pkey = od.fkey
4166 INNER JOIN #Zzeipcth th ON OH.ORD_NUM = th.ord_num
4167 and oh.ord_status = 'O' and od.line_status = 'O' AND th.poc_purp = '01'
4168 ENDTEXT
4169
4170 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
4171 lcSQL = Strtran(lcSQL,"#Zzoordrd_orig",pcZzoordrd_orig)
4172 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4173 *lcValues = Strtran(lcValues,"h.","od.")
4174 lcSQL = Strtran(lcSQL,"od.*",lcValues)
4175 lcSQL = "INSERT INTO " + pcZzoordrd_update + " ( " + lcFlds + " ) " + lcSQL
4176 llRetVal = llRetVal And v_SQLExec(lcSQL)
4177
4178 Select(lnOldSelect)
4179 Return llRetVal
4180
4181 Endproc
4182
4183*-----------------------------------------------------------------------------------------
4184
4185 Procedure CreateCancelOrderDtlToInsertForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4186
4187 Local llRetVal, lcFlds,lcValues, lcCalFlds_SQL, loCopyUtil,lcUnique,lcExcludeFlds, lcFilter
4188 lnOldSelect = Select()
4189 llRetVal = .T.
4190
4191 *---- Create detail CANCEL records where old line qty > new line qty from update list
4192 *---- only consider DI or RZ and size quantity is negative (-)
4193 *--- TR 1034532 NH
4194 LOCAL lcAddJoin, lcMsg_add
4195 IF EMPTY(this.c860SODetailAddMatchCriteria)
4196 lcAddJoin = ""
4197 lcExcludeFldsAddi = ""
4198 lcCalFldsAddi = ""
4199 lcCalFldsValuesAddi = ""
4200 ELSE
4201 lcAddJoin = " and d.LINE_ID = dv." + THIS.c860SODetailAddMatchCriteria
4202 lcExcludeFldsAddi = ",'" + THIS.c860SODetailAddMatchCriteria + "'"
4203 lcCalFldsAddi = "," + THIS.c860SODetailAddMatchCriteria
4204 lcCalFldsValuesAddi = ",d.LINE_ID"
4205 ENDIF
4206 *=== TR 1034532 NH
4207
4208 lcFlds = ""
4209 lcValues = ""
4210
4211 *--- TR 1034532 NH
4212 *--- TechRec 1085945 24-Aug-2015 vkrishnamurthy ---
4213*!* lcExcludeFlds = "'SQL_action', 'line_status','size_qty','cncl_type','cncl_rsn'" + lcExcludeFldsAddi
4214*!* lcCalFlds = "SQL_action,line_status,size_qty, cncl_type, cncl_rsn " + lcCalFldsAddi
4215*!* lcCalFldsValues = "'I','C',D.QTY_CHANGE * (-1), r.cncl_type, r.cncl_rsn " + lcCalFldsValuesAddi && change the sign for delete items.
4216
4217 lcExcludeFlds = "'SQL_action', 'line_status','size_qty','cncl_type','cncl_rsn','bulk_resolved'" + lcExcludeFldsAddi
4218 lcCalFlds = "SQL_action,line_status,size_qty, cncl_type, cncl_rsn,bulk_resolved " + lcCalFldsAddi
4219 lcCalFldsValues = "'I','C',D.QTY_CHANGE * (-1), r.cncl_type, r.cncl_rsn,dv.bulk_resolved " + lcCalFldsValuesAddi && change the sign for delete items.
4220 *=== TechRec 1085945 24-Aug-2015 vkrishnamurthy ===
4221 *=== TR 1034532 NH
4222
4223 lcFilter = "WHERE (1 = 1)"
4224 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrdv_update ,pcZzeipctd , lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"d")
4225
4226 *--- always create new cancel line
4227 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = h.customer and r.division = h.division and added r.pkey = h.cr_pkey
4228 TEXT TO lcSQL NOSHOW
4229 SELECT d.* from #Zzeipctd d inner join #Zzoordrdv_orig dv on d.ord_num = dv.ord_num AND d.style = dv.style AND d.color_code = dv.color_code
4230 and d.lbl_code = dv.lbl_code and d.dimension = dv.dimension and d.sizebucket = dv.sizebucket and
4231 (d.qualifier in ('QD','DI') or (d.qualifier = 'RZ' and d.qty_change < 0 )) AND dv.line_status = 'O' lcAddJoin
4232 inner join #Zzeipcth h on h.pkey = d.fkey and h.poc_purp <> '01'
4233 inner join zzeipccr r on /*r.customer = h.customer and r.division = d.division*/ r.pkey = h.cr_pkey
4234 ENDTEXT
4235
4236*!* where not exists (select * from #Zzoordrdv_orig idv where idv.ord_num = dv.ord_num and idv.style = dv.style AND idv.color_code = dv.color_code
4237*!* and idv.lbl_code = dv.lbl_code and idv.dimension = dv.dimension and idv.sizebucket = dv.sizebucket and idv.line_status = 'C')
4238 lcSql = STRTRAN(lcSql,"lcAddJoin",lcAddJoin) &&--- TR 1034532 NH
4239 lcSQL = Strtran(lcSQL,"#Zzeipctd",pcZzeipctd)
4240 lcSQL = Strtran(lcSQL,"#Zzeipcth",pcZzeipcth)
4241 lcSQL = STRTRAN(lcSQL,"#Zzoordrdv_orig",pcZzoordrdv_orig)
4242
4243 *lcValues = Strtran(lcValues,"H.","d.")
4244 lcSQL = Strtran(lcSQL,"d.*",lcValues)
4245 lcSQL = "INSERT INTO " + pcZzoordrdv_update + " ( " + lcFlds + " ) " + lcSQL
4246 llRetVal = llRetVal And v_SQLExec(lcSQL)
4247
4248 Select(lnOldSelect)
4249 Return llRetVal
4250
4251 Endproc
4252
4253*-----------------------------------------------------------------------------------------
4254
4255 Procedure CreateCancelOrderDtlToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4256
4257 Local llRetVal, lcFlds,lcValues, lcCalFlds_SQL, loCopyUtil,lcUnique,lcExcludeFlds, lcFilter
4258 lnOldSelect = Select()
4259 llRetVal = .T.
4260
4261 *--- create zzoshprh record - invoice header record
4262 *--- cancel quantity will be added to the original cancel order quantity
4263 lcFlds = ""
4264 lcValues = ""
4265 lcExcludeFlds = "'SQL_action','size_qty'"
4266 lcCalFlds = "SQL_action, size_qty"
4267 lcCalFldsValues = "'U', D.QTY_CHANGE * (-1)"
4268 lcFilter = "WHERE (1 = 1)"
4269 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrdv_update, pcZzoordrdv_orig, ;
4270 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"dvc")
4271
4272 *--- d.qualifier = 'RZ' We already changed the sign of the d.size_qty for decrease quanity
4273 TEXT TO lcSQL NOSHOW
4274 SELECT dvc.* from #Zzeipctd d
4275 inner join #Zzoordrdv_orig dv on d.ord_num = dv.ord_num AND d.style = dv.style AND d.color_code = dv.color_code
4276 and d.lbl_code = dv.lbl_code and d.dimension = dv.dimension and d.sizebucket = dv.sizebucket
4277 and (d.qualifier IN ('QD','DI') OR ( d.qualifier = 'RZ' and d.qty_change < 0 ))
4278 and dv.line_status = 'O'
4279 inner join #Zzoordrdv_orig dvc on dvc.ord_num = dv.ord_num AND dvc.style = dv.style AND dvc.color_code = dv.color_code
4280 and dvc.lbl_code = dv.lbl_code and dvc.dimension = dv.dimension and dvc.sizebucket = dv.sizebucket and dvc.line_status = 'C'
4281 and (d.qualifier IN ('QD','DI') OR ( d.qualifier = 'RZ' and d.qty_change < 0 ))
4282 ENDTEXT
4283
4284 lcSQL = Strtran(lcSQL,"#Zzeipctd", pcZzeipctd)
4285 lcSQL = Strtran(lcSQL,"#Zzoordrdv_orig", pcZzoordrdv_orig)
4286 lcSQL = Strtran(lcSQL,"dvc.*",lcValues)
4287 lcSQL = "INSERT INTO " + pcZzoordrdv_update + " ( " + lcFlds + " ) " + lcSQL
4288 llRetVal = llRetVal And v_SQLExec(lcSQL)
4289
4290 Select(lnOldSelect)
4291 Return llRetVal
4292
4293 Endproc
4294
4295*-----------------------------------------------------------------------------------------
4296
4297 Procedure CreateCancelOrderToInsertForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4298
4299 Local llRetVal, lcFlds,lcValues, lcCalFlds_SQL, loCopyUtil,lcUnique,lcExcludeFlds, lcFilter
4300 lnOldSelect = Select()
4301 llRetVal = .T.
4302
4303 *--- create NEW cancel header
4304 lcFlds = ""
4305 lcValues = ""
4306 lcExcludeFlds = "'SQL_action', 'ord_status'"
4307 lcCalFlds = "SQL_action, ord_status"
4308 lcCalFldsValues = "'I','C'"
4309 lcFilter = "WHERE (1 = 1)"
4310 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update , pcZzoordrh_orig, lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h")
4311
4312 TEXT TO lcSQL NOSHOW
4313 SELECT h.* FROM #Zzoordrh_orig h
4314 WHERE EXISTS ( SELECT * from #Zzoordrdv_update dv WHERE dv.ord_num = h.ord_num AND h.ord_status = 'O' AND dv.line_status = 'C' )
4315 AND NOT EXISTS (SELECT * FROM #Zzoordrh_orig ih WITH (NOLOCK) WHERE ih.ord_num = h.ord_num AND ih.ord_status = 'C')
4316 AND NOT EXISTS (SELECT * FROM #Zzoordrh_update hc WHERE hc.ord_num = h.ord_num AND hc.ord_status = 'C')
4317 ENDTEXT
4318
4319 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4320 lcSQL = Strtran(lcSQL,"#Zzoordrh_update",pcZzoordrh_update)
4321 lcSQL = Strtran(lcSQL,"#Zzoordrdv_update",pcZzoordrdv_update)
4322
4323 lcSQL = Strtran(lcSQL,"h.*",lcValues)
4324 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
4325 llRetVal = llRetVal And v_SQLExec(lcSQL)
4326
4327 *--- create delete records and remove record from update list
4328 *--- we want to update quantity for the cancel once only
4329 TEXT TO lcSQl NOSHOW
4330 UPDATE hu SET ord_qty = dv.ord_qty FROM #Zzoordrh_update hu
4331 INNER JOIN (select ord_num, sum(size_qty) as ord_qty from #Zzoordrdv_update
4332 WHERE SQL_ACTION = 'I' and line_status = 'C' group by ord_num) dv on dv.ord_num = hu.ord_num
4333 WHERE NOT EXISTS (SELECT * FROM #Zzoordrh_orig ih WHERE ih.ord_num = hu.ord_num AND ih.ord_status = 'C')
4334 and hu.ord_status = 'C' and hu.SQL_action = 'I'
4335 ENDTEXT
4336
4337 lcSQL = Strtran(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4338 lcSQL = Strtran(lcSQL,"#Zzoordrh_update",pcZzoordrh_update)
4339 lcSQL = STRTRAN(lcSQl,"#Zzoordrdv_update",pcZzoordrdv_update)
4340 llRetVal = llRetVal And v_SQLExec(lcSQL)
4341
4342 Select(lnOldSelect)
4343 Return llRetVal
4344
4345 Endproc
4346
4347*-----------------------------------------------------------------------------------------
4348
4349 Procedure CreateCancelOrderToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4350
4351 Local llRetVal, lcFlds,lcValues, lcCalFlds_SQL, loCopyUtil,lcUnique,lcExcludeFlds, lcFilter
4352 lnOldSelect = Select()
4353 llRetVal = .T.
4354
4355 *--- create cancel header for UPDATE
4356 lcFlds = ""
4357 lcValues = ""
4358 lcExcludeFlds = "'SQL_action', 'ord_status'"
4359 lcCalFlds = "SQL_action, ord_status"
4360 lcCalFldsValues = "'U','C'"
4361 lcFilter = "WHERE (1 = 1)"
4362 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update , pcZzoordrh_orig, lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"h")
4363
4364 *--- AND NOT EXISTS (SELECT * FROM #zzoordrv_update idv WHERE idv.ord_num = h.ord_num) :
4365 *--- this is also needed to prevent from mulitple header getting created
4366 *--- when there are mulitple line item has DI records for same order
4367 TEXT TO lcSQL NOSHOW
4368 SELECT h.* from #zzoordrh_orig h
4369 WHERE EXISTS (SELECT * FROM #zzoordrdv_update dv WHERE dv.ord_num = h.ord_num and dv.line_status = 'C')
4370 AND NOT EXISTS (SELECT * FROM #Zzoordrh_update hc WHERE hc.ord_num = h.ord_num AND hc.ord_status = 'C')
4371 AND h.ord_status = 'C'
4372 ENDTEXT
4373
4374 lcSQL = Strtran(lcSQL,"#zzoordrh_orig",pcZzoordrh_orig)
4375 lcSQL = Strtran(lcSQL,"#Zzoordrh_update",pcZzoordrh_update)
4376 lcSQL = Strtran(lcSQL,"#zzoordrdv_update",pcZzoordrdv_update)
4377 lcSQL = Strtran(lcSQL,"h.*",lcValues)
4378 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
4379 llRetVal = llRetVal And v_SQLExec(lcSQL)
4380
4381 *--- always create new cancel line item.
4382 *---- set order quantity of cancel header for UPDATE
4383 *---- cancel order quantity is only the new update quantity, on update this needs to be added to original cancel order quantity
4384 *--- some times, line item sizebucket does not exists in cancel order detail but sku exists then we need to consider that as an update to header
4385 *--- that will not be picked up by the insert cycle
4386*!* where exists (select dvo.ord_num from #Zzoordrdv_orig dvo where dvo.ord_num = dvu.ord_num and dvo.line_status = dvu.line_status
4387*!* and dvo.division = dvu.division and dvo.style = dvu.style and dvo.color_code = dvu.color_code and dvo.lbl_code = dvu.lbl_code
4388*!* and dvo.dimension = dvu.dimension and dvu.line_status = 'C' and dvu.sql_action in ('U','I'))
4389
4390 TEXT TO lcSQL NOSHOW
4391 UPDATE H SET ord_qty = dvu.ord_qty FROM #zzoordrh_update H
4392 INNER JOIN (
4393 SELECT dvu.ord_num, sum(dvu.size_qty) as ord_qty from #zzoordrdv_update dvu
4394 where dvu.line_status = 'C' and dvu.sql_action in ('U','I')
4395 group by dvu.ord_num) dvu ON dvu.ord_num = h.ord_num
4396 where h.ord_status = 'C' and h.SQL_action = 'U'
4397 ENDTEXT
4398
4399 lcSQL = Strtran(lcSQL,"#zzoordrh_orig",pcZzoordrh_orig)
4400 lcSQL = Strtran(lcSQL,"#zzoordrh_update",pcZzoordrh_update)
4401 lcSQL = Strtran(lcSQL,"#zzoordrdv_update",pcZzoordrdv_update)
4402 lcSQL = STRTRAN(lcSQL,"#Zzoordrdv_orig",pcZzoordrdv_orig)
4403 llRetVal = llRetVal And v_SQLExec(lcSQL)
4404
4405 Select(lnOldSelect)
4406 Return llRetVal
4407
4408 Endproc
4409
4410*-----------------------------------------------------------------------------------------
4411
4412 Procedure PrepareForQualifier_QuantityDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4413
4414 Local llRetVal, lcFlds,lcValues, lcCalFlds_SQL, loCopyUtil,lcUnique,lcExcludeFlds,lnThermoCnt
4415 lnOldSelect = Select()
4416 llRetVal = .T.
4417 lnThermoCnt = 0
4418
4419 *--- Qualifier - QD and RZ
4420 *--- add record to order detail for update
4421 this.InitThermoWithCaption(lnThermoCnt,6,"Prepare for order quantity decrease.")
4422 llRetVal = llRetVal And This.CreateOrderDtlToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4423 this.LogEntry("Prepare existing order detail for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4424 this.AdvanceThermoPlus(@lnThermoCnt)
4425
4426 llRetVal = llRetVal And This.CreateOrderToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4427 this.LogEntry("Prepare existing order for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4428 this.AdvanceThermoPlus(@lnThermoCnt)
4429
4430 llRetVal = llRetVal And This.CreateCancelOrderDtlToInsertForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4431 this.LogEntry("Prepare new cancel order detail for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4432 this.AdvanceThermoPlus(@lnThermoCnt)
4433
4434 *--- always create new cancel line.
4435*!* llRetVal = llRetVal And This.CreateCancelOrderDtlToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4436*!* this.LogEntry("Prepare existing cancel order detail for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4437*!* this.AdvanceThermoPlus(@lnThermoCnt)
4438
4439 llRetVal = llRetVal And This.CreateCancelOrderToInsertForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig,pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4440 this.LogEntry("Prepare new cancel order for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4441 this.AdvanceThermoPlus(@lnThermoCnt)
4442
4443 llRetVal = llRetVal And This.CreateCancelOrderToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig,pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4444 this.LogEntry("Prepare existing cancel order for quantity decrease " + IIF(llRetVal,"completed.","failed."))
4445 this.AdvanceThermoPlus(@lnThermoCnt)
4446
4447 Select(lnOldSelect)
4448 Return llRetVal
4449
4450 Endproc
4451
4452*-----------------------------------------------------------------------------------------
4453
4454 Procedure SetPkeyForCancelOrders(pcZzoordrh_update)
4455
4456 Local llRetVal, lnOldSelect
4457
4458 llRetVal = .T.
4459
4460 llRetVal = llRetVal And v_SQLExec(lcSQL)
4461
4462 Return llRetVal
4463
4464 Endproc
4465
4466*-----------------------------------------------------------------------------------------
4467
4468 Procedure CreateOrderDtlToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4469
4470 Local llRetVal, lnOldSelect, lcUnique
4471 lnOldSelect = Select()
4472 llRetVal = .T.
4473
4474 *--- TR 1034532 NH
4475 LOCAL lcAddJoin
4476 LOCAL lcExcludeFldsAddi,lcCalFldsAddi,lcCalFldsValuesAddi
4477 IF EMPTY(this.c860SODetailAddMatchCriteria)
4478 lcAddJoin = ""
4479 lcExcludeFldsAddi = ""
4480 lcCalFldsAddi = ""
4481 lcCalFldsValuesAddi = ""
4482 ELSE
4483 lcAddJoin = " and td.LINE_ID = dv." + THIS.c860SODetailAddMatchCriteria
4484 lcExcludeFldsAddi = ",'" + THIS.c860SODetailAddMatchCriteria + "'"
4485 lcCalFldsAddi = "," + THIS.c860SODetailAddMatchCriteria
4486 lcCalFldsValuesAddi = ",td.LINE_ID"
4487 ENDIF
4488 *=== TR 1034532 NH
4489
4490 *--- prepare 860 transaction quantity for DI - delete item.
4491 lcSQL = " Update td SET qty_change = dv.size_qty * (-1) from " + pcZzeipctd + " td " + ;
4492 " INNER JOIN " + pcZzoordrdv_orig + " dv " + ;
4493 " ON dv.ord_num = td.ord_num " + ;
4494 " and dv.division = td.division and dv.style = td.style and dv.color_code = td.color_code and dv.lbl_code = td.lbl_code " + ;
4495 " and dv.dimension = td.dimension and dv.sizebucket = td.sizebucket " + ;
4496 lcAddJoin + ; &&---TR 1034532 NH
4497 " Inner Join " + pcZzeipcth + " th ON th.pkey = td.fkey " + ;
4498 " WHERE td.qualifier = 'DI' AND dv.line_status = 'O' AND th.poc_purp <> '01'"
4499
4500 llRetVal = llRetVal and v_sqlexec(lcSQL)
4501
4502 lcFlds = ""
4503 lcValues = ""
4504
4505 *--- TR 1034532 NH
4506 *--- TechRec 1085945 24-Aug-2015 vkrishnamurthy ---
4507*!* lcExcludeFlds = "'SQL_action', 'line_status','size_qty'" + lcExcludeFldsAddi
4508*!* lcCalFlds = "SQL_action,line_status,size_qty" + lcCalFldsAddi
4509*!* lcCalFldsValues = "'U','O',TD.QTY_change " + lcCalFldsValuesAddi && keep the sign negative for reduction of quantity
4510
4511 lcExcludeFlds = "'SQL_action', 'line_status','size_qty','bulk_resolved'" + lcExcludeFldsAddi
4512 lcCalFlds = "SQL_action,line_status,size_qty,bulk_resolved" + lcCalFldsAddi
4513 lcCalFldsValues = "'U','O',TD.QTY_change , dv.bulk_resolved " + lcCalFldsValuesAddi && keep the sign negative for reduction of quantity
4514 *=== TechRec 1085945 24-Aug-2015 vkrishnamurthy ===
4515 *=== TR 1034532 NH
4516
4517 lcFilter = "WHERE (1 = 1)"
4518 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrdv_update, pcZzeipctd, lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"td")
4519
4520 lcSQL = " SELECT td.* FROM " + pcZzeipctd + " td " + ;
4521 " inner join " + pcZzoordrdv_orig + " dv " + ;
4522 " on td.ord_num = dv.ord_num " + ;
4523 " and td.style = dv.style and td.color_code = dv.color_code " + ;
4524 " and td.lbl_code = dv.lbl_Code and td.dimension = dv.dimension " + ;
4525 lcAddJoin + ; &&--- TR 1034532 NH
4526 " and td.sizebucket = dv.sizebucket and dv.line_status = 'O' " + ;
4527 " and ((td.qualifier = 'RZ' and td.qty_change < 0) or td.qualifier IN ( 'QD','DI')) " + ;
4528 " Inner Join " + pcZzeipcth + " th ON th.pkey = td.fkey AND th.poc_purp <> '01'"
4529
4530 lcSQL = Strtran(lcSQL,"td.*",lcValues)
4531 lcSQL = "INSERT INTO " + pcZzoordrdv_update + " ( " + lcFlds + " ) " + lcSQL
4532 llRetVal = llRetVal And v_SQLExec(lcSQL)
4533
4534 Select(lnOldSelect)
4535 Return llRetVal
4536
4537 Endproc
4538
4539*-----------------------------------------------------------------------------------------
4540
4541 Procedure CreateOrderToUpdateForQtyDecrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update)
4542
4543 Local llRetVal, lnOldSelect, lcUnique, lcFlds,lcValues,lcExcludeFlds,lcCalFlds,lcCalFldsValues,lcFilter
4544 lnOldSelect = Select()
4545 llRetVal = .T.
4546
4547 *--- insert orders those are not in pcZzoordrh_update
4548 lcFlds = ""
4549 lcValues = ""
4550 lcExcludeFlds = "'SQL_action', 'ord_status', 'ord_qty'"
4551 lcCalFlds = "SQL_action,ord_status, ord_qty"
4552 lcCalFldsValues = "'U','O',d.ord_qty" && keep the sign negative for reduction of quantity
4553 lcFilter = "WHERE (1 = 1)"
4554
4555 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update,pcZzoordrh_orig , lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"oh")
4556 TEXT TO lcSQL NOSHOW
4557 SELECT oh.* FROM #Zzoordrh_orig oh INNER JOIN ( SELECT ORD_NUM, SUM(size_qty) as ord_qty FROM #Zzoordrdv_update dvu
4558 WHERE dvu.size_qty < 0 AND dvu.line_status = 'O' group by dvu.ord_num) d ON oh.ord_num = d.ord_num AND oh.ord_status = 'O'
4559 ENDTEXT
4560
4561 lcSQL = STRTRAN(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4562 lcSQL = STRTRAN(lcSQL,"#Zzoordrdv_update",pcZzoordrdv_update)
4563 lcSQL = Strtran(lcSQL, "oh.*",lcValues)
4564 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
4565 llRetVal = llRetVal And v_SQLExec(lcSQL)
4566
4567 Select(lnOldSelect)
4568 Return llRetVal
4569
4570 Endproc
4571
4572*-----------------------------------------------------------------------------------------
4573
4574 Procedure PrepareForQualifier_QuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update,pcZzoordsp_update, pcRefZzoordrh_new)
4575
4576 Local llRetVal, lnOldSelect, lcUnique,lnThermoCnt
4577 lnOldSelect = Select()
4578 llRetVal = .T.
4579 lnThermoCnt = 0
4580 *--- qualifier - QI , RZ, AI
4581 this.InitThermoWithCaption(lnThermoCnt,3,"Prepare for order quantity increase.")
4582
4583 llRetVal = llRetVal and This.CreateNewOrderToInsertForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update,pcZzoordsp_update, @pcRefZzoordrh_new)
4584 this.LogEntry("Prepare new order for quantity increase " + IIF(llRetVal,"completed.","failed."))
4585 this.AdvanceThermoPlus(@lnThermoCnt)
4586
4587 llRetVal = llRetVal And This.CreateOrderDtlToUpdateForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update)
4588 this.LogEntry("Prepare existing order detail for quantity increase " + IIF(llRetVal,"completed.","failed."))
4589 this.AdvanceThermoPlus(@lnThermoCnt)
4590
4591 llRetVal = llRetVal And This.CreateOrderToUpdateForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update)
4592 this.LogEntry("Prepare existing order for quantity increase " + IIF(llRetVal,"completed.","failed."))
4593 this.AdvanceThermoPlus(@lnThermoCnt)
4594
4595 Select(lnOldSelect)
4596 Return llRetVal
4597
4598 Endproc
4599
4600*-----------------------------------------------------------------------------------------
4601
4602 PROCEDURE CreateNewOrderToInsertForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update, pcZzoordsp_update, pcRefZzoordrh_new)
4603
4604 *new_order
4605 Local llRetVal, lnOldSelect, lcUnique, lcZzoordrh_new
4606 LOCAL lnMaxOrd_num,lnOrdCount
4607
4608 *--- TR 1070419 16-Apr-2013 Goutam
4609 LOCAL lcFieldList
4610 *=== TR 1070419 16-Apr-2013 Goutam
4611
4612 lnOldSelect = Select()
4613 llRetVal = .T.
4614 lcUnique = SYS(2015)
4615 lcZzoordrh_new = "#zzoordrh" + lcUnique
4616
4617 *--- use zzoordrh instead of pcZzoordrh_orig table
4618 *--- add - and ih.ord_status = 'O' to avoid cancel orders
4619 *--- TR 1036066 NH : edi_Store field length should equal to zzxstorr.edi_store
4620 *--- rem out - h.store as Edi_store
4621 *--- TR 1048865 17-Mar-2011 Goutam. Removed r.customer = th.customer and r.division = th.division and added r.pkey = th.cr_pkey
4622 *--- TR 1053720 25-May-2011 Goutam. Removed and oh.ord_status = 'O' from the following condition
4623 *--- TR 1062197 10-Sep-2012 Goutam. Added additional condition in sub query not exists(...) for store validation
4624
4625 *--- TR 1070419 16-Apr-2013 Goutam
4626 lcFieldList = this.GetSOFieldListWithoutUDF("h.", "zzoordrh")
4627 *=== TR 1070419 16-Apr-2013 Goutam
4628
4629 *--- TR 1070419 16-Apr-2013 Goutam. Added lcFieldList in place of h.*
4630 *lcSQL = " SELECT h.*, n.store as NewStore, h.ord_num as old_ord_num, r.edi_store into " + lcZzoordrh_new
4631
4632 lcSQL = " SELECT " + lcFieldList + " , n.store as NewStore, h.ord_num as old_ord_num, r.edi_store into " + lcZzoordrh_new + ;
4633 " FROM " + ;
4634 " zzoordrh h (nolock) inner join ( " + ;
4635 " SELECT oh.customer, oh.po_num, th.store, max(oh.pkey) as pkey " + ;
4636 " FROM zzoordrh oh (nolock) " + ;
4637 " INNER JOIN " + pcZzeipcth + " th ON oh.customer = th.customer and oh.po_num = th.po_num and th.poc_purp <> '01' " + ;
4638 " INNER JOIN zzeipccr r on /*r.customer = th.customer and r.division = th.division*/ r.pkey = th.cr_pkey " + ;
4639 " WHERE not exists (select * from zzoordrh ih (nolock) " + ;
4640 " WHERE ih.customer = th.customer " + ;
4641 " and ih.po_num = th.po_num and ih.store = case when poc_purp = '04' and poc_store > '' then ih.store else th.store end and ih.ord_status = 'O') " + ;
4642 " GROUP BY oh.customer, oh.po_num, th.store) n " + ;
4643 " ON h.pkey = n.pkey " + ;
4644 " INNER JOIN zzxstorr r on r.customer = h.customer and r.store = h.store "
4645 *=== TR 1036066 NH
4646
4647 llRetVal = llRetVal and v_sqlexec(lcSQL)
4648
4649 pcRefZzoordrh_new = lcZzoordrh_new && make sure it exists later on
4650
4651 *--- UPDATE necessary field values
4652 *--- TR 1053720 25-May-2011 Goutam. Added cncl_num and ord_status in the following list
4653 lcSQL = " UPDATE h SET store = h.NewStore, cncl_num = 0, ord_status = 'O' FROM " + lcZzoordrh_new + " h "
4654 llRetVal = llRetVal and v_sqlexec(lcSQL)
4655
4656 lcSQL = " select COUNT(*) as NewOrderCount FROM " + lcZzoordrh_new + " h "
4657 llRetVal = llRetVal and v_sqlexec(lcSQL,"NewOrderCount")
4658
4659 lnMaxOrd_num = 0
4660 lnNewOrdCount = 0
4661
4662 IF USED("NewOrderCount")
4663 lnNewOrdCount = NewOrderCount.NewOrderCount
4664 USE IN NewOrderCount
4665 ENDIF
4666
4667 IF NOT (llRetVal AND lnNewOrdCount > 0)
4668 SELECT(lnOldSelect)
4669 RETURN llRetVal
4670 ENDIF
4671 this.LogEntry("Number of new order needs to be created " + TRANSFORM(lnNewOrdCount))
4672
4673 *--- create sp records.
4674 lcZzoordsp_new = "#zzoordsp" + lcUnique
4675 lcSQL = " SELECT * INTO " + lcZzoordsp_new + " FROM zzoordsp sp WHERE 1 =2 "
4676 llRetVal = llRetVal and v_sqlexec(lcSQL)
4677
4678 lcFlds = ""
4679 lcValues = ""
4680 lcExcludeFlds = "'ORD_NUM','carton_cls' "
4681 lcCalFlds = "ORD_NUM,carton_cls"
4682 lcCalFldsValues = "nh.NewOrd_num,'S'" && keep the sign negative for reduction of quantity
4683 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, lcZzoordsp_new , pcZzoordrh_orig, ;
4684 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"sp")
4685
4686 *---TR 1050774 01/20/2011 YE -Moved up here from below.
4687 *--- Set ord_num to new order header
4688 lnMaxOrd_num = v_NextId('ZZXCOMPR','ORD_NUM', lnNewOrdCount)
4689 llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(lcZzoordrh_new,"ORD_NUM",lnMaxOrd_num,lnNewOrdCount,"ORD_NUM_I")
4690 *===TR 1050774 01/20/2011 YE
4691
4692 *--- here, GROUP BY n.Ord_num is used to get only one record per new order number.
4693 lcSQL = " INSERT INTO " + lcZzoordsp_new + " ( " + lcFlds + " ) " + ;
4694 " SELECT " + lcValues + " FROM zzoordsp sp (NOLOCK) " + ;
4695 " INNER JOIN " + ;
4696 " (SELECT MIN(oh.ORD_NUM) as ord_num, MIN(oh.PICK_NUM) as pick_num, MIN(oh.INV_NUM) as inv_num, " + ;
4697 " n.Ord_num as NewOrd_Num " + ;
4698 " FROM zzoordrh oh (nolock) " + ;
4699 " INNER JOIN " + lcZzoordrh_new + " n ON n.po_num = oh.po_num and n.customer = oh.customer " + ;
4700 " and oh.ord_status = 'O' GROUP BY n.Ord_num " + ;
4701 " ) nh " + ;
4702 " ON nh.ord_num = sp.ord_num and nh.pick_num = sp.pick_num " + ;
4703 " and nh.inv_num = sp.inv_num "
4704
4705 llRetVal = llRetVal and v_sqlexec(lcSQL)
4706
4707 *--- make sure cartons = 'N' , carton_seq = 0, prod_num = 0
4708 lcSQL = " UPDATE sp SET cartons = 'N' , carton_seq = 0, prod_num = 0 FROM " + lcZzoordsp_new + " sp "
4709 llRetVal = llRetVal and v_sqlexec(lcSQL)
4710
4711 *---TR 1050774 01/20/2011 YE - We must do this BEFORE creating lcZzoordsp_new otherwise lcZzoordsp_new won't have the new orders
4712 *--- Set ord_num to new order header
4713*!* lnMaxOrd_num = v_NextId('ZZXCOMPR','ORD_NUM', lnNewOrdCount)
4714*!* llRetVal = llRetVal and this.oCopyUtil.KeyFldUpdate(lcZzoordrh_new,"ORD_NUM",lnMaxOrd_num,lnNewOrdCount,"ORD_NUM_I")
4715 *===TR 1050774 01/20/2011 YE
4716
4717 *--- clear shipping fields : lcZzoordrh_new table name will be changed if there is any record exists.
4718 llRetVal = llRetVal and this.ClearShippingFields(lcZzoordrh_new)
4719
4720 *--- set ord_num to transaction header
4721 lcSQL = " UPDATE th SET ord_num = n.ord_num FROM " + pcZzeipcth + " th " + ;
4722 " INNER JOIN " + lcZzoordrh_new + " n ON n.customer = th.customer and n.po_num = th.po_num " +;
4723 " AND n.store = th.store "
4724 llRetVal = llRetVal and v_sqlexec(lcSQL)
4725
4726 *--- set ord_num to transaction detail
4727 lcSQL = " UPDATE td SET ord_num = th.ORD_NUM FROM " + pcZzeipctd + " td " + ;
4728 " INNER JOIN " + pcZzeipcth + " th ON th.pkey = td.fkey "
4729 llRetVal = llRetVal and v_sqlexec(lcSQL)
4730
4731 * --- TR 1043960 5/25/10 CM
4732 *--- set ord_num for transaction header on the server
4733 lcSQL = " UPDATE h SET ord_num = th.ord_num FROM zzeipcth h " + ;
4734 " INNER JOIN " + pcZzeipcth + " th ON h.pkey = th.pkey "
4735 llRetVal = llRetVal and v_sqlexec(lcSQL)
4736
4737 lcSQL = " UPDATE " + lcZzoordrh_new + " SET chk_hist = 'Y' "
4738 llRetVal = llRetVal and v_sqlexec(lcSQL)
4739 * === TR 1043960 5/25/10 CM
4740
4741 *--- update edi_store in new orders for later purpose.
4742 lcSQL = " UPDATE n SET edi_store = th.edi_store FROM " + pcZzeipcth + " th " + ;
4743 " INNER JOIN " + lcZzoordrh_new + " n ON n.customer = th.customer and n.po_num = th.po_num " +;
4744 " AND n.store = th.store "
4745 llRetVal = llRetVal and v_sqlexec(lcSQL)
4746
4747 *--- add new orders to order update table
4748 lcFlds = ""
4749 lcValues = ""
4750 lcExcludeFlds = "'SQL_action','ord_qty','bulk_red' "
4751 lcCalFlds = "SQL_action, ord_qty,bulk_red"
4752 lcCalFldsValues = "'I',0,'N' " && keep the sign negative for reduction of quantity
4753 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, lcZzoordrh_new, ;
4754 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"n")
4755 lcSQL = " INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) SELECT " + lcValues + " FROM " + lcZzoordrh_new + " n "
4756 llRetVal = llRetVal and v_sqlexec(lcSQL)
4757
4758 *--- update ord_num in sp records
4759 lcSQL = " UPDATE sp SET ord_num = n.ord_num FROM " + lcZzoordsp_new + " sp INNER JOIN " + lcZzoordrh_new + " n " + ;
4760 " ON sp.ord_num = n.old_ord_num "
4761 llRetVal = llRetVal and v_sqlexec(lcSQL)
4762
4763 *--- add new sp records to sp update table
4764 lcFlds = ""
4765 lcValues = ""
4766 lcExcludeFlds = "'SQL_action','old_ord_num' "
4767 lcCalFlds = "SQL_action"
4768 lcCalFldsValues = "'I'" && keep the sign negative for reduction of quantity
4769 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordsp_update, lcZzoordsp_new, ;
4770 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"n")
4771
4772 lcSQL = " INSERT INTO " + pcZzoordsp_update + " ( " + lcFlds + " ) SELECT " + lcValues + " FROM " + lcZzoordsp_new + " n "
4773 llRetVal = llRetVal and v_sqlexec(lcSQL)
4774
4775 *--- drop temp tables
4776 IF llRetVal
4777 v_sqlexec("drop table " + lcZzoordsp_new )
4778 *--- do not drop lcZzoordrh_new this will be used to add new store to other trans record for duplicate PO changes
4779 *v_sqlexec("drop table " + lcZzoordrh_new)
4780 ENDIF
4781
4782 Select(lnOldSelect)
4783 Return llRetVal
4784
4785 Endproc
4786
4787*-----------------------------------------------------------------------------------------
4788
4789 PROCEDURE ClearShippingFields(pcZzoordrh_new)
4790
4791 Local llRetVal, lnOldSelect, lcUnique
4792 lnOldSelect = Select()
4793 llRetVal = .T.
4794
4795 LOCAL lcSQL,lcZzoordrh_new, loOrdHdr
4796 lcZzoordrh_cur = "zzoordrh" + SYS(2015)
4797 lcSQL = "SELECT * FROM " + pcZzoordrh_new
4798 llRetVal = llRetVal and v_sqlexec(lcSQL,lcZzoordrh_cur)
4799
4800 IF RECCOUNT(lcZzoordrh_cur) = 0
4801 RETURN llRetVal
4802 ENDIF
4803
4804 SELECT(lcZzoordrh_cur)
4805 SCAN
4806 SCATTER NAME loOrdHdr
4807 this.oMainProcess.oBPOSalesOrder.ClearShippingFields(@loOrdHdr)
4808 GATHER NAME loOrdHdr
4809 ENDSCAN
4810
4811 this.cSQLTempTable = ""
4812 llRetVal = llRetVal AND this.GenerateSQLTempTable(lcZzoordrh_cur)
4813 llRetVal = llRetVal AND this.PopulateSQLTempTable(lcZzoordrh_cur) and not EMPTY(this.cSQLTempTable)
4814
4815 IF llRetVal
4816 llRetVal = llRetVal and v_sqlexec("DROP TABLE " + pcZzoordrh_new)
4817 llRetVal = llRetVal and v_sqlexec("select * into " + pcZzoordrh_new + " from " + this.cSQLTempTable)
4818 llRetVal = llRetVal and v_sqlexec("DROP TABLE " + this.cSQLTempTable)
4819 ENDIF
4820 Select(lnOldSelect)
4821 Return llRetVal
4822
4823 Endproc
4824
4825*-----------------------------------------------------------------------------------------
4826
4827 Procedure CreateOrderDtlToUpdateForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZoordrh_orig, pcZoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update)
4828
4829 Local llRetVal, lnOldSelect, lcUnique
4830 lnOldSelect = Select()
4831 llRetVal = .T.
4832
4833 *--- TR 1034532 NH
4834 LOCAL lcExcludeFldsAddi,lcCalFldsAddi,lcCalFldsValuesAddi
4835
4836 IF EMPTY(this.c860SODetailAddMatchCriteria)
4837 lcExcludeFldsAddi = ""
4838 lcCalFldsAddi = ""
4839 lcCalFldsValuesAddi = ""
4840 ELSE
4841 lcExcludeFldsAddi = ",'" + THIS.c860SODetailAddMatchCriteria + "'"
4842 lcCalFldsAddi = "," + THIS.c860SODetailAddMatchCriteria
4843 lcCalFldsValuesAddi = ",td.LINE_ID"
4844 ENDIF
4845 *=== TR 1034532 NH
4846
4847 lcFlds = ""
4848 lcValues = ""
4849
4850 *--- TR 1034532 NH
4851*!* lcExcludeFlds = "'SQL_action', 'line_status','size_qty'" + lcExcludeFldsAddi
4852*!* lcCalFlds = "SQL_action,line_status,size_qty" + lcCalFldsAddi
4853*!* lcCalFldsValues = "'I','O',td.qty_change" + lcCalFldsValuesAddi
4854 lcExcludeFlds = "'SQL_action', 'line_status','price','size_qty'" + lcExcludeFldsAddi && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
4855 lcCalFlds = "SQL_action,line_status,price,size_qty" + lcCalFldsAddi && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
4856 lcCalFldsValues = "'I','O',poc_cost,td.qty_change" + lcCalFldsValuesAddi && VKK 1067224 &&--- TechRec 1067224 27-Mar-2013 vkrishnamurthy ===
4857 *=== TR 1034532 NH
4858
4859 lcFilter = "WHERE (1 = 1)"
4860 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrdv_update, pcZzeipctd, lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,'td')
4861
4862 lcSQL = "SELECT td.* FROM " + pcZzeipctd + " td inner join " + pcZzeipcth + " th ON th.pkey = td.fkey and th.poc_purp <> '01' " + ;
4863 " WHERE (td.qualifier in ('QI','AI') OR (td.qualifier = 'RZ' AND td.qty_change >= 0)) and td.ord_num > 0 "
4864
4865 lcSQL = Strtran(lcSQL,"td.*",lcValues)
4866 lcSQL = "INSERT INTO " + pcZzoordrdv_update + " ( " + lcFlds + " ) " + lcSQL
4867 llRetVal = llRetVal And v_SQLExec(lcSQL)
4868
4869 *--- correct the sql_action for existing detail lines
4870
4871 Select(lnOldSelect)
4872 Return llRetVal
4873
4874 Endproc
4875
4876*-----------------------------------------------------------------------------------------
4877
4878 Procedure CreateOrderToUpdateForQuantityIncrease(pcZzeipcth, pcZzeipctd, pcZzoordrh_orig, pcZzoordrdv_orig, pcZzoordrh_update, pcZzoordrdv_update)
4879
4880 Local llRetVal, lnOldSelect, lcUnique
4881 lnOldSelect = Select()
4882 llRetVal = .T.
4883
4884 *--- update ord_qty if the header is already exists
4885 TEXT TO lcSQL NOSHOW
4886 UPDATE h set ord_qty = h.ord_qty + td.ord_qty from #Zzoordrh_update h inner join ( select d.ord_num, SUM(d.qty_change) as ord_qty
4887 from #Zzeipctd d inner join #Zzeipcth th on th.pkey = d.fkey and th.poc_purp <> '01'
4888 WHERE (d.qualifier IN ('QI','AI')) OR (d.qualifier = 'RZ' AND d.qty_change >= 0) group by d.ord_num )
4889 td on h.ord_num = td.ord_num and h.ord_status = 'O' and h.SQL_action ='U'
4890 ENDTEXT
4891
4892 lcSQL = STRTRAN(lcSQL,"#Zzoordrh_update",pcZzoordrh_update)
4893 lcSQL = STRTRAN(lcSQL,"#Zzeipctd",pcZzeipctd)
4894 lcSQL = STRTRAN(lcSQL,"#Zzeipcth",pcZzeipcth)
4895
4896 llRetVal = llRetVal And v_SQLExec(lcSQL)
4897 *--- create order header record
4898
4899 lcFlds = ""
4900 lcValues = ""
4901 lcExcludeFlds = "'SQL_action', 'ord_status','ord_qty'"
4902 lcCalFlds = "SQL_action,ord_status, ord_qty"
4903 lcCalFldsValues = "'U','O',td.ord_qty" && change the sign for delete items.
4904 lcFilter = "WHERE (1 = 1)"
4905 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pcZzoordrh_update, pcZzoordrh_orig, lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"oh")
4906
4907 TEXT TO lcSQL NOSHOW
4908 SELECT oh.* FROM #Zzoordrh_orig oh (nolock) INNER JOIN
4909 ( SELECT d.ord_num, SUM(d.qty_change) AS ord_qty FROM #Zzeipctd d inner join #Zzeipcth th on th.pkey = d.fkey and th.poc_purp <> '01'
4910 WHERE (d.qualifier IN ('QI', 'AI') OR (d.qualifier = 'RZ' AND d.qty_change >= 0)) GROUP BY d.ord_num)
4911 td ON oh.ord_num = td.ord_num AND oh.ord_status = 'O'
4912 where not exists ( SELECT * FROM #Zzoordrh_update hu WHERE hu.ord_num = oh.ord_num AND hu.ord_status = 'O')
4913 ENDTEXT
4914
4915 lcSQL = Strtran(lcSQL,"oh.*",lcValues)
4916 lcSQL = Strtran(lcSQL,"#Zzoordrh_update",pcZzoordrh_update)
4917 *lcSQL = STRTRAN(lcSQL,"#Zzoordrh_orig",pcZzoordrh_orig)
4918 lcSQL = STRTRAN(lcSQL,"#Zzoordrh_orig","zzoordrh")
4919 lcSQL = STRTRAN(lcSQL,"#Zzeipctd",pcZzeipctd)
4920 lcSQL = STRTRAN(lcSQL,"#Zzeipcth",pcZzeipcth)
4921 lcSQL = "INSERT INTO " + pcZzoordrh_update + " ( " + lcFlds + " ) " + lcSQL
4922 llRetVal = llRetVal And v_SQLExec(lcSQL)
4923
4924 Select(lnOldSelect)
4925 Return llRetVal
4926
4927 Endproc
4928
4929*-----------------------------------------------------------------------------------------
4930
4931 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
4932*!* Procedure CreateOrderUpdateTempTables(pcZzeipcth,pcZzeipctd, pcZzoordrdv_orig, pcRefZzoordrh_update, pcRefZzoordrd_update, pcRefZzoordrdv_update, pcRefZzoordsp_update, pcReflcAlloc_update)
4933 Procedure CreateOrderUpdateTempTables(pcZzeipcth,pcZzeipctd, pcZzoordrdv_orig, pcRefZzoordrh_update, pcRefZzoordrd_update, pcRefZzoordrdv_update, pcRefZzoordsp_update, pcReflcAlloc_update,pczzeipohd,pczzeipohd_update)
4934 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
4935
4936 Local llRetVal, lnOldSelect, lcUnique
4937 lnOldSelect = Select()
4938 llRetVal = .T.
4939
4940 Local lcZzoordrh_Update, lcZzoordrd_update, lcZzoordsp_update,lcUnique
4941
4942 lcUnique = Sys(2015)
4943 lcZzoordrh_Update = "#Zzoordrh" + lcUnique
4944 lcZzoordrd_Update = "#Zzoordrd" + lcUnique
4945 lcZzoordrdv_update = "#Zzoordrdv" + lcUnique
4946 lcZzoordsp_update = "#Zzoordsp" + lcUnique
4947
4948 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
4949 LOCAL lczzeipohd_update
4950 lczzeipohd_update = "#zzeipohd" + lcUnique
4951 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
4952
4953 lcSQL = "SELECT * into " + lcZzoordrh_Update + " from zzoordrh WHERE 1=2"
4954 llRetVal = llRetVal And v_SQLExec(lcSQL)
4955
4956 lcSQL = "SELECT * into " + lcZzoordrd_Update + " from zzoordrd WHERE 1=2"
4957 llRetVal = llRetVal And v_SQLExec(lcSQL)
4958
4959 lcSQL = "SELECT * into " + lcZzoordrdv_update + " from " + pcZzoordrdv_orig + " WHERE 1=2"
4960 llRetVal = llRetVal And v_SQLExec(lcSQL)
4961
4962 lcSQL = "SELECT * into " + lcZzoordsp_update + " from zzoordsp WHERE 1=2"
4963 llRetVal = llRetVal And v_SQLExec(lcSQL)
4964
4965 lcSQL = "ALTER TABLE " + lcZzoordrh_Update + " add SQL_action char(1) default('') not null"
4966 llRetVal = llRetVal And v_SQLExec(lcSQL)
4967
4968 lcSQL = "ALTER TABLE " + lcZzoordrh_Update + " add poc_purp char(2) default('') not null"
4969 llRetVal = llRetVal And v_SQLExec(lcSQL)
4970
4971 lcSQL = "ALTER TABLE " + lcZzoordrd_update + " ADD SQL_action char(1) default('') not null"
4972 llRetVal = llRetVal And v_SQLExec(lcSQL)
4973
4974 lcSQL = "ALTER TABLE " + lcZzoordrd_update + " add poc_purp char(2) default('') not null"
4975 llRetVal = llRetVal And v_SQLExec(lcSQL)
4976
4977 lcSQL = "ALTER TABLE " + lcZzoordrdv_update + " ADD SQL_action char(1) default('') not null"
4978 llRetVal = llRetVal And v_SQLExec(lcSQL)
4979
4980 lcSQL = "ALTER TABLE " + lcZzoordsp_update + " ADD SQL_action char(1) default('') not null"
4981 llRetVal = llRetVal And v_SQLExec(lcSQL)
4982
4983 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
4984 lcSQL = "SELECT * into " + lczzeipohd_update + " from " + pczzeipohd + " WHERE 1=2"
4985 llRetVal = llRetVal And v_SQLExec(lcSQL)
4986
4987 lcSQL = "ALTER TABLE " + lczzeipohd_update + " ADD SQL_action char(1) default('') not null"
4988 llRetVal = llRetVal And v_SQLExec(lcSQL)
4989 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
4990
4991 pcRefZzoordrh_update = lcZzoordrh_Update
4992 pcRefZzoordrd_update = lcZzoordrd_Update
4993 pcRefZzoordrdv_update = lcZzoordrdv_update
4994 pcRefZzoordsp_update = lcZzoordsp_update
4995
4996 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
4997 pczzeipohd_update = lczzeipohd_update
4998 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
4999
5000 *---?????????????????? Allocation not done!
5001
5002 Select(lnOldSelect)
5003 Return llRetVal
5004
5005 Endproc
5006
5007*-----------------------------------------------------------------------------------------
5008
5009 Procedure FinalValidation(pcZzeipcth,pcZzeipctd,pcRefZzoordrh_orig,pcRefZzoordrd_orig,pcRefZzoordrdv_orig, pcRefZzoordsp_orig)
5010
5011 Local llRetVal, lnOldSelect,lcZzoordrh,lcZzoordrd,lcZzoordrdv,lnThermoCnt
5012
5013 llRetVal = .T.
5014 lnOldSelect = Select()
5015 lcZzoordrh_orig = ""
5016 lcZzoordrd_orig = ""
5017 lcZzoordrdv_orig = ""
5018 lcZzoordsp_orig = ""
5019 lnThermoCnt = 0
5020 this.LogEntry("Final Validations.")
5021 this.InitThermoWithCaption(lnThermoCnt,8,"Final Validations.")
5022
5023 llRetVal = llRetVal And This.GetSalesOrdersToChange(pcZzeipcth, pcZzeipctd, @lcZzoordrh_orig, @lcZzoordrd_orig, @lcZzoordsp_orig)
5024 This.LogEntry("Retreive sales orders to process " + Iif(llRetVal,"completed.","failed."))
5025 this.AdvanceThermoPlus(@lnThermoCnt)
5026
5027 llRetVal = llRetVal And This.SetValue_Ord_num(pcZzeipcth, pcZzeipctd)
5028 This.LogEntry("Set Order number to temporary transaction tables " + Iif(llRetVal,"completed.","failed."))
5029 this.AdvanceThermoPlus(@lnThermoCnt)
5030 *--- set delv_code
5031 *llRetVal = llRetVal and this.SetDelvCodeForQualifierAI(lcZzeipcth, lcZzeipctd, lcZzoordrh_Update, lcZzoordrd_update)
5032
5033 *--- make Sale order vertical zzoordrv
5034 llRetVal = llRetVal And This.GetVerticalOpenOrder(lcZzoordrd_orig,@lcZzoordrdv_orig)
5035 This.LogEntry("Prepare Vertical table to " + Iif(llRetVal,"completed.","failed."))
5036 this.AdvanceThermoPlus(@lnThermoCnt)
5037
5038 *--- 1070659 07-Jun-2013 Bnarayanan update end date for template 'SEARS CANADA 4030' ---
5039 llRetVal = llRetVal and this.UpdateEndDateForSears(pcZzeipcth, lcZzoordrdv_orig)
5040 *=== 1070659 07-Jun-2013 Bnarayanan ===
5041
5042 *--- 1063610 08-Nov-2012 Bnarayanan update total_qty and qty_change for template 'SEARS CANADA 4030' ---
5043 llRetVal = llRetVal and this.PopulateTotalQty(pcZzeipcth, pcZzeipctd, lcZzoordrdv_orig)
5044 *=== 1063610 08-Nov-2012 Bnarayanan ===
5045
5046 *--- TR 1034532 NH
5047 llRetVal = llRetVal and this.SetQtyChangeForQuanityIncreaseDecrease(pcZzeipctd,lcZzoordrdv_orig)
5048 *=== TR 1034532 NH
5049
5050 *--- common validation for all qualifier
5051 llRetVal = llRetVal And This.FirstLevelValidation(pcZzeipcth, pcZzeipctd, lcZzoordrh_orig, lcZzoordrdv_orig)
5052 This.LogEntry("Final validation Step 1 " + Iif(llRetVal,"completed.","failed."))
5053 this.AdvanceThermoPlus(@lnThermoCnt)
5054
5055 llRetVal = llRetVal And This.SecondLevelValidation(pcZzeipcth, pcZzeipctd, lcZzoordrh_orig, lcZzoordrdv_orig,lcZzoordrd_orig)
5056 This.LogEntry("Final validation Step 2 " + Iif(llRetVal,"completed.","failed."))
5057 this.AdvanceThermoPlus(@lnThermoCnt)
5058
5059 llRetVal = llRetVal And This.FlagHeaderForDetailError(pcZzeipcth, pcZzeipctd)
5060 This.LogEntry("Mark transaction header records for detail for error " + Iif(llRetVal,"completed.","failed."))
5061 this.AdvanceThermoPlus(@lnThermoCnt)
5062
5063 *--- TR 1034532 NH
5064 llRetVal = llRetVal and this.MarkHeaderForAutoProcFlag(pcZzeipcth)
5065 this.LogEntry("Mark 860 trans Header for auto process flag " + Iif(llRetVal,"completed.","failed."))
5066 *=== TR 1034532 NH
5067
5068 *--- TechRec 1041233 06-Aug-2009 vkrishnamurthy ---
5069 llRetVal = llRetVal and this.PopulateTerms(pcZzeipcth)
5070 *=== TechRec 1041233 06-Aug-2009 vkrishnamurthy ===
5071
5072 *--- TechRec 1041233 16-Jul-2009 vkrishnamurthy ---
5073 llRetVal = llRetVal and this.ValidateForTermsChange(pcZzeipcth)
5074 this.LogEntry("Validation for Terms Change " + Iif(llRetVal,"completed.","failed."))
5075 *=== TechRec 1041233 16-Jul-2009 vkrishnamurthy ===
5076
5077 llRetVal = llRetVal and This.SetUserIdAndTimeStamp(pcZzeipcth)
5078 llRetVal = llRetVal and This.SetUserIdAndTimeStamp(pcZzeipctd)
5079 *--- At this point all possible errors have been accounted for and so, update 860 transaction
5080
5081 llRetVal = llRetVal And This.Update860TransctionForError(pcZzeipcth, pcZzeipctd)
5082 This.LogEntry("Update 860 transaction for error " + Iif(llRetVal,"completed.","failed."))
5083 this.AdvanceThermoPlus(@lnThermoCnt)
5084
5085 llRetVal = llRetVal And This.DeleteAllRecordsWithErrorFromTempTransTables(pcZzeipcth, pcZzeipctd)
5086 This.LogEntry("Remove error records from 860 change recordset " + Iif(llRetVal,"completed.","failed."))
5087 this.AdvanceThermoPlus(@lnThermoCnt)
5088
5089 pcRefZzoordrh_orig = lcZzoordrh_orig
5090 pcRefZzoordrd_orig = lcZzoordrd_orig
5091 pcRefZzoordrdv_orig = lcZzoordrdv_orig
5092 pcRefZzoordsp_orig = lcZzoordsp_orig
5093 Select(lnOldSelect)
5094 Return llRetVal
5095 Endproc
5096
5097*============================================================
5098
5099 PROCEDURE MarkHeaderForAutoProcFlag(pcZzeipcth)
5100
5101 LOCAL llRetVal, lnOldSelect, lcSql
5102 llRetVal = .t.
5103 lnOldSelect = SELECT()
5104 lcSql = " Update th Set Errs_flg_h = 'Y' , Errs_msg_h = CAST(th.Errs_msg_h as varchar(1000)) " +;
5105 " + '" + EDI_AUTOPROCESS_MSG + "' + char(10) + char(13) " + ;
5106 " From " + pcZzeipcth + " th where auto_proc <> 'Y' and th.Errs_flg_h <> 'Y'"
5107
5108 llRetVal = llRetVal and v_sqlexec(lcSql)
5109
5110 Select(lnOldSelect)
5111 Return llRetVal
5112 Endproc
5113
5114*============================================================
5115
5116 *--- TR 1034532 NH
5117 PROCEDURE SetQtyChangeForQuanityIncreaseDecrease(pcZzeipctd,pcZzoordrdv_orig)
5118
5119 LOCAL llRetVal, lnOldSelect
5120 llRetVal = .t.
5121 lnOldSelect = SELECT()
5122
5123 LOCAL lcAddJoin
5124 IF EMPTY(this.c860SODetailAddMatchCriteria)
5125 lcAddJoin = ""
5126 ELSE
5127 lcAddJoin = " and td.Line_id = od." + this.c860SODetailAddMatchCriteria + " "
5128 ENDIF
5129
5130 *--- TR 1063610 14-Nov-2012 BNarayanan code changed
5131 *lcSql = " UPDATE td set qty_Change = td.total_qty - od.size_qty " + ;
5132 " from " + pcZzeipctd + " td inner join " + pcZzoordrdv_orig + " od " + ;
5133 " on td.ord_num = od.ord_num and td.division = od.division " + ;
5134 " and td.style = od.style and td.color_code = od.color_code " + ;
5135 " and td.lbl_code = od.lbl_code and td.dimension = od.dimension " + ;
5136 lcAddJoin + ;
5137 " where td.qualifier IN ( 'QI', 'QD') and td.qty_change = 0 " + ;
5138 " and td.total_qty > 0 "
5139
5140 lcSql = " UPDATE td set qty_Change = ABS(td.total_qty - coalesce(od.size_qty,0)) " + ;
5141 " from " + pcZzeipctd + " td left join " + pcZzoordrdv_orig + " od " + ;
5142 " on td.ord_num = od.ord_num and td.division = od.division " + ;
5143 " and td.style = od.style and td.color_code = od.color_code " + ;
5144 " and td.lbl_code = od.lbl_code and td.dimension = od.dimension " + ;
5145 " and td.sizebucket = od.sizebucket " + ;
5146 " and od.line_status = 'O' " + ;
5147 lcAddJoin + ;
5148 " where td.qualifier IN ( 'QI', 'QD') and td.qty_change = 0 " + ;
5149 " and td.total_qty > 0 "
5150 *=== TR 1063610 14-Nov-2012 BNarayanan
5151
5152 llRetVal = llRetVal and v_sqlexec(lcSql)
5153
5154 *--- update original zzeipctd table.
5155 lcSql = " update td set qty_change = tmp.qty_change from zzeipctd td inner join " + pcZzeipctd + " tmp " + ;
5156 " on td.pkey = tmp.pkey " + ;
5157 " where td.qualifier IN ( 'QI', 'QD') and td.qty_change = 0 " + ;
5158 " and td.total_qty > 0 and tmp.qty_change > 0 "
5159
5160 llRetVal = llRetVal and v_sqlexec(lcSql)
5161
5162 Select(lnOldSelect)
5163 Return llRetVal
5164 Endproc
5165
5166*============================================================
5167
5168 *--- Please see TR 1028744 documentation for more information
5169 PROCEDURE PrepareForQualifier_DB(pcZzeipcth, pcZzeipctd,pcZzoordrh_Update, pcZzoordrd_Update)
5170
5171 LOCAL llRetVal, lnOldSelect
5172 llRetVal = .t.
5173 lnOldSelect = SELECT()
5174 LOCAL lcAddJoin
5175 IF EMPTY(this.c860SODetailAddMatchCriteria)
5176 lcAddJoin = ""
5177 ELSE
5178 lcAddJoin = " and td.Line_id = od." + this.c860SODetailAddMatchCriteria + " "
5179 ENDIF
5180
5181*!* REPLACE UDFOORDD1C WITH tcEiPCtd.UDFOORDD1C, ;
5182*!* UDFOORDD2C WITH tcEiPCtd.UDFOORDD2C IN Vzzoordrd_860I
5183
5184 lcSql = "Update od SET UDFOORDD1C = td.UDFOORDD1C, UDFOORDD2C = td.UDFOORDD2C from " + pcZzoordrd_Update + " od " + ;
5185 " inner join " + pcZzeipctd + " td on od.ord_num = td.ord_num and od.division = td.division " + ;
5186 " and od.style = td.style and od.color_code = td.color_code and od.lbl_code = td.lbl_code " + ;
5187 " and od.dimension = td.dimension " + lcAddJoin + ;
5188 " where td.qualifier = 'DB' "
5189
5190 llRetVal = llRetVal and v_sqlexec(lcSql)
5191
5192 Select(lnOldSelect)
5193 Return llRetVal
5194 Endproc
5195 *=== TR 1034532 NH
5196
5197*========================================================================
5198
5199 *--- TechRec 1040484 18-Jun-2009 vkrishnamurthy ---
5200 PROCEDURE Get850HDUpdateSQL(pcZzeipohd_Update,pcUpdateSQL_Zzeipohd)
5201
5202 Local llRetVal, lnOldSelect
5203 lnOldSelect = Select()
5204 llRetVal = .T.
5205
5206 LOCAL lcUpdateSQL_Zzeipohd
5207 STORE "" to lcUpdateSQL_Zzeipohd
5208
5209 LOCAL lcUpdateAllFields
5210 lcUpdateAllFields = ""
5211 llRetVal = llRetVal and this.oCopyUtil.GetFldsValuesForUpdate(@lcUpdateAllFields, "Zzeipohd", pcZzeipohd_Update,"","","","uh")
5212 lcUpdateSQL_Zzeipohd = "UPDATE h SET " + lcUpdateAllFields + " FROM Zzeipohd h INNER JOIN " + pcZzeipohd_Update + " uh ON uh.pkey = h.pkey " + ;
5213 " WHERE uh.SQL_action = 'U'"
5214
5215 pcUpdateSQL_Zzeipohd = lcUpdateSQL_Zzeipohd
5216 Select(lnOldSelect)
5217 Return llRetVal
5218
5219 ENDPROC
5220
5221*========================================================================
5222
5223 PROCEDURE PrepareSalesOrderTable_850HDChange(pcZzeipctd,pczzeipohd_update, pcZzoordrd_Update)
5224 &&--- TechRec 1041520 09-Mar-2010 vkrishnamurthy === Added pcZzoordrd_Update
5225
5226 Local llRetVal, lnOldSelect,lcUnique, lcSQL,lnThermoCnt
5227 llRetVal = .T.
5228 lnOldSelect = Select()
5229 lnThermoCnt = 0
5230
5231 LOCAL lcFlds, lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
5232 lcFlds = ""
5233 lcValues = ""
5234 lcExcludeFlds = "'SQL_action'"
5235 lcCalFlds = "SQL_action"
5236 lcCalFldsValues = "'U'" && keep the sign negative for reduction of quantity
5237 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, pczzeipohd_update,"zzeipohd" , lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"oh")
5238
5239 *--- TechRec 1041520 09-Mar-2010 vkrishnamurthy ---
5240 LOCAL lcAddJoin
5241 IF EMPTY(this.c860SODetailAddMatchCriteria)
5242 lcAddJoin = ""
5243 ELSE
5244 lcAddJoin = " and td.Line_id = od." + this.c860SODetailAddMatchCriteria + " "
5245 ENDIF
5246 *=== TechRec 1041520 09-Mar-2010 vkrishnamurthy ===
5247
5248 *--- TechRec 1041520 09-Mar-2010 vkrishnamurthy ---
5249*!* lcSql = " select oh.* from zzeipohd oh " + ;
5250*!* " where " + ;
5251*!* " exists (select th.pkey from " + pcZzeipctd + " th where th.ord_num = oh.ord_num and th.line_seq = oh.line_seq and th.QUALIFIER = 'RZ' and th.edipo4udf1 >0 )"
5252
5253 *--- TR 1050786 23-NOV-2010 HNISAR && included edipo4udf2 > 0 in exists clause
5254*!* lcSql = " select oh.* from zzeipohd oh " + ;
5255*!* " where " + ;
5256*!* " exists (select th.pkey from " + pcZzeipctd + " th where th.ord_num = oh.ord_num and th.QUALIFIER = 'RZ' and th.edipo4udf1 >0 )"
5257
5258 lcSql = " select oh.* from zzeipohd oh " + ;
5259 " where " + ;
5260 " exists (select th.pkey from " + pcZzeipctd + " th where th.ord_num = oh.ord_num and th.QUALIFIER = 'RZ' "+;
5261 " and (th.edipo4udf1 >0 OR th.edipo4udf2 >0 ) )"
5262 *=== TR 1050786 23-NOV-2010 HNISAR
5263
5264 *=== TechRec 1041520 09-Mar-2010 vkrishnamurthy ===
5265
5266 lcSQL = Strtran(lcSQL, "oh.*",lcValues)
5267 lcSQL = "INSERT INTO " + pczzeipohd_update + " ( " + lcFlds + " ) " + lcSQL
5268 llRetVal = llRetVal And v_SQLExec(lcSQL)
5269
5270 *--- TechRec 1041520 09-Mar-2010 vkrishnamurthy ---
5271*!* lcSQL = "Update temp set EDIPO4UDF1 = td.EDIPO4UDF1 FROM " + pczzeipohd_update + " temp Inner JOIN " + ;
5272*!* pcZzeipctd + " td on temp.ord_num = td.ord_num and temp.line_seq = td.line_seq "
5273
5274 *--- TR 1050786 23-NOV-2010 HNISAR && Added edipo4udf2
5275*!* lcSQL = "Update temp set EDIPO4UDF1 = td.EDIPO4UDF1 FROM " + pczzeipohd_update + " temp Inner JOIN " + ;
5276*!* + pcZzoordrd_update + " od On od.ord_num = temp.ord_num and od.line_Seq = temp.line_Seq " + ;
5277*!* " Join " + pcZzeipctd + " td on td.ord_num = od.ord_num and "+ ;
5278*!* " td.QUALIFIER = 'RZ' and td.edipo4udf1 >0 and " + ;
5279*!* " od.style = td.style and od.color_code = td.color_code and "+ ;
5280*!* " od.lbl_code = td.lbl_code " + ;
5281*!* " and od.dimension = td.dimension " + lcAddJoin
5282
5283 *--- TechRec 1052884 06-Jun-2011 asharma ---
5284 * included sizebucket when updating for PO4 fields
5285 *lcSQL = "Update temp set "+;
5286 " EDIPO4UDF1 = CASE WHEN td.EDIPO4UDF1 > 0 THEN td.EDIPO4UDF1 ELSE temp.EDIPO4UDF1 END " +;
5287 ", EDIPO4UDF2 = CASE WHEN td.EDIPO4UDF2 > 0 THEN td.EDIPO4UDF2 ELSE temp.EDIPO4UDF2 END " +;
5288 " FROM " + pczzeipohd_update + " temp Inner JOIN " + ;
5289 + pcZzoordrd_update + " od On od.ord_num = temp.ord_num and od.line_Seq = temp.line_Seq " + ;
5290 " Join " + pcZzeipctd + " td on td.ord_num = od.ord_num and "+ ;
5291 " td.QUALIFIER = 'RZ' and "+;
5292 " ( td.edipo4udf1 >0 OR td.edipo4udf2 >0 ) and " + ;
5293 " od.style = td.style and od.color_code = td.color_code and "+ ;
5294 " od.lbl_code = td.lbl_code " + ;
5295 " and od.dimension = td.dimension " + lcAddJoin
5296
5297 lcSQL = "Update temp set "+;
5298 " EDIPO4UDF1 = CASE WHEN td.EDIPO4UDF1 > 0 THEN td.EDIPO4UDF1 ELSE temp.EDIPO4UDF1 END " +;
5299 ", EDIPO4UDF2 = CASE WHEN td.EDIPO4UDF2 > 0 THEN td.EDIPO4UDF2 ELSE temp.EDIPO4UDF2 END " +;
5300 " FROM " + pczzeipohd_update + " temp Inner JOIN " + ;
5301 + pcZzoordrd_update + " od On od.ord_num = temp.ord_num and od.line_Seq = temp.line_Seq " + ;
5302 " Join " + pcZzeipctd + " td on td.ord_num = od.ord_num and "+ ;
5303 " td.QUALIFIER = 'RZ' and "+;
5304 " ( td.edipo4udf1 >0 OR td.edipo4udf2 >0 ) and " + ;
5305 " od.style = td.style and od.color_code = td.color_code and "+ ;
5306 " od.lbl_code = td.lbl_code " + ;
5307 " and od.dimension = td.dimension " + ;
5308 " and temp.sizebucket = td.sizebucket " + lcAddJoin
5309 *=== TechRec 1052884 06-Jun-2011 asharma ===
5310
5311 *=== TechRec 1041520 09-Mar-2010 vkrishnamurthy ===
5312
5313 llRetVal = llRetVal And v_SQLExec(lcSQL)
5314
5315 Select(lnOldSelect)
5316 Return llRetVal
5317
5318 ENDPROC
5319 *=== TechRec 1040484 18-Jun-2009 vkrishnamurthy ===
5320
5321*========================================================================
5322
5323 *--- TechRec 1041233 16-Jul-2009 vkrishnamurthy ---
5324 FUNCTION PrepareSalesOrderTable_TermsChange
5325 LPARAMETERS pcZzeipcth,pcZzoordrh_Update
5326 LOCAL llRetVal, lnSelect , lcSQLString
5327
5328 *--- TR 1072834 20-Aug-2013 Goutam
5329 LOCAL lcWarnCondition
5330 *=== TR 1072834 20-Aug-2013 Goutam
5331
5332 llRetVal = true
5333 lnSelect = SELECT()
5334
5335 *--- TR 1072834 20-Aug-2013 Goutam
5336 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
5337 *=== TR 1072834 20-Aug-2013 Goutam
5338
5339 WITH This
5340 *--- TR 1048865 17-Mar-2011 Goutam.
5341
5342 *lcSQLString = " UPDATE oh SET Terms = ct.Terms " + ;
5343 " FROM " + pcZzoordrh_update + " oh " + ;
5344 " JOIN " + pcZzeipcth + " th " + ;
5345 " ON oh.ord_num = th.ord_num " + ;
5346 " JOIN zzectrmx ct " + ;
5347 " ON th.itd_tmtype = ct.itd_tmtype "+ ;
5348 " AND th.itd_duedays = ct.itd_duedays " + ;
5349 " AND th.itd_discpct = ct.itd_discpct " + ;
5350 " AND th.itd_discdays = ct.itd_discdays "+ ;
5351 " AND th.itd_basis = ct.itd_basis " + ;
5352 " AND direction IN ('I','B') " + ;
5353 " JOIN zzeipccr cr " + ;
5354 " ON oh.customer = cr.customer "+;
5355 " AND oh.division = cr.division and cr.active_ok = 'Y' "+;
5356 " WHERE (th.itd_tmtype<> '' OR th.itd_basis <> '') " + ;
5357 " AND th.Errs_flg_h <> 'Y' "
5358
5359 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
5360 lcSQLString = " UPDATE oh SET Terms = ct.Terms " + ;
5361 " FROM " + pcZzoordrh_update + " oh " + ;
5362 " JOIN " + pcZzeipcth + " th " + ;
5363 " ON oh.ord_num = th.ord_num " + ;
5364 " JOIN zzectrmx ct " + ;
5365 " ON th.itd_tmtype = ct.itd_tmtype "+ ;
5366 " AND th.itd_duedays = ct.itd_duedays " + ;
5367 " AND th.itd_discpct = ct.itd_discpct " + ;
5368 " AND th.itd_discdays = ct.itd_discdays "+ ;
5369 " AND th.itd_basis = ct.itd_basis " + ;
5370 " AND direction IN ('I','B') " + ;
5371 " JOIN zzeipccr cr " + ;
5372 " ON cr.pkey = th.cr_pkey " + ;
5373 " AND cr.active_ok = 'Y' "+;
5374 " WHERE (th.itd_tmtype<> '' OR th.itd_basis <> '') " + ;
5375 " AND th.Errs_flg_h <> 'Y' " + lcWarnCondition
5376
5377 llRetVal = llRetVal and v_sqlexec(lcSQLString)
5378
5379 ENDWITH
5380
5381 SELECT (lnSelect)
5382 RETURN llRetVal
5383 ENDFUNC
5384
5385*============================================================
5386
5387 FUNCTION ValidateForTermsChange
5388 LPARAMETERS pcZzeipcth
5389 LOCAL llRetVal, lnSelect,lcSQLString
5390
5391 llRetVal = true
5392 lnSelect = SELECT()
5393
5394 WITH This
5395
5396 *-- TR 1051181 17-Dec-2010 RKI ---*
5397 *Commented to Restrict Error message when Term_deft='S'
5398*!* lcSQLString = " Update th Set Errs_flg_h = 'Y' " + ;
5399*!* " , Errs_msg_h = CAST(th.Errs_msg_h as varchar(1000)) " +;
5400*!* " + 'Terms are not updated because 850(i) process uses System Terms'+ char(10) + char(13) " + ;
5401*!* " From " + pcZzeipcth + " th "+ ;
5402*!* " JOIN ZZEIPOCR C " + ;
5403*!* " ON C.division = th.division " + ;
5404*!* " AND c.Customer = th.customer " + ;
5405*!* " AND c.term_deft = 'S' " + ;
5406*!* " WHERE (th.itd_tmtype <> '' OR th.itd_basis <> '') " && --- TR 1042155 18-Aug-2009 Surinder ===
5407*!*
5408*!* llRetVal = llRetVal and v_sqlexec(lcSQLString)
5409
5410 *-- TR 1051181 17-Dec-2010 RKI ---*
5411 * Join condition for ZZEIPOCR added.
5412
5413 lcSQLString = " UPDATE th set Errs_flg_h = 'Y' " + ;
5414 " , Errs_msg_h = CAST(th.Errs_msg_h as varchar(1000)) " +;
5415 " + 'Terms Could not be resolved'+ char(10) + char(13) " + ;
5416 " FROM " + pcZzeipcth + " th " + ;
5417 " LEFT JOIN zzectrmx ct " + ;
5418 " ON th.itd_tmtype = ct.itd_tmtype "+ ;
5419 " AND th.itd_duedays = ct.itd_duedays " + ;
5420 " AND th.itd_discpct = ct.itd_discpct " + ;
5421 " AND th.itd_discdays = ct.itd_discdays "+ ;
5422 " AND th.itd_basis = ct.itd_basis " + ;
5423 " AND direction IN ('I','B') " + ;
5424 " JOIN ZZEIPOCR C " + ;
5425 " ON C.division = th.division " + ;
5426 " AND c.Customer = th.customer " + ;
5427 " AND c.term_deft <> 'S' " + ;
5428 " WHERE (th.itd_tmtype<> '' OR th.itd_basis <> '') " + ;
5429 " AND ct.pkey is NULL "
5430
5431 llRetVal = llRetVal and v_sqlexec(lcSQLString)
5432 ENDWITH
5433
5434 SELECT (lnSelect)
5435 RETURN llRetVal
5436 ENDFUNC
5437
5438*============================================================
5439
5440 FUNCTION PopulateTerms
5441 LPARAMETERS pcZzeipcth
5442 LOCAL llRetVal, lnSelect ,lcSQLString
5443
5444 llRetVal = true
5445 lnSelect = SELECT()
5446
5447 WITH This
5448
5449 *-- TR 1051181 17-Dec-2010 RKI ---*
5450 * Join condition for ZZEIPOCR added.
5451 *--- TR 1048865 17-Mar-2011 Goutam.
5452 *lcSQLString = " UPDATE th SET Terms = COALESCE(ct.Terms, '') " + ;
5453 " FROM " + pcZzeipcth + " th " + ;
5454 " LEFT JOIN zzectrmx ct " + ;
5455 " ON th.itd_tmtype = ct.itd_tmtype "+ ;
5456 " AND th.itd_duedays = ct.itd_duedays " + ;
5457 " AND th.itd_discpct = ct.itd_discpct " + ;
5458 " AND th.itd_discdays = ct.itd_discdays "+ ;
5459 " AND th.itd_basis = ct.itd_basis " + ;
5460 " AND direction IN ('I','B') " + ;
5461 " JOIN zzeipccr cr " + ;
5462 " ON th.customer = cr.customer "+;
5463 " AND th.division = cr.division and cr.active_ok = 'Y' "+;
5464 " JOIN ZZEIPOCR C " + ;
5465 " ON C.division = th.division " + ;
5466 " AND c.Customer = th.customer " + ;
5467 " AND c.term_deft <> 'S' " + ;
5468 " WHERE (th.itd_tmtype<> '' OR th.itd_basis <> '') "
5469
5470 lcSQLString = " UPDATE th SET Terms = COALESCE(ct.Terms, '') " + ;
5471 " FROM " + pcZzeipcth + " th " + ;
5472 " LEFT JOIN zzectrmx ct " + ;
5473 " ON th.itd_tmtype = ct.itd_tmtype "+ ;
5474 " AND th.itd_duedays = ct.itd_duedays " + ;
5475 " AND th.itd_discpct = ct.itd_discpct " + ;
5476 " AND th.itd_discdays = ct.itd_discdays "+ ;
5477 " AND th.itd_basis = ct.itd_basis " + ;
5478 " AND direction IN ('I','B') " + ;
5479 " JOIN zzeipccr cr " + ;
5480 " ON th.cr_pkey = cr.pkey "+;
5481 " AND cr.active_ok = 'Y' "+;
5482 " JOIN ZZEIPOCR C " + ;
5483 " ON C.division = th.division " + ;
5484 " AND c.Customer = th.customer " + ;
5485 " AND c.term_deft <> 'S' " + ;
5486 " WHERE (th.itd_tmtype<> '' OR th.itd_basis <> '') "
5487
5488 *=== TR 1048865 17-Mar-2011 Goutam.
5489
5490 llRetVal = llRetVal and v_sqlexec(lcSQLString)
5491
5492 ENDWITH
5493
5494 SELECT (lnSelect)
5495 RETURN llRetVal
5496 ENDFUNC
5497 *=== TechRec 1041233 15-Jul-2009 vkrishnamurthy ===
5498
5499*-----------------------------------------------------------------------------------------
5500
5501 *--- TR 1036847 DEC-09-2008 BR
5502 PROCEDURE CascadeHeaderFields(pcZzoordrh_Update,pcZzoordrd_update)
5503
5504 LOCAL llRetVal, lnOldSelect,lcSQL
5505 llRetVal = .T.
5506 lnOldSelect = SELECT()
5507
5508 lcSQL = "UPDATE d SET customer_cascaded = h.customer, conf_type_cascaded = h.conf_type, slsperson1_cascaded = h.slsperson1, " + ;
5509 " d.tax_empt = h.tax_empt, terms_cascaded = h.terms FROM " + pcZzoordrd_update + " d " +;
5510 " INNER JOIN " + pcZzoordrh_Update + " h on d.fkey = h.pkey where d.SQL_ACTION = 'I' "
5511
5512 llRetVal = llRetVal and v_sqlexec(lcSQL)
5513
5514 Select(lnOldSelect)
5515 Return llRetVal
5516
5517 ENDPROC
5518 *=== TR 1036847 DEC-09-2008 BR
5519
5520*============================================================
5521
5522 * --- TR 1047609 7/7/10 CM
5523 PROCEDURE CreateSLNHistoryTable(pcZzeipcth, pcZzeipctd, pcZzeipchs)
5524 LOCAL llRetVal, lnOldSelect, lcSQL, lcUnique
5525 llRetVal = .T.
5526 lnOldSelect = SELECT()
5527 lcUnique = SYS(2015)
5528 lcSLNHistory = "#Zzeipchs" + lcUnique
5529
5530 * --- Inserting into temp history table
5531 lcSQL = "SELECT s.* INTO " + lcSLNHistory + " FROM zzeipcts s " + ;
5532 " JOIN " + This.cTmpSLNTable + " t ON s.pkey = t.pkey "
5533
5534 llRetVal = llRetVal and v_sqlexec(lcSQL)
5535
5536 * --- Deleting SLNs from Transaction
5537 lcSQL = "DELETE s " + ;
5538 "FROM zzeipcts s " + ;
5539 " JOIN " + This.cTmpSLNTable + " t ON s.pkey = t.pkey "
5540
5541 llRetVal = llRetVal and v_sqlexec(lcSQL)
5542
5543 llRetVal = llRetVal and v_sqlexec("DROP TABLE " + This.cTmpSLNTable)
5544
5545 pcZzeipchs = lcSLNHistory
5546
5547 SELECT(lnOldSelect)
5548 RETURN llRetVal
5549
5550 ENDPROC
5551
5552 PROCEDURE GetSLNHistInsertSQL(pcZzeipchs_Insert,pcInsertSQL_Zzeipchs)
5553
5554 LOCAL llRetVal, lnOldSelect, lcInsertSQL_Zzeipchs
5555 lnOldSelect = SELECT()
5556 llRetVal = .T.
5557 lcInsertSQL_Zzeipchs = ""
5558
5559 LOCAL lcFlds, lcValues, lcExcludeFlds, lcCalFlds, lcCalFldsValues
5560 lcFlds = ""
5561 lcValues = ""
5562 lcExcludeFlds = ""
5563 lcCalFlds = ""
5564 lcCalFldsValues = ""
5565
5566 *--- SLN History insert
5567 IF !EMPTY(pcZzeipchs_Insert)
5568 llRetVal = llRetVal And This.oCopyUtil.GetFldsValues(@lcFlds, @lcValues, "zzeipchs", pcZzeipchs_Insert, ;
5569 lcExcludeFlds,lcCalFlds,lcCalFldsValues,.f.,"s.")
5570
5571 lcInsertSQL_Zzeipchs = " INSERT INTO zzeipchs (" + lcFlds + " ) SELECT " + lcValues + " FROM " + pcZzeipchs_Insert + " s "
5572
5573 pcInsertSQL_Zzeipchs = lcInsertSQL_Zzeipchs
5574 ENDIF
5575
5576 SELECT(lnOldSelect)
5577 RETURN llRetVal
5578
5579 ENDPROC
5580 * === TR 1047609 7/7/10 CM
5581
5582*============================================================
5583
5584 *-----------------------------------------------------------------------------------------
5585 *--- TR 1058034 22-Nov-2011 Goutam
5586 PROCEDURE SetPriceCode(pcZzoordrh_update, pcZzeipcth)
5587
5588 Local llRetVal, lnOldSelect, lcSQL
5589
5590
5591 *--- TR 1072834 20-Aug-2013 Goutam
5592 LOCAL lcWarnCondition
5593 *=== TR 1072834 20-Aug-2013 Goutam
5594
5595 llRetVal = .T.
5596 lnOldSelect = Select()
5597
5598 *--- TR 1072834 20-Aug-2013 Goutam
5599 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
5600 *=== TR 1072834 20-Aug-2013 Goutam
5601
5602 *--- UPDATE PRICE CODE ACROSS ALL qualifier
5603 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
5604 lcSQL = " UPDATE oh SET price_code = th.price_code " + ;
5605 " FROM " + pcZzoordrh_update + " oh " + ;
5606 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5607 " WHERE oh.ord_status = 'O' and th.Errs_flg_h <> 'Y' " + lcWarnCondition + " and th.price_code > ''"
5608
5609 llRetVal = llRetVal and v_sqlexec(lcSQL)
5610
5611 Select(lnOldSelect)
5612 Return llRetVal
5613
5614 Endproc
5615 *=== TR 1058034 22-Nov-2011 Goutam
5616 *-----------------------------------------------------------------------------------------
5617
5618 *--- TR 1062197 7-Sep-2012 Goutam
5619 PROCEDURE SetPOCStore
5620 LPARAMETERS pcZzoordrh_update, pcZzeipcth
5621
5622 Local llRetVal, lnOldSelect, lcSQL
5623
5624 *--- TR 1072834 20-Aug-2013 Goutam
5625 LOCAL lcWarnCondition
5626 *=== TR 1072834 20-Aug-2013 Goutam
5627
5628 llRetVal = .T.
5629 lnOldSelect = Select()
5630
5631 *--- TR 1072834 20-Aug-2013 Goutam
5632 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
5633 *=== TR 1072834 20-Aug-2013 Goutam
5634
5635 *--- UPDATE Store code based on POC Store for poc_purp = '04'
5636 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
5637 lcSQL = " UPDATE oh SET store = th.edi_store " + ;
5638 " FROM " + pcZzoordrh_update + " oh " + ;
5639 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5640 " WHERE oh.ord_status = 'O' and th.Errs_flg_h <> 'Y' " + lcWarnCondition + " and th.poc_purp = '04' and th.poc_store > ''"
5641
5642 llRetVal = llRetVal and v_sqlexec(lcSQL)
5643
5644 Select(lnOldSelect)
5645 Return llRetVal
5646
5647 ENDPROC
5648
5649 PROCEDURE SetConsolidatorNCentercode
5650 LPARAMETERS pcZzoordrh_update, pcZzeipcth
5651
5652 Local llRetVal, lnOldSelect, lcSQL
5653
5654 *--- TR 1072834 20-Aug-2013 Goutam
5655 LOCAL lcWarnCondition
5656 *=== TR 1072834 20-Aug-2013 Goutam
5657
5658 llRetVal = .T.
5659 lnOldSelect = Select()
5660
5661 *--- TR 1072834 20-Aug-2013 Goutam
5662 lcWarnCondition = " and (th.warn_flg_h <> 'Y' or (th.warn_flg_h = 'Y' and th.ignore_warn = 'Y'))"
5663 *=== TR 1072834 20-Aug-2013 Goutam
5664
5665 *--- UPDATE consol_code based on POC Shipto for poc_purp = '04'
5666 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
5667 lcSQL = " UPDATE oh SET consol_code = th.poc_shipto, ship_dc = 'B' " + ;
5668 " FROM " + pcZzoordrh_update + " oh " + ;
5669 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5670 " WHERE oh.ord_status = 'O' and th.Errs_flg_h <> 'Y' " + lcWarnCondition + " and th.poc_purp = '04' and th.poc_shipto > ''"
5671
5672 llRetVal = llRetVal and v_sqlexec(lcSQL)
5673
5674 *--- TR 1072834 20-Aug-2013 Goutam. Added lcWarnCondition
5675 lcSQL = " UPDATE oh SET center_code = th.center_code, ship_dc = 'D' " + ;
5676 " FROM " + pcZzoordrh_update + " oh " + ;
5677 " INNER JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5678 " WHERE oh.ord_status = 'O' and th.Errs_flg_h <> 'Y' " + lcWarnCondition + " and th.poc_purp = '04' and th.center_code > '' and th.poc_shipto = ''"
5679
5680 llRetVal = llRetVal and v_sqlexec(lcSQL)
5681
5682 Select(lnOldSelect)
5683 Return llRetVal
5684
5685 Endproc
5686
5687 *=== TR 1062197 7-Sep-2012 Goutam
5688 *-----------------------------------------------------------------------------------------
5689
5690*========================================================================
5691
5692 *--- TR 1059173 20-Feb-2012 Partha ---
5693 FUNCTION PrepareSalesOrderTable_BillToChange
5694 LPARAMETERS pcZzeipcth,pcZzoordrh_Update
5695 LOCAL llRetVal, lnSelect , lcSQLString
5696 llRetVal = true
5697 lnSelect = SELECT()
5698
5699 WITH This
5700
5701 *--- TR 1062197 7-Sep-2012 Goutam
5702 *lcSQLString = +;
5703 " UPDATE oh SET edibill_to= th.edibill_to " + ;
5704 " FROM " + pcZzoordrh_update + " oh " + ;
5705 " JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5706 " WHERE th.poc_purp = '04' and th.edibill_to > '' "
5707
5708 lcSQLString = +;
5709 " UPDATE oh SET edibill_to = Case When th.edibill_to > '' then th.edibill_to else th.poc_billto end " + ;
5710 " FROM " + pcZzoordrh_update + " oh " + ;
5711 " JOIN " + pcZzeipcth + " th ON oh.ord_num = th.ord_num " + ;
5712 " WHERE th.poc_purp = '04' and (th.edibill_to > '' or th.poc_billto > '')"
5713
5714 *=== TR 1062197 7-Sep-2012 Goutam
5715
5716 llRetVal = llRetVal and v_sqlexec(lcSQLString)
5717
5718 ENDWITH
5719
5720 SELECT (lnSelect)
5721 RETURN llRetVal
5722 ENDFUNC
5723 *=== TR 1059173 20-Feb-2012 Partha ===
5724
5725*============================================================
5726 *--- 1063610 12-Nov-2012 Bnarayanan ---
5727 PROCEDURE PopulateTotalQty(pcZzeipcth, pcZzeipctd,pcZzoordrdv_orig)
5728
5729 LOCAL llRetVal, lnOldSelect
5730 llRetVal = .t.
5731 lnOldSelect = SELECT()
5732
5733 LOCAL lcAddJoin
5734 IF EMPTY(this.c860SODetailAddMatchCriteria)
5735 lcAddJoin = ""
5736 ELSE
5737 lcAddJoin = " and td.Line_id = od." + this.c860SODetailAddMatchCriteria + " "
5738 ENDIF
5739
5740 *--- TR 1073894 28-Oct-2013 Goutam. Added or cr.template = 'NEIMAN MARCUS' in where clause.
5741 lcSql = " UPDATE td set qualifier = 'DI' " + ;
5742 " from " + pcZzeipctd + " td inner join " + pcZzoordrdv_orig + " od " + ;
5743 " on td.ord_num = od.ord_num and td.division = od.division " + ;
5744 " and td.style = od.style and td.color_code = od.color_code " + ;
5745 " and td.lbl_code = od.lbl_code and td.dimension = od.dimension " + ;
5746 lcAddJoin + ;
5747 " join " + pcZzeipcth + " h on h.pkey = td.fkey " + ;
5748 " join zzeipccr cr on cr.pkey = h.cr_pkey " + ;
5749 " where td.qualifier = 'QD' and td.qty_Change = 0 and (cr.template = 'SEARS CANADA 4030' or cr.template = 'NEIMAN MARCUS')"
5750
5751 llRetVal = llRetVal and v_sqlexec(lcSql)
5752
5753 *--- TR 1073894 28-Oct-2013 Goutam. Added or cr.template = 'NEIMAN MARCUS' in where clause.
5754 lcSql = " UPDATE td set total_qty = qty_change, qty_change = 0 " + ;
5755 " from " + pcZzeipctd + " td inner join " + pcZzoordrdv_orig + " od " + ;
5756 " on td.ord_num = od.ord_num and td.division = od.division " + ;
5757 " and td.style = od.style and td.color_code = od.color_code " + ;
5758 " and td.lbl_code = od.lbl_code and td.dimension = od.dimension " + ;
5759 lcAddJoin + ;
5760 " join " + pcZzeipcth + " h on h.pkey = td.fkey " + ;
5761 " join zzeipccr cr on cr.pkey = h.cr_pkey " + ;
5762 " where td.qualifier IN ( 'QI', 'QD') and td.qty_Change <> 0 and (cr.template = 'SEARS CANADA 4030' or cr.template = 'NEIMAN MARCUS')"
5763
5764 llRetVal = llRetVal and v_sqlexec(lcSql)
5765
5766 Select(lnOldSelect)
5767 Return llRetVal
5768 ENDPROC
5769 *=== 1063610 12-Nov-2012 Bnarayanan ===
5770
5771 *--- TR 1070419 16-Apr-2013 Goutam
5772 FUNCTION GetSOFieldListWithoutUDF
5773 LPARAMETERS tcAlias, tcSource
5774 LOCAL llRetVal, lnSelect, lcSQLString, lcCursor, lcSourceFieldList, laSourceColumn[1], lcColumn, lnRow, lcSOFieldListWithoutUDF
5775
5776 lcSOFieldListWithoutUDF = ""
5777 llRetVal = true
5778 lnSelect = SELECT()
5779 lcCursor = GetUniqueFileName()
5780
5781 WITH This
5782 *--- TechRec 1073591 04-Mar-2014 TShenbagavalli to avoid too many columns error ---
5783*!* lcSQLString = " Select * from " + tcSource + " where 1=2 "
5784*!* llRetVal = .vSqlExec(lcSQLString,lcCursor)
5785*!* IF llRetVal
5786*!* *lcSourceFieldList = CreateFieldListFromCursor(lcCursor)
5787*!*
5788*!* ParseArr(@laSourceColumn, lcSourceFieldList, 1, ",")
5789*!*
5790*!* FOR I = 1 TO ALEN(laSourceColumn, 1)
5791*!* lcColumn = laSourceColumn[I]
5792*!* IF !(LEFT(lcColumn, 6) = "UDFORD")
5793*!* lcSOFieldListWithoutUDF = lcSOFieldListWithoutUDF + IIF(!EMPTY(lcSOFieldListWithoutUDF) ,",","")+ tcAlias + lcColumn
5794*!* ENDIF
5795*!* ENDFOR
5796*!* ENDIF
5797
5798 llRetVal = v_SQLColumns(tcSource, lcCursor)
5799
5800 SELECT (lcCursor)
5801 SCAN
5802 lcColumn = alltrim(column_name)
5803 IF !(LEFT(lcColumn, 6) = "UDFORD")
5804 lcSOFieldListWithoutUDF = lcSOFieldListWithoutUDF + IIF(!EMPTY(lcSOFieldListWithoutUDF),",","")+ tcAlias + lcColumn
5805 ENDIF
5806
5807 ENDSCAN
5808 *=== TechRec 1073591 04-Mar-2014 TShenbagavalli ===
5809 .TableClose(lcCursor)
5810 ENDWITH
5811
5812 SELECT (lnSelect)
5813 RETURN lcSOFieldListWithoutUDF
5814 ENDFUNC
5815 *=== TR 1070419 16-Apr-2013 Goutam
5816
5817 *--- TR 1066871 13-May-2013 Goutam
5818 PROCEDURE GetNoErrorRecordInCursor
5819 LPARAMETERS pcZzeipcth
5820
5821 Local llRetVal, lnOldSelect, lcSql
5822 lnOldSelect = Select()
5823 llRetVal = .T.
5824
5825 lcSql = "Select h.* from zzeipcth h inner join " + pcZzeipcth + " th on h.pkey = th.pkey where th.proc_850 = 'Y'"
5826 llRetVal = v_SqlExec(lcSql, this.oMainProcess.cNoErrorCursor)
5827
5828 Select(lnOldSelect)
5829 Return llRetVal
5830 Endproc
5831 *=== TR 1066871 13-May-2013 Goutam
5832
5833*============================================================
5834 *--- 1070659 07-Jun-2013 Bnarayanan ---
5835 PROCEDURE UpdateEndDateForSears(pcZzeipcth, pcZzoordrdv_orig)
5836
5837 LOCAL llRetVal, lnOldSelect
5838 llRetVal = .t.
5839 lnOldSelect = SELECT()
5840
5841 lcSQL = " UPDATE h set h.end_date = h.start_date + DATEDIFF(day,oh.start_date,oh.end_date) " + ;
5842 " from " + pcZzeipcth + " h join " + lcZzoordrh_orig + ;
5843 " oh on oh.po_num = h.po_num and oh.customer = h.customer " + ;
5844 " and h.store = case when h.poc_purp = '04' and h.poc_store > '' then h.store else oh.store end and oh.division = h.division " + ;
5845 " join zzeipccr cr on cr.pkey = h.cr_pkey " + ;
5846 " where h.start_date <> oh.start_date and oh.ord_status <> 'C' AND " + ;
5847 " cr.template = 'SEARS CANADA 4030' "
5848
5849 llRetVal = llRetVal and v_sqlexec(lcSql)
5850
5851 Select(lnOldSelect)
5852 Return llRetVal
5853 ENDPROC
5854 *=== 1070659 07-Jun-2013 Bnarayanan ===
5855
5856*--- TechRec 1085945 28-May-2015 vkrishnamurthy ---
5857*============================================================
5858 Procedure CreateBulkNibblerTempTables
5859
5860 Local llRetVal, lcUnique, lcSql
5861 llRetVal = .T.
5862 lcUnique = Sys(2015)
5863 With This
5864 .cZzxniblr = "#zzxniblr" + lcUnique
5865 .cZzoordwh = "#zzoordwh" + lcUnique
5866 .cZzoordwd = "#zzoordwd" + lcUnique
5867
5868 lcSql = "select *, pkey as zzoordrh_pkey, 0 as NibBatchNum into " + .cZzxniblr + " from zzxniblr where 1=2"
5869 llRetVal = llRetVal And v_sqlexec(lcSql)
5870 .RegisterTable(.cZzxniblr)
5871
5872 lcSql = "Alter Table " + .cZzxniblr + " add pkey_I int identity(1,1) "
5873 llRetVal = llRetVal And v_sqlexec(lcSql)
5874
5875 lcSql = "select *, pkey as zzoordrh_pkey, 0 as NibBatchNum into " + .cZzoordwh + " from zzoordwh where 1=2"
5876 llRetVal = llRetVal And v_sqlexec(lcSql)
5877 .RegisterTable(.cZzoordwh)
5878
5879
5880 lcSql = "select *, pkey as zzoordrh_pkey, pkey as zzoordrd_pkey, pkey as zzoordwh_pkey, 0 as NibBatchNum into " +;
5881 .cZzoordwd + " from zzoordwd where 1=2"
5882 llRetVal = llRetVal And v_sqlexec(lcSql)
5883 .RegisterTable(.cZzoordwd)
5884 ENDWITH
5885
5886 Return llRetVal
5887
5888 ENDPROC
5889 *============================================================
5890
5891 PROCEDURE RegisterTable
5892 LPARAMETERS tcTable
5893
5894 IF NOT USED("curTabDrop")
5895 CREATE CURSOR curTabDrop (tabname CHAR(100))
5896 ENDIF
5897
5898 IF USED("curTabDrop") AND NOT EMPTY(tcTable)
5899 INSERT INTO curTabDrop VALUES (tcTable)
5900 ENDIF
5901
5902 ENDPROC
5903*============================================================
5904 Procedure PopulateNibblerRecord
5905 Lparameters tcModule,tcTrx_type,tcTrx_mode
5906
5907 Local llRetVal, lcSql, lcExcludeFlds, lcCalFlds, lcCalFldsValues, llSkipExistsCheck, lcSrcAlias, lcDesAlias
5908 Local lcModule,lcTrx_type,lcTrx_mode
5909 llRetVal = .T.
5910 lcSql = ""
5911 lcModule = "'" + Upper(Alltrim(tcModule)) + "'"
5912 lcTrx_type = "'" + Upper(Alltrim(tcTrx_type)) + "'"
5913 lcTrx_mode = "'" + Upper(Alltrim(tcTrx_mode)) + "'"
5914 lcExcludeFlds = "'PKEY_I','Module','TRX_TYPE','TRX_MODE','TRX_NUM','TRX_USER','TRX_TIME','TRX_PROC','ZZOORDRH_PKEY','NibBatchNum'"
5915 lcCalFlds = "Module,TRX_TYPE,TRX_MODE,TRX_NUM,TRX_USER,TRX_TIME,TRX_PROC,ZZOORDRH_PKEY, NibBatchNum"
5916 lcCalFldsValues = lcModule + "," + lcTrx_type + "," + lcTrx_mode + ",s.pkey,s.user_id,s.last_mod,'N',s.pkey," + TRANSFORM(this.NibBatchNum)
5917
5918 llRetVal = llRetVal And This.oCopyUtil.GetInsertSql(@lcSql, This.cOrdHdrold, This.cZzxniblr, lcExcludeFlds, lcCalFlds, lcCalFldsValues,.T.,'S','D')
5919 llRetVal = llRetVal And v_sqlexec(lcSql)
5920
5921 lcSql = "Update h Set Trx_num = h.pkey_I from " + This.cZzxniblr + " h "
5922 llRetVal = llRetVal And v_sqlexec(lcSql)
5923
5924 Return llRetVal
5925
5926 Endproc
5927 *---------------------------------------------------------------------------------
5928
5929 Procedure PopulateBulkHeaderRecord
5930 Lparameters tcNew_old
5931
5932 Local llRetVal, lcSql, lcExcludeFlds, lcCalFlds, lcCalFldsValues, llSkipExistsCheck, lcSrcAlias, lcDesAlias ,lcSource
5933
5934 llRetVal = .T.
5935
5936 lcSource = IIF(tcNew_old = 'N',This.cOrdHdrNew,This.cOrdHdrOld)
5937
5938 lcSql = ""
5939 lcNew_old = "'" + Upper(Alltrim(tcNew_old)) + "'"
5940 lcExcludeFlds = "'pkey_I','zzoordrh_pkey','NEW_OLD','NibBatchNum','trx_pkey'"
5941 lcCalFlds = "zzoordrh_pkey,NEW_OLD,NibBatchNum"
5942 lcCalFldsValues = "s.pkey," + lcNew_old + "," + TRANSFORM(this.NibBatchNum)
5943
5944 llRetVal = llRetVal And This.oCopyUtil.GetInsertSql(@lcSql, lcSource , This.cZzoordwh, lcExcludeFlds, lcCalFlds, lcCalFldsValues,.T.,'S','D')
5945 llRetVal = llRetVal And v_sqlexec(lcSql)
5946
5947 *--- get Trx_num from zzxniblr
5948*!* lcSql = "Update h Set Trx_num = n.Trx_num from " + This.cZzoordwh + " h inner join " + ;
5949*!* this.cZzxniblr + " n on n.zzoordrh_pkey = h.zzoordrh_pkey and n.NibBatchNum = h.NibBatchNum "
5950 lcSql = " Update h Set Trx_num = n.Trx_num from " + This.cZzoordwh + " h inner join " + ;
5951 this.cZzxniblr + " n on "+ ;
5952 " n.zzoordrh_pkey = case when n.zzoordrh_pkey <>h.zzoordrh_pkey and h.cncl_num > 0 then n.zzoordrh_pkey "+ ;
5953 " else h.zzoordrh_pkey end "+ ;
5954 " and n.NibBatchNum = h.NibBatchNum "
5955
5956 llRetVal = llRetVal And v_sqlexec(lcSql)
5957
5958 Return llRetVal
5959
5960 Endproc
5961
5962 *---------------------------------------------------------------------------------
5963
5964 Procedure PopulateBulkDetailRecord
5965 Lparameters tcNew_old
5966
5967 Local llRetVal, lcSql, lcExcludeFlds, lcCalFlds, lcCalFldsValues, llSkipExistsCheck, lcSrcAlias, lcDesAlias ,lcSource
5968 llRetVal = .T.
5969
5970 lcSource = IIF(tcNew_old = 'N',This.cOrdDtlNew,This.cOrdDtlOld)
5971
5972 lcSql = ""
5973 lcNew_old = "'" + Upper(Alltrim(tcNew_old)) + "'"
5974 lcExcludeFlds = "'pkey_I','zzoordrh_pkey','zzoordrd_pkey','NEW_OLD','NibBatchNum','trx_pkey'"
5975 lcCalFlds = "zzoordrh_pkey,zzoordrd_pkey,NEW_OLD,NibBatchNum"
5976 lcCalFldsValues = "s.fkey,s.pkey," + lcNew_old + "," + TRANSFORM(this.NibBatchNum)
5977
5978 llRetVal = llRetVal And This.oCopyUtil.GetInsertSql(@lcSql, lcSource , This.cZzoordwd, lcExcludeFlds, lcCalFlds, lcCalFldsValues,.T.,'S','D')
5979 llRetVal = llRetVal And v_sqlexec(lcSql)
5980
5981 *--- get Trx_num from zzxniblr
5982 lcSql = " Update d Set Trx_num = n.Trx_num from " + This.cZzoordwd + " d inner join " + ;
5983 this.cZzxniblr + " n on "+ ;
5984 " n.zzoordrh_pkey = case when n.zzoordrh_pkey <>d.zzoordrh_pkey and d.line_status = 'C' then n.zzoordrh_pkey "+ ;
5985 " else d.zzoordrh_pkey end "+ ;
5986 " and n.NibBatchNum = d.NibBatchNum "
5987 llRetVal = llRetVal And v_sqlexec(lcSql)
5988
5989 Return llRetVal
5990
5991 Endproc
5992
5993 *---------------------------------------------------------------------------------
5994
5995 PROCEDURE GetOrdersEligibleForBulkAdjustment
5996 LPARAMETERS pcZzeipcth ,pcZzeipctd,pcOrdHdr, pcOrdDtl ,plnew
5997 LOCAL llRetVal,lcSql, lcUnique ,lcCnclCondition
5998
5999 llRetVal = .t.
6000
6001 IF plnew
6002 lcSql = "Select h.Ord_num, h.ord_status into "+ this.cOpenCnclHdr+ ;
6003 " from ZZOORDRH h " + ;
6004 " Join "+ pcZzeipcth + " th on th.ord_num = h.ord_num and (h.ord_status = 'O' OR h.ord_status = 'C') and th.errs_flg_h <> 'Y' and h.bulk_red = 'Y' "+ ;
6005 " where exists ( select oh.pkey from zzoordrh oh (nolock) where (h.customer = oh.customer "+ ;
6006 " or customer = (Select parent from zzxcustr where customer = oh.customer)) "+ ;
6007 " and oh.conf_type = 'B') "
6008 llRetVal = llRetVal and v_sqlexec(lcSql)
6009
6010 lcSQL = " Select * into "+ this.cUniqueHdr+ ;
6011 " from "+ this.cOpenCnclHdr+ " H "+ ;
6012 " where str(ord_num) + ord_status = (Select top 1 str(ord_num)+ord_status "+ ;
6013 " from "+ this.cOpenCnclHdr+ " h1 "+ ;
6014 " where h1.ord_num = h.ord_num order by ord_status desc)"
6015 llRetVal = llRetVal and v_sqlexec(lcSql)
6016
6017
6018 lcSql = "Select h.* into " + pcOrdHdr + " from ZZOORDRH h " + ;
6019 " Join "+ this.cUniqueHdr + " th on th.ord_num = h.ord_num and h.ord_status = th.ord_status "
6020 llRetVal = llRetVal and v_sqlexec(lcSql)
6021 ELSE
6022 lcSql = "Select h.* into " + pcOrdHdr + " from ZZOORDRH h " + ;
6023 " Join "+ pcZzeipcth + " th on th.ord_num = h.ord_num and h.ord_status = 'O' and th.errs_flg_h <> 'Y' and h.bulk_red = 'Y' "+ ;
6024 " where exists ( select oh.pkey from zzoordrh oh (nolock) where (h.customer = oh.customer "+ ;
6025 " or customer = (Select parent from zzxcustr where customer = oh.customer)) "+ ;
6026 " and oh.conf_type = 'B') "
6027 llRetVal = llRetVal and v_sqlexec(lcSql)
6028 ENDIF
6029
6030
6031 lcCnclCondition = IIF(plnew and not EMPTY(this.cCnclDtlOld )," and Not Exists ( select pkey from "+ this.cCnclDtlOld + " where pkey = d.pkey ) ","")
6032
6033 lcSql = " Select d.* into " + pcOrdDtl + " from zzoordrd d inner join " + ;
6034 pcZzeipcth + " h on h.ord_num = d.ord_num "+ ;
6035 " join "+ pcZzeipctd + " td "+ ;
6036 " on h.pkey = td.fkey "+ ;
6037 " and d.division = td.division "+ ;
6038 " and d.style = td.style "+ ;
6039 " and d.color_code = td.color_code "+ ;
6040 " and d.lbl_code = td.lbl_code "+ ;
6041 " and d.dimension = td.dimension "+ ;
6042 " and d.bulk_red = 'Y' and " +IIF(plnew , " d.line_status ='O' OR d.line_status = 'C' "," d.line_status = 'O' ")+ ;
6043 lcCnclCondition
6044
6045 llRetVal = llRetVal and v_sqlexec(lcSql)
6046
6047 RETURN llRetVal
6048
6049 ENDPROC
6050
6051
6052*============================================================
6053
6054 FUNCTION PopulateBulkNibblerRecord
6055 LPARAMETERS pcZzeipcth,pcZzeipctd
6056 LOCAL llRetVal, lnSelect,lcUnique
6057
6058 Local lcInsertSQL_zzoordwh, lcInsertSQL_zzoordwd, lcInsertSQL_zzxniblr
6059 STORE " " TO lcInsertSQL_zzoordwh, lcInsertSQL_zzoordwd, lcInsertSQL_zzxniblr
6060
6061
6062 llRetVal = true
6063 lnSelect = SELECT()
6064
6065
6066 llRetVal = llRetVal and this.oCopyUtil.GetInsertSql(@lcInsertSQL_zzxniblr,this.cZzxniblr,"zzxniblr",,,,.t.)
6067 llRetVal = llRetVal and this.oCopyUtil.GetInsertSql(@lcInsertSQL_zzoordwh,this.cZzoordwh,"zzoordwh","'trx_pkey'",,,.t.)
6068 llRetVal = llRetVal and this.oCopyUtil.GetInsertSql(@lcInsertSQL_zzoordwd,this.cZzoordwd,"zzoordwd","'trx_pkey'",,,.t.)
6069
6070
6071 lcUnique = SYS(2015)
6072 this.cOrdHdrNew = "#zzoordrh" + lcUnique
6073 this.cOrdDtlNew = "#zzoordrd" + lcUnique
6074 llRetVal = llRetVal And this.GetOrdersEligibleForBulkAdjustment(pcZzeipcth,pcZzeipctd,this.cOrdHdrNew,this.cOrdDtlNew,.t.)
6075 this.RegisterTable(this.cOrdHdrNew )
6076 this.RegisterTable(this.cOrdDtlNew )
6077
6078 *--- create record for zzoordwh
6079 llRetVal = llRetVal And This.PopulateBulkHeaderRecord('O')
6080
6081 *--- create record for zzoordwd
6082 llRetVal = llRetVal And This.PopulateBulkDetailRecord('O')
6083
6084 *--- create record for zzoordwh
6085 llRetVal = llRetVal And This.PopulateBulkHeaderRecord('N')
6086
6087 *--- create record for zzoordwd
6088 llRetVal = llRetVal And This.PopulateBulkDetailRecord('N')
6089
6090 lcSql = "Alter table " + This.cZzxniblr + " drop column Pkey_I"
6091 llRetVal = llRetVal and v_sqlexec(lcSql)
6092
6093 llRetVal = llRetVal And This.SetTrxNum()
6094
6095 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzxniblr)
6096
6097 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzoordwh)
6098
6099 llRetVal = llRetVal And v_SQLExec(lcInsertSQL_zzoordwd)
6100
6101 SELECT (lnSelect)
6102 RETURN llRetVal
6103 ENDFUNC
6104
6105*============================================================
6106 Procedure SetTrxNum
6107
6108 Local llRetVal, lnOldSelect,lcUnique, lcSql, lnTrxCount
6109 llRetVal = .T.
6110 lnOldSelect = Select()
6111 lnTrxCount = 0
6112 lcSql = " select COUNT(*) as NewOrderCount FROM " + This.cZzxniblr + " n "
6113 llRetVal = llRetVal And v_sqlexec(lcSql,"NewOrderCount")
6114
6115 If Used("NewOrderCount")
6116 lnTrxCount = NewOrderCount.NewOrderCount
6117 Use In NewOrderCount
6118 Endif
6119
6120 If Not (llRetVal And lnTrxCount > 0)
6121 Select(lnOldSelect)
6122 Return llRetVal
6123 Endif
6124
6125 *--- update Trx_num in work order header
6126 Declare laOrdDtls[2,4]
6127 laOrdDtls[1,1] = This.cZzoordwh
6128 laOrdDtls[1,2] = "TRX_NUM" && update field of detail table
6129 laOrdDtls[1,3] = "TRX_NUM" && relation field of Detail table
6130 laOrdDtls[1,4] = "TRX_NUM" && relation field of Header table
6131
6132 *--- update Trx_num in work order detail
6133 laOrdDtls[2,1] = This.cZzoordwd
6134 laOrdDtls[2,2] = "TRX_NUM" && update field of detail table
6135 laOrdDtls[2,3] = "TRX_NUM" && relation field of Detail table
6136 laOrdDtls[2,4] = "TRX_NUM" && relation field of Header table
6137
6138 *--- Set ord_num to new order header
6139 lnMaxTrx_num = v_nextPkey("ZZXNIBLR", lnTrxCount)
6140 llRetVal = llRetVal And This.oCopyUtil.HdrDtlNumKeyFldUpdate(This.cZzxniblr,"TRX_NUM",@laOrdDtls,lnMaxTrx_num,lnTrxCount,;
6141 "TRX_NUM_I")
6142
6143
6144 lcSql = "Update n Set pkey = n.TRX_NUM from " + This.cZzxniblr + " n "
6145 llRetVal = llRetVal And v_sqlexec(lcSql)
6146
6147 Select(lnOldSelect)
6148 Return llRetVal
6149
6150 Endproc
6151
6152*============================================================
6153*=== TechRec 1085945 28-May-2015 vkrishnamurthy ===
6154
6155Enddefine