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