· 7 years ago · Oct 10, 2018, 03:00 PM
1 PROCEDURE DeleteALLStoreOrder
2 LPARAMETERS pceIPCth, pceIPCtd,pcVzzeiPCth_iPCproc, pcVzzeiPCtd_iPCproc, pceipcth_dbf_add, pceipctD_dbf_Bad
3
4 LOCAL lnOldIpcdOrder, llRetVal, lnOldSelect, lcCustPo
5 SELECT(pceIPCtd)
6 SET ORDER TO fkey
7 llRetVal = .t.
8 lnOldSelect = SELECT()
9 IF llRetVal
10 SELECT(pceIPCth)
11 *--- TR 1036066 NH
12 *--- TR 1039809 APR-17-2009 BR - ADDED: AND ord_num <= 0
13 SELECT customer, po_num, pkey FROM (pceIPCth) th WHERE edi_store = '' AND EMPTY(store) AND ForAllStore = 'Y' AND ord_num <= 0 ;
14 ORDER BY customer, po_num INTO CURSOR tmpCurs
15 LOCAL lcPrevOrderBy
16 *SCAN FOR edi_store = this.cStore_ALL AND EMPTY(store)
17 SELECT tmpCurs
18 SCAN
19 *=== TR 1036066 NH
20 lcCustPo = customer+po_num
21 SELECT(pceipcth_dbf_add)
22 *--- if the customer po not found in the add list then do not delete
23 *--- some kind of error occured user need to see the IPC record
24 IF SEEK(lcCustPo, pceipcth_dbf_add, "CustPo")
25 *--- 1036066 NH
26 *DELETE FOR fkey = EVALUATE(pceIPCth + ".pkey") IN (pceIPCtd)
27 SELECT (pceIPCtd)
28 lcPrevOrderBy = ORDER()
29 SET ORDER to fkey
30 IF SEEK(tmpCurs.pkey,pceIPCtd,"FKEY")
31 SCAN WHILE fkey = tmpCurs.pkey
32 IF !SEEK(pkey,pceipctD_dbf_Bad,'pkey') &&--- TR 1036066 NH
33 DELETE IN (pceIPCtd)
34 ENDIF
35 ENDSCAN
36 ENDIF
37 SET ORDER to lcPrevOrderBy
38
39 *--- delete from IPC view right here
40 *DELETE FOR fkey = EVALUATE(pceIPCth + ".pkey") IN (pcVzzeiPCtd_iPCproc)
41 select (pcVzzeiPCtd_iPCproc)
42 lcPrevOrderBy = ORDER()
43 SET ORDER TO fkey
44 IF SEEK(tmpCurs.pkey,pcVzzeiPCtd_iPCproc,"FKEY")
45 SCAN WHILE fkey = tmpCurs.pkey
46 IF !SEEK(pkey,pceipctD_dbf_Bad,'pkey') &&--- TR 1036066 NH
47 DELETE IN (pcVzzeiPCtd_iPCproc)
48 ENDIF
49 ENDSCAN
50 ENDIF
51 SET ORDER to lcPrevOrderBy
52
53 *DELETE FOR pkey = EVALUATE(pceIPCth + ".pkey") IN (pcVzzeiPCth_iPCproc)
54 *---
55 IF SEEK(tmpCurs.pkey,pcVzzeiPCth_iPCproc,"PKEY") AND !SEEK(tmpCurs.pkey,pceipctD_dbf_Bad,'Fkey') &&--- TR 1036066 NH
56 DELETE IN (pcVzzeiPCth_iPCproc)
57 ENDIF
58 *--- now delete the header
59 *DELETE IN (pceIPCth)
60 IF SEEK(tmpCurs.pkey,pceIPCth,"PKEY") AND !SEEK(tmpCurs.pkey,pceipctD_dbf_Bad,'Fkey') &&--- TR 1036066 NH
61 DELETE IN (pceIPCth)
62 ENDIF
63 *=== TR 1036066 NH
64 ENDIF
65 ENDSCAN
66 ENDIF
67 SELECT(lnOldSelect)
68 RETURN llRetVal
69 ENDPROC
70
71 ********************************************************************************
72
73 PROCEDURE UpdateActualStoreNotesWithALLStoreNotes
74 lPARAMETERS pceIPCth,pceIPCtd, pcVnotes_IPCH_iPCproc, pcVnotes_iPCD_iPCproc
75
76 *--- delete all ALL records from detail.
77 *--- add "DI" notes from ALL records to actual store records.
78 *--- create notes detail view
79 *--- add detail notes from ALL store records to acutal store records.
80
81 LOCAL llRetVal, lnOldSelect
82 llRetVal = .t.
83 lnOldSelect = SELECT()
84 *--- header view
85 *--- find the notes of ALL headers
86 LOCAL lcOldOrder
87 SELECT (pceIPCth)
88 lcOldOrder = ORDER()
89 INDEX ON edi_store TAG edi_store
90
91 *--- TechRec 1061523 28-May-2012 jjanand --- Enabled support to header notes
92 SELECT h.customer, h.division, h.po_num, n.* from (pcVnotes_IPCh_iPCproc) n ;
93 inner join (pceIPCth) h on h.pkey = n.fkey WHERE h.ForAllStore = 'Y' INTO CURSOR tcNotesIPCh_add
94
95 IF RECCOUNT("tcNotesIPCh_add") > 0
96 SELECT (pceIPCth)
97 INDEX ON customer + division + po_num TAG custPoHdr
98
99 SELECT("tcNotesIPCh_add")
100 SCAN
101 SCATTER NAME loNotesIPCh_add memo
102 SELECT(pceIPCth)
103
104 IF SEEK(loNotesIPCh_add.customer + loNotesIPCh_add.division + loNotesIPCh_add.PO_num, pceIPCth, "custPoHdr")
105 SCAN WHILE customer + division + po_num = loNotesIPCh_add.customer + loNotesIPCh_add.division + loNotesIPCh_add.PO_num
106 IF ForAllStore <> 'Y'
107 loNotesIPCh_add.fkey = EVALUATE(pceIPCth + ".pkey")
108 loNotesIPCh_add.pkey = v_nextPkey("SYSNOTES")
109 SELECT(pcVnotes_iPCh_iPCproc)
110 APPEND BLANK
111 GATHER NAME loNotesIPCh_add memo
112 ENDIF
113 ENDSCAN
114 ENDIF
115 ENDSCAN
116 ENDIF
117 *=== TechRec 1061523 28-May-2012 jjanand ===
118
119 *--- TR 1036066 NH
120*!* SELECT h.customer, h.po_num, d.upc, d.sku, d.ean, d.qualifier, n.* from (pcVnotes_IPCD_iPCproc) n INNER JOIN (pceIPCtd) d ON d.pkey = n.fkey ;
121*!* inner join (pceIPCth) h on h.pkey = d.fkey WHERE h.edi_store = this.cStore_ALL INTO CURSOR tcNotesIPCD_add
122
123 SELECT h.customer, h.po_num, d.upc, d.sku, d.ean, d.qualifier, n.* from (pcVnotes_IPCD_iPCproc) n INNER JOIN (pceIPCtd) d ON d.pkey = n.fkey ;
124 inner join (pceIPCth) h on h.pkey = d.fkey WHERE h.ForAllStore = 'Y' INTO CURSOR tcNotesIPCD_add
125 *=== TR 1036066 NH
126 IF RECCOUNT("tcNotesIPCD_add") > 0
127 SELECT (pceIPCth)
128 INDEX ON customer + po_num TAG custPo
129 *--- IPC tran detail notes
130 SELECT(pceIPCtd)
131 SELECT("tcNotesIPCD_add")
132 SCAN
133 SCATTER NAME loNotesIPCD_add memo
134 SELECT(pceIPCth)
135 IF SEEK(loNotesIPCD_add.customer + loNotesIPCD_add.PO_num, pceIPCth, "custPo")
136 SCAN WHILE customer + Po_num = loNotesIPCD_add.customer + loNotesIPCD_add.PO_num
137 *--- TR 1036066 NH
138 *IF edi_store <> this.cStore_ALL
139 IF ForAllStore <> 'Y'
140 *=== TR 1036066 NH
141 lnPkey_IPCH = pkey
142 SELECT(pceIPCtd)
143 IF SEEK(lnPkey_IPCH,pceIPCtd,"fkey")
144 SCAN WHILE fkey = lnPkey_IPCH
145 IF upc + sku + ean + qualifier = loNotesIPCD_add.upc + ;
146 loNotesIPCD_add.sku + loNotesIPCD_add.ean + loNotesIPCD_add.qualifier
147 *-- found the detail record where this notes will be linked
148 loNotesIPCD_add.fkey = EVALUATE(pceIPCtd + ".pkey")
149 loNotesIPCD_add.pkey = v_nextPkey("SYSNOTES")
150 SELECT(pcVnotes_iPCD_iPCproc)
151 APPEND BLANK
152 GATHER NAME loNotesIPCD_add memo
153 ENDIF
154 ENDSCAN
155 ENDIF
156 ENDIF
157 ENDSCAN
158 ENDIF
159 ENDSCAN
160 ENDIF
161 SELECT(lnOldSelect)
162 RETURN llRetVal
163 ENDPROC
164
165 ********************************************************************************
166
167 PROCEDURE ScatterGatherOnExistsCopyErrorMsg
168 Lparameter tcSource, tcTarget
169
170 LOCAL lcSelect, lcSetCentury
171 lcSelect = SELECT(0)
172 lcSetCentury = SET('CENTURY')
173 SET CENTURY ON
174
175 LOCAL loSrc
176 SELECT (tcSource)
177 SCAN
178 SCATTER NAME loSrc MEMO
179 SELECT (tcTarget)
180 IF SEEK(loSrc.pkey, tcTarget,"Pkey")
181 IF NOT EMPTY(loSrc.errs_msg_h) AND loSrc.errs_msg_h <> errs_msg_h
182 replace errs_flg_h WITH 'Y', errs_msg_h WITH ALLTRIM(errs_msg_h) + loSrc.errs_msg_h IN (tcTarget)
183 ENDIF
184 ELSE
185 APPEND BLANK
186 GATHER NAME loSrc MEMO
187 ENDIF
188 ENDSCAN
189 SET CENTURY &lcSetCentury
190 SELECT (lcSelect)
191 Endproc
192
193 *=== TR 1016904 NH
194
195 *--- TR 1017209 NH
196 PROCEDURE PopulateActualStoreForEmptyStoreOnHdrCancel
197 LPARAMETERS pcEipcTH
198 LOCAL llRetVal, lnOldSelect
199 llRetVal = .t.
200 lnOldSelect = SELECT()
201 *--- Notes: We do not handle Bulk Order cancelation. ?????????
202 *--- As at this stage we do not have enough information on how to cancel a bulk order.
203 *--- As for example : what should be done when an Bulk order has Assortment order also.
204 *--- - We can cancel remainder of the bulk order or
205 *--- - Cancel the Bulk order including all existing open assortment orders of the PO.
206
207 *--- get all the SO Order for the customer + po_num
208 LOCAL lcSQL, lcAllStores, lnPkeyEmptyStore, llFound
209 lcAllStores = "zzoordrhAllStores"
210 lcIpcthEmptyStore = SYS(2015)
211 SELECT * from (pcEipcTH) WHERE EMPTY(edi_store) AND poc_purp = "01" INTO CURSOR (lcIpcthEmptyStore)
212 SELECT (lcIpcthEmptyStore)
213 SCAN
214 SCATTER NAME loEipcTH memo
215 lcSQL = "Select h.po_num, h.customer, h.store, h.division, r.edi_store from zzoordrh h inner join zzxstorr r on " + ;
216 " h.customer = r.customer and h.store = r.store " + ;
217 " where h.customer = '" + TRANSFORM(loEipcTH.customer) + "' and h.po_num = '" + TRANSFORM(loEipcTH.po_num) + "'" + ;
218 " and h.conf_type = 'A'"
219 llRetVal = llRetVal and v_SQLExec(lcSQL,lcAllStores) and USED(lcAllStores)
220
221 IF llRetVal
222 *--- create new trans header for each store SO order
223 SELECT(lcAllStores)
224 lnPkeyCount = RECCOUNT(lcAllStores)
225 *-- we are going to use the blank store Trans header so, one less pkey needs to be generated.
226 lnPkeyEmptyStore = loEipcTH.pkey
227 lnPkeyCount = lnPkeyCount - 1
228 lnPkey = 0
229 IF lnPkeyCount > 0
230 lnPkey = v_NextPkey('ZZEIPCTH',lnPkeyCount) - lnPkeyCount
231 ENDIF
232
233 SELECT(lcAllStores)
234 SCAN
235 *--- create new tran Hdr line for each BC SO order
236 loEipcTH.edi_store = edi_store
237 loEipcTH.store = store
238 loEipcTH.division = division && division is populated for entire order cancellation.
239 llFound = .f.
240 SELECT (pcEipcTH)
241 *--- new record only when store count is more than one.
242 IF lnPkeyEmptyStore > 0
243 llFound = SEEK(lnPkeyEmptyStore,pcEipcTH,"pkey")
244 ELSE
245 lnPkey = lnPkey + 1
246 loEipcTH.pkey = lnPkey
247 APPEND BLANK
248 ENDIF
249
250 IF lnPkeyEmptyStore > 0 AND NOT llFound && this is should not result in true at any time
251 .LogEntry("pkey " + TRANSFORM(lnPkeyEntryStore) + " could not be found! Process will fail.")
252 llRetVal = .f.
253 EXIT
254 ELSE
255 lnPkeyEmptyStore = 0 && assign zero here so that this routine will be executed only once per empty store.
256 GATHER NAME loEipcTH memo
257 ENDIF
258 ENDSCAN
259 ENDIF
260 IF USED(lcAllStores)
261 USE IN (lcAllStores)
262 ENDIF
263 ENDSCAN
264 SELECT(lnOldSelect)
265 RETURN llRetVal
266
267 ENDPROC
268 *=== TR 1017209 NH
269 *--- TR 1016559 NH
270 ******************************************************************************
271 PROCEDURE PrepackConversion
272 LPARAMETERS pcTransDetail
273 LOCAL llRetVal, lnOldSelect, lcErrs_Msg
274 llRetVal = .T.
275 lnOldSelect = SELECT()
276 this.LogEntry("Starting program " + program())
277 this.LogEntry("Prepack Conversion Allowed - " + IIF(this.lPrepackConversion,"Yes.","No."))
278 *--- making this modification backward compatible.
279 IF NOT this.lPrepackConversion
280 RETURN llRetVal
281 ENDIF
282
283 lcSQLString = "Select * from zzxrangh where rng_type = 'P'"
284 llRangeP = v_SqlExec(lcSQLString, "__RangeP")
285
286 SELECT DISTINCT d.division, d.STYLE, d.color_code, d.lbl_code, d.DIMENSION, d.ppk_action ;
287 FROM (pcTransDetail) d ;
288 WHERE d.ppk_action $ 'QPB' ; && prepack style that requires some conversion
289 AND not exists (select * from __RangeP rp where rp.division = d.division and rp.rng_style = d.style ;
290 and rp.rng_color = d.color_code and rp.rng_lbl = d.lbl_code and rp.rng_pack = d.dimension ) ;
291 ORDER BY d.division, d.STYLE, d.color_code, d.lbl_code, d.DIMENSION INTO CURSOR __TmpCursor
292
293 IF RECCOUNT("__TmpCursor") > 0
294 THIS.cSQLTempTable = ""
295 llRetVal = llRetVal and THIS.GenerateSQLTempTable('__TmpCursor')
296 llRetVal = llRetVal and THIS.PopulateSQLTempTable('__TmpCursor')
297 llRetVal = llRetval and !EMPTY(THIS.cSQLTempTable)
298
299 *--- TR 1046757 12-AUG-2010 MANI. Added condition ph.Active_ok = 'Y' ===
300 lcSQLString = "Select t.*, ph.ppk_desc, ph.pack_qty, s.size_code " +;
301 "from zzxppakh ph, zzxscolr s, " + THIS.cSQLTempTable + " t " +;
302 "Where s.ppack_ok= 'Y' and s.division= t.division and " +;
303 "s.style= t.style and s.color_code= t.color_code and " +;
304 "s.lbl_code = t.lbl_code and s.dimension = t.dimension and " + ;
305 "s.division= ph.division and s.size_code= ph.size_code and "+;
306 "s.dimension= ph.ppk_code and ph.Active_ok = 'Y' "
307
308 llRetVal = llRetVal AND v_SqlExec(lcSQLString, "_PPK_Qty") and USED("_PPK_Qty")
309 IF llRetVal
310 this.LogEntry("Number of prepack-style requires conversion is " + TRANSFORM(RECCOUNT("_PPK_Qty")))
311 ENDIF
312 llRetVal = llRetval and THIS.PrePackConvert("_PPK_Qty",pcTransDetail)
313 ENDIF
314 IF USED("__TmpCursor")
315 USE IN __TmpCursor
316 ENDIF
317 IF USED("_PPK_Qty")
318 USE IN _PPK_Qty
319 ENDIF
320 SELECT(lnOldSelect)
321 RETURN llRetVal
322 ENDPROC
323
324 ******************************************************************************
325
326 PROCEDURE PrePackConvert
327 LPARAMETERS pcurPPK_Qty, pcTransDetail
328 LOCAL llRetVal, lnOldSelect
329 LOCAL lcppk_action, lnPack_Qty
330 llRetVal = .t.
331 lnOldSelect = SELECT()
332 this.LogEntry("Starting program " + PROGRAM())
333 SELECT(pcurPPK_Qty)
334 INDEX ON division+STYLE+color_code+lbl_code+DIMENSION TAG Ppk
335 llRetVal = llRetVal AND .SetRelation(pcurPPK_Qty, "Ppk", pcTransDetail, ;
336 "division+style+color_code+lbl_code+dimension")
337 IF llRetVal
338 THIS.oLog.LogEntry("Validating prepack style.")
339 lcErrs_Msg = "No valid prepack code found"
340 SELECT (pcTransDetail)
341 SCAN FOR !(Errs_Flg_D= "Y") AND ppk_action $ 'QPB'
342 lnPack_Qty = EVALUATE(pcurPPK_Qty + ".pack_qty")
343 IF EMPTY(lnPack_Qty)
344 REPLACE Errs_Msg_D WITH Errs_Msg_D + lcErrs_Msg + CRLF, ;
345 Errs_Flg_D WITH "Y" ;
346 IN (pcTransDetail)
347 ELSE
348 lcppk_action = EVALUATE(pcurPPK_Qty + ".ppk_action")
349 DO CASE
350 CASE lcppk_action = 'Q' && multiply qty
351 REPLACE ppk_qty WITH lnPack_Qty, ;
352 total_qty WITH total_qty*lnPack_Qty, ;
353 qty_change WITH qty_change*lnPack_Qty, ;
354 ppk_action WITH 'M' ; && 'M'ultiplied. Don't do it again.
355 IN (pcTransDetail)
356 CASE _PPK_Qty.ppk_action = 'P' && divide price
357 REPLACE ppk_qty WITH lnPack_Qty, ;
358 org_price WITH org_price/lnPack_Qty, ;
359 poc_cost WITH poc_cost/lnPack_Qty, ;
360 poc_price WITH poc_price/lnPack_Qty, ;
361 poc_retail2 WITH poc_retail2/lnPack_Qty, ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
362 ppk_action WITH 'D' ; && 'D'ivided. Don't do it again.
363 IN (pcTransDetail)
364 CASE _PPK_Qty.ppk_action = 'B' && both multiply qty and divide price
365 REPLACE ppk_qty WITH lnPack_Qty, ;
366 org_price WITH org_price/lnPack_Qty, ;
367 poc_cost WITH poc_cost/lnPack_Qty, ;
368 poc_price WITH poc_price/lnPack_Qty, ;
369 poc_retail2 WITH poc_retail2/lnPack_Qty, ; &&--- TechRec 1054692 21-Sep-2011 jisingh ===
370 total_qty WITH total_qty*lnPack_Qty, ;
371 qty_change WITH qty_change*lnPack_Qty, ;
372 ppk_action WITH 'X' ; && Divided and Multiplied. Don't do it again.
373 IN (pcTransDetail)
374 OTHERWISE
375 ENDCASE
376 ENDIF
377 ENDSCAN
378 ENDIF
379 SET RELATION TO
380 SELECT(lnOldSelect)
381 RETURN llRetVal
382 ENDPROC
383
384 ******************************************************************************
385
386 *=== TR 1016559 NH
387 *---- TR 1016560 NH
388
389 ************************************************************************************
390 * - Implosion single prepack
391 * 860 Multiple Prepack Implosion
392 ************************************************************************************
393 ************************************************************************************
394 * - Implosion logic for Simple Prepack (not Multiple prepack)
395 *
396 * -- Build work cursor prepack: Prepack SKU, pack_qty, pack01..24 qty
397 * -- Build work cursor order: horizontal size like actual orders and mark vertical
398 * tran detail with same DtlPkey (--will use for latter removing group of tran detail)
399 * Only select order lines that are none prepack (--not previously resolve to prepack
400 * nor original come in as prepack UPC/SKU)
401 * -- Search for prepack to use: order total qty divisible by pack_qty; make sure also
402 * all size bucket also divisible. When find a prepack will create new transaction
403 * detail with order line qty stuff to 1st avail bucket of prepack style.
404 * -- Implosion set to "Y"es and not found prepack report error message or skip
405 * if imposion set to "O"pen stock
406 *
407 * Notes: condition for single vs. multiple prepack
408 * zzxppakh.pack_qty <> zzxppakd.pack_total : MULTIPLE RECORD PrePack
409 * zzxppakh.pack_qty = zzxppakd.pack_total : SINGLE RECORD PrePack
410 *
411 ************************************************************************************
412
413 ************************************************************************************
414 * resolving prepack (multiple and single color prepack imposion)
415 ***********************************************************************************
416
417
418 PROCEDURE Resolve860Prepack
419 LPARAMETERS pceipcTH, pceipcTD, pceipcCR
420
421 *--- get all qualifier present in the detail
422
423 LOCAL llRetVal, lnOldSelect,lceipcTD_Qualifier, lceipcTD_temp, lcQualifier
424 llRetVal = .t.
425 lnOldSelect = SELECT()
426 lceipcTD_Qualifier = "tceIPCtd_Qualifier"
427 lceipcTD_temp = "tceipcTD_temp"
428 lcQualifier = "tcQualifier"
429
430 WITH this
431 SELECT DISTINCT qualifier from (pceipcTD) INTO CURSOR (lcQualifier)
432 SELECT * from (pceipcTD) into CURSOR (lceipcTD_temp)
433
434 *--- clear all record from 860 trans detail so after each scan loop records realted to each will be appended back
435 SELECT (pceipcTD)
436 DELETE ALL
437 SELECT (lcQualifier)
438 SCAN
439 *--- create dtl cursor for each type of qualifier pceipcTD_Qualifier
440 llRetVal = llRetVal and .CreateQualifierDltFromIPCdtl(lceipcTD_temp, lceipcTD_Qualifier, EVALUATE(lcQualifier + ".qualifier"))
441 .LogEntry("Resolving Prepack/Range style for Qualifier " + EVALUATE(lcQualifier + ".qualifier") + ".")
442
443 llRetVal = llRetVal and .ResolvePrepack(pceipcTH, lceipcTD_Qualifier, pceipcCR)
444 .LogEntry("Resolving Prepack for Qualifier " + EVALUATE(lcQualifier + ".qualifier") + " " + IIF(llRetVal,"successful.","failed."))
445
446 llRetVal= llRetVal AND .ResolveRangeP(pceipcTH, lceipcTD_Qualifier, pceipcCR)
447 .LogEntry("Resolving Range Style type 'P' for Qualifier " + EVALUATE(lcQualifier + ".qualifier") + ;
448 " " + IIF(llRetVal,"successful.","failed."))
449
450 IF .lMultipack
451 llRetVal = llRetVal AND .ResolveMultiPrepacks(pceipcTH, lceipcTD_Qualifier,.cMPPK)
452 .LogEntry("Resolving Multipack Prepack for Qualifier " + EVALUATE(lcQualifier + ".qualifier") + ;
453 " " + IIF(llRetVal,"successful.","failed."))
454 ENDIF
455 llRetVal = llRetVal and .AppendToIPCtd(lceipcTD_Qualifier,pceipcTD)
456 llRetVal = llRetVal and .TableClose(lceipcTD_Qualifier)
457 ENDSCAN
458 .TableClose(lceipcTD_temp)
459 ENDWITH
460 SELECT(lnOldSelect)
461 RETURN llRetVal
462 ENDPROC
463
464 ************************************************************************************
465
466 FUNCTION ResolveRangeP
467 LPARAMETERS pceipcTH, pceipcTD, pceipcCR
468 LOCAL llRetVal, lnOldSelect, lcSQLString, lnResult
469 llRetVal = .T.
470 lnOldSelect = SELECT()
471
472 WITH THIS
473 .LogMajorStage("Range Style Implosion.")
474 *- do we have any range styles 'P' in BC
475 lcSQLString= "Select count(*) From zzxrangH where rng_type = 'P' "
476 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "tcTemp")
477 IF !llRetVal OR RECC("tcTemp") = 0
478 .LogEntry("No range styles for implosion")
479 RETURN llRetVal
480 ENDIF
481
482 *--- TR 1048865 Changed from d.division = C.division AND d.customer = C.customer ; to c.pkey = th.cr_pkey and join with pceipcTH
483 SELECT DISTINCT fkey, C.Rng_impl ;
484 FROM (pceipcTD) d ;
485 JOIN (pceipcTH) h ;
486 ON h.pkey = d.fkey ;
487 JOIN (pceipcCR) C ;
488 ON c.pkey = h.cr_pkey ;
489 WHERE C.Rng_impl <> 'N' AND !EMPTY(d.STYLE) ;
490 AND !EMPTY(d.division) AND !EMPTY(d.customer) ;
491 AND EMPTY(d.rng_style) AND d.implosion <> "Y" ;
492 INTO CURSOR rng_det
493
494 SELECT division, STYLE, color_code, lbl_code, DIMENSION, Sizebucket, d.qty_change as total_qty, d.fkey ;
495 FROM (pceipcTD) d ;
496 JOIN rng_det r ON r.fkey = d.fkey ;
497 WHERE !EMPTY(d.STYLE) ;
498 AND !EMPTY(d.division) AND !EMPTY(d.customer) ;
499 AND EMPTY(d.rng_style) AND d.implosion <> "Y" ;
500 INTO CURSOR __TmpCurs
501
502 IF RECCOUNT("__TmpCurs") < 1
503 SELECT (lnOldSelect)
504 RETURN llRetVal
505 ENDIF
506
507 .cSQLTempTable=""
508 llRetVal = llRetVal and .GenerateSQLTempTable('__TmpCurs')
509 llRetVal = llRetVal and .PopulateSQLTempTable('__TmpCurs') and !EMPTY(.cSQLTempTable)
510 IF llRetVal
511 SELECT rng_det
512 SCAN
513 lnFkey = rng_det.fkey
514 lcRng_Impl = rng_det.Rng_impl
515 lcSQLStr = "select * from " + .cSQLTempTable + " where FKey = " + SQLFormatNum(lnFkey)
516 dtl = SQLTableFromQuery(lcSQLStr )
517 lnResult = .RangeImplosion(lnFkey, dtl, pceipcTD)
518 SELECT (pceipcTD)
519 DO CASE
520 CASE lnResult = 0 && match not found
521 IF lcRng_Impl = 'Y'
522 REPLACE Errs_Msg_D WITH Errs_Msg_D + " Cannot find range style " + CRLF, ;
523 Errs_Flg_D WITH "Y" ;
524 FOR fkey = lnFkey AND !EMPTY(STYLE) ;
525 AND !EMPTY(division) AND !EMPTY(customer) ;
526 AND EMPTY(rng_style) AND implosion <> "Y" IN (pceipcTD)
527 ENDIF
528 CASE lnResult > 1 && ambiguous
529 REPLACE Errs_Msg_D WITH Errs_Msg_D + " Ambiguous range style " + CRLF, ;
530 Errs_Flg_D WITH "Y" ;
531 FOR fkey = lnFkey AND !EMPTY(STYLE) ;
532 AND !EMPTY(division) AND !EMPTY(customer) ;
533 AND EMPTY(rng_style) AND implosion <> "Y" IN (pceipcTD)
534 ENDCASE
535 ENDSCAN
536 ENDIF
537 ENDWITH
538 SELECT (lnOldSelect)
539 RETURN llRetVal
540 ENDFUNC
541
542 ******************************************************************************************
543
544 FUNCTION RangeImplosion
545 LPARAMETERS pnFkey, dtl, pceipcTD
546 LOCAL llRetVal, lnOldSelect, lcSQLString, llSingleMatch, lnPPKCnt, llAmbig, lnCnt, ;
547 lcFldStr, lcTopStr, lcBotStr ,lcMiddleStr, lcCoalStr_pkey, lcCoalRevStr_pkey, ;
548 lcCoalStr_ratio, lcCoalRevStr_ratio, lcGroupFkeyStr, lcGroupStr, lnPrepacks
549
550 llRetVal = .T.
551 lnOldSelect = SELECT()
552 WITH THIS
553
554 *- select all range style details with the matching BCSku(style/color/lbl/dim) and
555 *- turn them vertical into SQL-side temp table var. RangD
556 lcSQLString = "select d.Division, d.Style, d.Color_code, d.Lbl_Code, d.Dimension, " + ;
557 " Size_Num as Size_Bk, d.PKey, d.FKey, " + ;
558 "d.Size01_Qty*Sz01 + d.Size02_Qty*Sz02+ " + ;
559 "d.Size03_Qty*Sz03 + d.Size04_Qty*Sz04+ " + ;
560 "d.Size05_Qty*Sz05 + d.Size06_Qty*Sz06+ " + ;
561 "d.Size07_Qty*Sz07 + d.Size08_Qty*Sz08+ " + ;
562 "d.Size09_Qty*Sz09 + d.Size10_Qty*Sz10+ " + ;
563 "d.Size11_Qty*Sz11 + d.Size12_Qty*Sz12+ " + ;
564 "d.Size13_Qty*Sz13 + d.Size14_Qty*Sz14+ " + ;
565 "d.Size15_Qty*Sz15 + d.Size16_Qty*Sz16+ " + ;
566 "d.Size17_Qty*Sz17 + d.Size18_Qty*Sz18+ " + ;
567 "d.Size19_Qty*Sz19 + d.Size20_Qty*Sz20+ " + ;
568 "d.Size21_Qty*Sz21 + d.Size22_Qty*Sz22+ " + ;
569 "d.Size23_Qty*Sz23 + d.Size24_Qty*Sz24 as Qty, " + ;
570 "d.a_price, d.b_price, d.c_price, d.d_price, d.e_price " + ;
571 "from " + ;
572 " (select dd.* from zzxrangd dd " + ;
573 " where fkey in ( " + ;
574 " select distinct ph.pkey " + ;
575 " from zzxrangh ph " + ;
576 " join zzxrangd pd " + ;
577 " on ph.Pkey = Pd.Fkey " + ;
578 " join " + dtl + " td1 " + ;
579 " on pd.style = td1.style " + ;
580 " and pd.color_code = td1.color_code " + ;
581 " and pd.lbl_code = td1.lbl_code " + ;
582 " and pd.dimension = td1.dimension " + ;
583 " where ph.rng_type = 'P') ) d " + ;
584 "cross join zzxbuckt b " + ;
585 "where d.Size01_Qty*Sz01 + d.Size02_Qty*Sz02+ " + ;
586 "d.Size03_Qty*Sz03 + d.Size04_Qty*Sz04+ " + ;
587 "d.Size05_Qty*Sz05 + d.Size06_Qty*Sz06+ " + ;
588 "d.Size07_Qty*Sz07 + d.Size08_Qty*Sz08+ " + ;
589 "d.Size09_Qty*Sz09 + d.Size10_Qty*Sz10+ " + ;
590 "d.Size11_Qty*Sz11 + d.Size12_Qty*Sz12+ " + ;
591 "d.Size13_Qty*Sz13 + d.Size14_Qty*Sz14+ " + ;
592 "d.Size15_Qty*Sz15 + d.Size16_Qty*Sz16+ " + ;
593 "d.Size17_Qty*Sz17 + d.Size18_Qty*Sz18+ " + ;
594 "d.Size19_Qty*Sz19 + d.Size20_Qty*Sz20+ " + ;
595 "d.Size21_Qty*Sz21 + d.Size22_Qty*Sz22+ " + ;
596 "d.Size23_Qty*Sz23 + d.Size24_Qty*Sz24 > 0 "
597
598 RangD = SQLTableFromQuery(lcSQLString)
599
600 *- Cartesian join to create sets of detail UPCs (BCSku/sizebucket) and all
601 *- possible combinations of RangD that cover them.
602 *- Result is SQL-side temp table var. RangeSet
603 lcSQLString = ; &&td.*,mtch.PKey as FKey, mtch.*, d.PKey +
604 'select td.style, td.color_code, td.lbl_code, td.dimension, td.sizebucket, mtch.PKey as FKey, d.PKey, ' + ;
605 ' mtch.rng_style, mtch.rng_color, mtch.rng_lbl, mtch.rng_pack, mtch.rng_qty, ' + ;
606 ' td.total_qty, d.qty, 1.0*td.total_qty/d.qty ratio ' + ;
607 ' from ' + dtl + ' td ' + ;
608 ' cross join ( ' + ;
609 ' select * from zzxrangh H where exists ' + ;
610 '( select * from ' + RangD + ' dd ' + ;
611 ' join ' + dtl + ' td1 ' + ;
612 ' on dd.Division = td1.Division and dd.style = td1.style and dd.color_code = td1.color_code ' + ;
613 'and dd.lbl_code = td1.lbl_code and dd.dimension = td1.dimension and dd.size_bk = td1.sizebucket ' + ;
614 'where dd.FKey = H.PKey )) mtch ' + ;
615 'left join ' + RangD + ' D on d.FKey = mtch.PKey and d.Division = td.Division and d.style = td.style ' + ;
616 ' and d.color_code = td.color_code and d.lbl_code = td.lbl_code and d.dimension = td.dimension ' + ;
617 'and d.size_bk = td.sizebucket ' + ;
618 ' where not exists ( ' + ;
619 ' select * from ' + RangD + ' dd where dd.Fkey = mtch.Pkey and not exists( ' + ;
620 ' select * from ' + dtl + ' td2 ' + ;
621 ' where dd.style = td2.style ' + ;
622 ' and dd.color_code = td2.color_code ' + ;
623 ' and dd.lbl_code = td2.lbl_code ' + ;
624 ' and dd.dimension = td2.dimension ' + ;
625 ' and dd.size_bk = td2.sizebucket ' + ;
626 ' and dd.Division = td2.Division )) '
627
628 RangeSet = SQLTableFromQuery(lcSQLString)
629
630 *- how many different range styles were found for this order
631 lcSQLString = ;
632 ' select count(*) PPKCnt ' + ;
633 ' from (select distinct fkey from ' + RangeSet + ') t'
634
635 llRetVal = v_SqlExec(lcSQLString, "tmp_cnt")
636 lnPPKCnt = tmp_cnt.PPKCnt
637
638 *--- the result (Query #2):
639 *- See if any single range style in the RangeSet fully matches DTL
640 lcSQLString = ;
641 ' select Count(*), t1.Fkey, t1.rng_style, t1.rng_color, t1.rng_lbl, t1.rng_pack, t1.ratio ' + ;
642 ' from ' + dtl + ' dtl ' + ;
643 ' join ' + RangeSet + ' t1 ' + ;
644 ' on dtl.style = t1.style ' + ;
645 ' and dtl.color_code = t1.color_code ' + ;
646 ' and dtl.lbl_code = t1.lbl_code ' + ;
647 ' and dtl.dimension = t1.dimension ' + ;
648 ' and dtl.sizebucket = t1.sizebucket ' + ;
649 ' group by t1.Fkey, t1.rng_style, t1.rng_color, t1.rng_lbl, t1.rng_pack, t1.ratio ' + ;
650 ' having count(*) = (select count(*) from ' + dtl + ') '
651
652 llRetVal = v_SqlExec(lcSQLString, "__tmp")
653 lnCnt = RECCOUNT()
654
655 llSingleMatch = .F.
656 llAmbig = .F.
657 CREATE CURSOR q_Result( ValidRange MEMO)
658 DO CASE
659 CASE lnCnt > 1
660 llAmbig = .T. && ambiguos, give error message and do not continue
661 CASE lnCnt = 1
662 llSingleMatch = .T.
663 INSERT INTO q_Result (ValidRange) VALUES( ALLTR(STR(__tmp.fkey)) + ", " + TRANS(__tmp.ratio))
664 OTHERWISE
665 ENDCASE
666
667 lnResult = lnCnt
668
669 IF !llAmbig
670 *- If none single range style in the RangeSet fully matches DTL,
671 *- or even if a match was found
672 *- start going through combinations of 2,3... - may be ambiguous
673 lcFldStr = ' select Count(*), t1.Fkey'
674 lcTopStr = ;
675 ' from ' + dtl + ' dtl ' + ;
676 ' join ' + RangeSet + ' t1 ' + ;
677 ' on dtl.style = t1.style ' + ;
678 ' and dtl.color_code = t1.color_code ' + ;
679 ' and dtl.lbl_code = t1.lbl_code ' + ;
680 ' and dtl.dimension = t1.dimension ' + ;
681 ' and dtl.sizebucket = t1.sizebucket '
682
683 lcBotStr = ' having count(*) = (select count(*) from ' + dtl + ') '
684 lcMiddleStr = ''
685 lcCoalStr_pkey = 't1.pkey'
686 lcCoalRevStr_pkey = 't1.pkey'
687 lcCoalStr_ratio = 't1.ratio'
688 lcCoalRevStr_ratio = 't1.ratio'
689 lcGroupFkeyStr = ' t1.FKey'
690 lcGroupStr = ''
691 lnPrepacks = MIN(lnPPKCnt, 6)
692
693 FOR j = 2 TO lnPrepacks && 6 different range styles in a single order is enough?
694 llFoundNext = .F.
695
696 lcnum = TRANS(j, "9")
697 lcPrevNum = TRANS(j - 1, "9")
698 lcCoalStr_pkey = lcCoalStr_pkey + ', t' + lcnum + '.Pkey'
699 lcCoalRevStr_pkey = 't' + lcnum + '.Pkey, ' + lcCoalRevStr_pkey
700
701 lcCoalStr_ratio = lcCoalStr_ratio + ', t' + lcnum + '.ratio'
702 lcCoalRevStr_ratio = 't' + lcnum + '.ratio, ' + lcCoalRevStr_ratio
703
704 lcGroupFkeyStr = lcGroupFkeyStr + ', t' + lcnum + '.Fkey '
705 lcGroupStr = lcGroupFkeyStr + ', coalesce(' + lcCoalStr_ratio + '), coalesce(' + lcCoalRevStr_ratio + ') '
706 lcFldStr = lcFldStr + ", t" + lcnum + '.Fkey AS t' + lcnum + '_Fkey'
707 lcMiddleStr = lcMiddleStr + ;
708 "join " + RangeSet + " t" + lcnum + ;
709 ' on dtl.style = t' + lcnum + '.style ' + ;
710 ' and dtl.color_code = t' + lcnum + '.color_code ' + ;
711 ' and dtl.lbl_code = t' + lcnum + '.lbl_code ' + ;
712 ' and dtl.dimension = t' + lcnum + '.dimension ' + ;
713 ' and dtl.sizebucket = t' + lcnum + '.sizebucket ' + ;
714 ' and t' + lcnum + '.Fkey > t' + lcPrevNum + '.Fkey '
715
716 lcWhereStr = 'where coalesce(' + lcCoalStr_pkey + ') = coalesce(' + lcCoalRevStr_pkey + ') ' + ;
717 ' Group by ' + lcGroupStr
718
719 lcFldStr_ratio = ', coalesce(' + lcCoalStr_ratio + ') ratio ' && get ratio
720 lcSQLResultStr = lcFldStr + lcFldStr_ratio + lcTopStr + lcMiddleStr + lcWhereStr + lcBotStr
721 llRetVal = v_SqlExec(lcSQLResultStr, "__tmp")
722 lnCnt = RECCOUNT()
723 llFoundNext = (lnCnt = 1)
724 *- ambig when either prev or this SQL returned more than 1 row or
725 *- one match was found before AND one is found now - making it two.
726 IF lnCnt > 0
727 SCAN
728 *- ADD CONDITION TO CHECK THAT THE RATIO IS INTEGER, i.e. detail qty is properly
729 *- divisible by the number of items in the range style!!!
730 IF MOD(ratio, 1) <> 0 && not divisible, exclude
731 ELSE
732 lcInsertStr = TRANS(fkey)
733 FOR lnCounter = 2 TO j
734 lcInsertStr = lcInsertStr + ", " + TRANS(EVAL("t" + lcnum + '_Fkey ' ))
735 ENDFOR
736 lcInsertStr = lcInsertStr + ", " + TRANS(ratio)
737 INSERT INTO q_Result (ValidRange) VALUES(lcInsertStr)
738 ENDIF
739 ENDSCAN
740 ENDIF
741 lnResultCnt = RECC("q_Result")
742 llAmbig = (lnResultCnt > 1)
743 llSingleMatch = (lnResultCnt = 1)
744 IF llAmbig
745 lnResult = lnResultCnt
746 EXIT
747 ENDIF
748 ENDFOR
749 IF llSingleMatch
750 lnResult = 1
751 .ConsolidateRangeP(pceipcTD, "q_Result", pnFkey)
752 ENDIF
753 ELSE && ambiguous
754 lnResult = lnCnt
755 ENDIF
756 ENDWITH
757 RETURN lnResult
758 ENDPROC
759
760 *****************************************************************************************
761
762 PROCEDURE ConsolidateRangeP
763 LPARAMETERS pceipcTD, q_Result, pnFkey
764 LOCAL llRetVal, lnOldSelect, lcSQLString, lcSizeBucket, lnLen, lnRatio, oDtl
765 LOCAL lnPocCost
766
767 llRetVal = .T.
768 lnOldSelect = SELECT()
769
770 *- insert range styles that match zzxrangd.fkey from q_result
771 *- into pceipcTD.
772 *- parse the string from cursor q_result to get the list of fkeys
773 SELECT (pceipcTD)
774 LOCATE FOR fkey = pnFkey
775 SCATTER NAME oDtl MEMO
776 DECLARE aRange[1]
777 aRange = ''
778 SELECT q_Result
779 SCATTER MEMVAR MEMO
780 StringToArray(m.ValidRange, @aRange, ",")
781 lnLen = ALEN(aRange) - 1 && the last element is ratio
782 lnRatio = VAL( aRange[lnLen + 1] )
783 FOR j = 1 TO lnLen
784 lcFkey = aRange[j]
785 v_SqlExec("select * from zzxrangh where pkey = " + lcFkey, "__RangH")
786 oDtl.STYLE = __RangH.rng_style
787 oDtl.color_code = __RangH.rng_color
788 oDtl.lbl_code = __RangH.rng_lbl
789 oDtl.DIMENSION = __RangH.rng_pack
790 oDtl.rng_style = __RangH.rng_style
791 oDtl.rng_color = __RangH.rng_color
792 oDtl.rng_lbl = __RangH.rng_lbl
793 oDtl.rng_pack = __RangH.rng_pack
794 oDtl.rng_qty = __RangH.rng_qty
795 oDtl.rng_type = __RangH.rng_type
796 *- don't have to have upc or sku for the imploded range style
797 oDtl.upc = ''
798 oDtl.sku = ''
799 *-- No need for price information here.
800 *- clear err msg and err flag which may have error after unsuccessful implosion
801 lnPocCost = this.GetRangePocCost("__RangH", this.SaleOrderControlRef)
802 oDtl.Errs_Msg_D = ""
803
804 *- 1009211 03/09/05 YIK
805 *- Initializ3e errs_flg_d to N, not blank
806 *- oDtl.Errs_Flg_D = " "
807 oDtl.Errs_Flg_D = "N"
808 *- org_price is based on zzocntrc (cust sales) price_code
809 *- we'll get the proper price_code in ValidOrderControl()
810 *- and the org_price will be updated in ResolvePriceFromRangeStyle()
811
812 *- 1009211 02/24/05 YIK
813 *- Keep quantity in cases and use price per case.
814 *- and zero out orig price which will be resolved.
815 *- oDtl.total_qty = __RangH.rng_qty*lnRatio
816 oDtl.total_qty = lnRatio
817 oDtl.qty_change = lnRatio
818 oDtl.poc_cost = lnPocCost
819 *= 1009211
820 oDtl.Sizebucket = __RangH.rng_bk
821 oDtl.rng_bk = oDtl.Sizebucket
822 IF !v_GetSizeHeadings(oDtl.division, oDtl.STYLE, "__xSizer")
823 llRetVal = .F.
824 EXIT
825 ENDIF
826 lcSizeBucket = "Size" + TRANS(oDtl.Sizebucket, "@L 99") && zzxsizer bucket field names
827 oDtl.size_desc = TRIM(EVAL("__xSizer." + lcSizeBucket)) && zzxsizer bucket Names
828 *--
829 oDtl.pkey = v_nextPkey("ZZEIPCTD")
830 SELECT (pceipcTD)
831 APPEND BLANK
832 GATHER NAME oDtl
833 ENDFOR
834 IF llRetVal
835 *- delete components
836 DELETE FOR fkey = pnFkey AND !EMPTY(STYLE) ;
837 AND !EMPTY(division) AND !EMPTY(customer) ;
838 AND EMPTY(rng_style) AND implosion <> "Y" ;
839 IN (pceipcTD)
840 ENDIF
841 SELECT (lnOldSelect)
842 RETURN llRetVal
843 ENDPROC
844
845 ******************************************************************************************
846
847 PROCEDURE GetRangePocCost
848 LPARAMETERS tcRangH, tcSaleOrderControlRef
849
850 LOCAL lnOldSelect, lnCost, lcPrice_code
851 lnOldSelect = SELECT()
852 lnCost = 0
853 lcPrice_code = ""
854 SELECT(tcRangH)
855 lcDivision = EVALUATE(tcRangH + ".division")
856 IF NOT EMPTY(lcDivision) AND SEEK(lcDivision, tcSaleOrderControlRef, "div")
857 lcPrice_code = ALLTRIM(EVALUATE(tcSaleOrderControlRef + ".Price_code"))
858 IF NOT EMPTY(lcPrice_code)
859 lnCost = EVALUATE(tcRangH + "." + lcPrice_code + "_price")
860 ENDIF
861 ENDIF
862 SELECT(lnOldSelect)
863 RETURN lnCost
864
865 ENDPROC
866
867 ******************************************************************************************
868
869 PROCEDURE UpdateFlds
870 LPARAMETERS pceipctd
871 LOCAL llRetVal, lnOldselect
872 lnOldselect = SELECT()
873 llRetVal = .t.
874 REPLACE Qty_change WITH Total_qty FOR implosion = 'Y' IN (pceipctd)
875 SELECT(lnOldselect)
876 RETURN llRetVal
877 ENDPROC
878
879
880 ************************************************************************************
881
882 PROCEDURE CreateQualifierDltFromIPCdtl
883 LPARAMETERS pceipcTD, pceipcTD_Qualifier, pcQualifier
884
885 LOCAL llRetVal, lnOldSelect,loipcTD
886
887 llRetVal = .t.
888 lnOldSelect = SELECT()
889 WITH this
890 llRetVal = llRetVal and .CreateCursorStructure(pceipcTD,,pceipcTD_Qualifier)
891 SELECT (pceipcTD)
892 SCAN FOR qualifier = pcQualifier
893 SCATTER NAME loipcTD memo
894 SELECT(pceipcTD_Qualifier)
895 APPEND BLANK
896 GATHER NAME loipcTD memo
897 ENDSCAN
898 ENDWITH
899 RELEASE loipcTD
900
901 SELECT (pceipcTD_Qualifier)
902 INDEX ON dtlpkey TAG dtlpkey
903 INDEX ON STR(dtlpkey) + STR(Sizebucket) TAG dtlSzPkey
904 INDEX ON STR(fkey)+STYLE+color_code+lbl_code+DIMENSION TAG GrpDetail
905 INDEX ON pkey TAG pkey
906 INDEX ON fkey TAG fkey
907
908 SELECT(lnOldSelect)
909 RETURN llRetVal
910
911 ENDPROC
912
913 ************************************************************************************
914
915 PROCEDURE AppendToIPCtd
916 LPARAMETERS pceipcTD_Qualifier,pceipcTD
917 LOCAL llRetVal, lnOldSelect,loipcTD
918
919 lnOldSelect = SELECT()
920 llRetVal = .t.
921 SELECT (pceipcTD_Qualifier)
922 SCAN
923 SCATTER NAME loipcTD memo
924 SELECT (pceipcTD)
925 APPEND BLANK
926 GATHER NAME loipcTD memo
927 ENDSCAN
928 RELEASE loipcTD
929 SELECT(lnOldSelect)
930 RETURN llRetVal
931 ENDPROC
932
933 ************************************************************************************
934
935 PROCEDURE ResolvePrepack
936 LPARAMETERS pceipcTH, pceipcTD, pceipcCR
937 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
938 llRetVal = .T.
939 lnOldSelect = SELECT()
940 WITH THIS
941 .LogMajorStage("Prepack Implosion.")
942
943 *--- Single prepack implosion without prepack any logic (--Alpha)
944 *--- with prepack any logic for (--Amerex)
945 llRetVal= llRetVal AND .IsPrepackAny()
946 .LogEntry("Getting multiple records prepack.")
947 *--- prepack has multiple lines in the prepack detail
948 *--- this is regardless of ALL exists or not in prepack detail
949 llRetVal= llRetVal AND .GetMultiplePrepacks(pceipcTH, pceipcTD, "tcMultPPK")
950 *--- Single prepack implosion without prepack any logic (--Alpha)
951 *--- with prepack any logic for (--Amerex)
952 IF .lSinglePrepackAny
953 *--- check for each prepack that it resolve the SKU is in scolr
954 .LogEntry("Getting all prepack SKUs from Style master for verify existing prepack.")
955 .cQualPPKSkus = "tcQPPKSKU"
956 *--- only BC sku with dim/pk as prepack from scolr
957 llRetVal = llRetVal AND .GetQualifyPrepackSKU(pceipcTH, pceipcTD, .cQualPPKSkus)
958 llRetVal = llRetVal AND .GetQualifyMultiPackPrePack(.cQualPPKSkus,.cMPPK)
959 *-- Cannot join to zzxscolr and prepack detail color/label "ALL" is
960 *-- a resolution not actual color/lbl to join.
961 .LogEntry("Getting single record prepack with prepack any logic.")
962 .GetSinglePrepacks(pceipcTH, pceipcTD, "tcSnglPPK")
963 ELSE
964 .LogEntry("Getting single record prepack without prepack any logic.")
965 llRetVal = llRetVal AND .IsMultiPack(pceipcTH)
966 IF THIS.lMultipack
967 .MoreSinglePrepacksWithoutPrepackAny(pceipcTH, pceipcTD, "tcSnglPPK")
968 ELSE
969 .GetSinglePrepacksWithoutPrepackAny(pceipcTH, pceipcTD, "tcSnglPPK")
970 ENDIF
971 ENDIF
972
973 .LogEntry("Verifying implosion flag.")
974 llRetVal = llRetVal AND .CascadingCustomerToDetail(pceipcTH, pceipcTD)
975 .LogEntry("Creating temporaty order cursor for prepack match.")
976 llRetVal = llRetVal AND .BuildOrderForPrepack(pceipcTH, pceipcTD, pceipcCR, "tcOrdDtl")
977 .LogEntry("Implosion multiple records prepack.")
978 llRetVal = llRetVal AND .ImplosionMultiPrepack(pceipcTH, pceipcTD, pceipcCR, "tcMultPPK", "tcOrdDtl")
979 *--- Single prepack implosion without prepack any logic (--Alpha)
980 *--- with prepack any logic for (--Amerex)
981 IF .lSinglePrepackAny
982 .LogEntry("Implosion single record prepack with prepack any logic.")
983 llRetVal= llRetVal AND .ImplosionSinglePrepack(pceipcTH, pceipcTD, pceipcCR, "tcSnglPPK", "tcOrdDtl")
984 .LogEntry("Getting single record single size prepack with prepack any logic.")
985 .GetSingleSizePrepacks("tcSnglPPK", "tcSSizePPK")
986 .LogEntry("Getting Vertical details for single size prepack with prepack any logic.")
987 llRetVal= llRetVal AND .BuildVerticalOrderForPrepack("tcOrdDtl", "tcVertOrdDtl")
988 .LogEntry("Implosion single record single size prepack with prepack any logic.")
989 llRetVal= llRetVal AND .ImplosionSingleSizePrepackWithPrepackAny(pceipcTH, pceipcTD, pceipcCR, "tcSSizePPK", "tcVertOrdDtl")
990 ELSE
991 .LogEntry("Implosion single record prepack without prepack any logic.")
992 llRetVal= llRetVal AND .ImplosionSinglePrepackWithoutPrepackAny(pceipcTH, pceipcTD, pceipcCR, "tcSnglPPK", "tcOrdDtl")
993 *- Add new layer - single size implosion.
994 *- Only for Alpha
995 .LogEntry("Getting single record single size prepack without prepack any logic.")
996 .GetSingleSizePrepacks("tcSnglPPK", "tcSSizePPK")
997 .LogEntry("Getting Vertical details for single size prepack without prepack any logic.")
998 llRetVal= llRetVal AND .BuildVerticalOrderForPrepack("tcOrdDtl", "tcVertOrdDtl")
999 .LogEntry("Implosion single record single size prepack without prepack any logic.")
1000 llRetVal= llRetVal AND .ImplosionSingleSizePrepackWithoutPrepackAny(pceipcTH, pceipcTD, pceipcCR, "tcSSizePPK", "tcVertOrdDtl")
1001 ENDIF
1002
1003 .TableClose("tcMultPPK")
1004 .TableClose("tcSnglPPK")
1005 .TableClose("tcOrdDtl")
1006 ENDWITH
1007 SELECT(lnOldSelect)
1008 RETURN llRetVal
1009 ENDPROC
1010
1011 ************************************************************************************
1012 *-- Is prepack any logic set (prepack detail color_code='ALL' or lbl_code='ALL')
1013 ***********************************************************************************
1014 *--- Single prepack implosion without prepack any logic (--Alpha)
1015 *--- with prepack any logic for (--Amerex)
1016 PROCEDURE IsPrepackAny
1017 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
1018 llRetVal = .T.
1019 lnOldSelect = SELECT()
1020 WITH THIS
1021 lcSQLString= "Select count(*) as ppk_any From zzxppakd where (color_code='ALL' or lbl_code='ALL')"
1022 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "tcTemp")
1023 .lSinglePrepackAny= IIF(USED("tcTemp") AND tcTemp.ppk_any > 0, .T., .F.) && for optimizing client that does not use Prepack Any logic
1024 *- To be able to test Alpha ppk logic (where .lSinglePrepackAny= .F.)
1025 *- Our DEV has records with color_code='ALL', so QA always uses the Amerex (.lSinglePrepackAny =.T.) logic.
1026 .lSinglePrepackAny = .lSinglePrepackAny AND (goEnv.SV("ALPHA_PPK_LOGIC", "N") = "N")
1027 .lSinglePrepackAny = .T. && TR 1041687 JUL-28-2009 BR
1028 ENDWITH
1029 SELECT(lnOldSelect)
1030 RETURN llRetVal
1031 ENDPROC
1032
1033 ***********************************************************************************
1034 * Get all Multiple Prepacks (by division,style) for resolving prepack
1035 ***********************************************************************************
1036 PROCEDURE GetMultiplePrepacks
1037 LPARAMETERS pcHeader, pcDetail, pcPrePack
1038 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
1039 llRetVal = .T.
1040 lnOldSelect = SELECT()
1041
1042 SELECT DISTINCT d.division,d.STYLE FROM (pcDetail) d , (pcHeader) h ;
1043 WHERE h.pkey=d.fkey INTO CURSOR _TmpCursor && -- and !(d.Errs_Flg_D= "Y")
1044
1045 WITH THIS
1046 .cSQLTempTable=""
1047 IF .GenerateSQLTempTable('_TmpCursor')
1048 IF .PopulateSQLTempTable('_TmpCursor')
1049 IF !EMPTY(.cSQLTempTable)
1050 * Get ALL Multiple record Prepack for valid div,style
1051 lcSQLString= "Select ph.ppk_desc, ph.pack_qty, ph.mulcllb_ok, ph.ppk_color, pd.*,z.* " +;
1052 " FROM zzxppakh ph " +;
1053 " JOIN zzxppakd pd " +;
1054 " ON ph.pkey = pd.fkey " +;
1055 " JOIN zzxsizer z " +;
1056 " ON ph.division=z.division and ph.size_code=z.size_code " +;
1057 " WHERE ph.active_ok='Y' And ph.pack_qty > pd.pack_total and ph.division+ph.size_code IN " +;
1058 " (SELECT s.division + s.size_code " +;
1059 " FROM zzxscolr s " +;
1060 " JOIN " + .cSQLTempTable + " t " +;
1061 " ON (s.division=t.division And s.style=t.style) " +;
1062 " WHERE s.ppack_ok= 'Y' " +;
1063 " )"
1064 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "_PrePack")
1065 llRetVal= llRetVal AND .MakeCursorWritable("_PrePack", pcPrePack)
1066 ENDIF
1067 ENDIF
1068 ENDIF
1069 .TableClose('_TmpCursor')
1070 .TableClose('_PrePack')
1071 ENDWITH
1072 * index for optimizing
1073 IF USED(pcPrePack)
1074 SELECT (pcPrePack)
1075 *--- 860 Inbound implosion of Prepack - single color with multi dimension
1076 LOCATE FOR color_code= "ALL" OR lbl_code= "ALL"
1077 .lMultiPrepackAny= IIF(FOUND(), .T., .F.) && for optimizing client that does not use Prepack Any logic
1078 .oLog.LogEntry("Prepack any logic for multiple records: " + IIF(.lMultiPrepackAny, "Yes", "No"))
1079 LOCATE FOR color_code= "ALL" OR color_code= " "
1080 .lSingleColorMultiPrepack = FOUND()
1081 GO TOP IN (pcPrePack)
1082 INDEX ON division+ppk_code TAG DivPPK
1083 INDEX ON division+color_code+lbl_code+DIMENSION+ppk_code TAG ColLblDim
1084 ENDIF
1085
1086 SELECT(lnOldSelect)
1087 RETURN llRetVal
1088 ENDPROC
1089
1090 ***************************************************************************************
1091 *--- check for each prepack that it resolve the SKU is in scolr
1092 *-- COULD BE VERY SLOW, FOR EACH DETAIL LINE AND EACH RESOLUTION OF PREPACK NEED
1093 *-- TO VERIFY FOR EXISTING OF SKU IN SCOLR, DUE TO UNABLE TO JOIN BECAUSE PREPACK
1094 *-- PREPACK ANY LOGIC (COLOR,LBL_CODE COULD BE "ALL")
1095 PROCEDURE GetQualifyPrepackSKU
1096 LPARAMETERS pcHeader, pcDetail, pcPrePack
1097 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
1098 llRetVal = .T.
1099 lnOldSelect = SELECT()
1100
1101 SELECT DISTINCT d.division,d.STYLE,h.customer FROM (pcDetail) d , (pcHeader) h ;
1102 WHERE h.pkey=d.fkey INTO CURSOR _TmpCursor && -- and !(d.Errs_Flg_D= "Y")
1103
1104 WITH THIS
1105 .cSQLTempTable=""
1106 IF .GenerateSQLTempTable('_TmpCursor')
1107 IF .PopulateSQLTempTable('_TmpCursor')
1108 IF !EMPTY(.cSQLTempTable)
1109 * Get ALL Single Prepack for valid div,style
1110 lcSQLString= "SELECT s.*,t.customer FROM zzxscolr s " +;
1111 " JOIN " + .cSQLTempTable + " t " +;
1112 " ON s.division=t.division And s.style=t.style " +;
1113 " WHERE s.ppack_ok= 'Y' "
1114 llRetVal= llRetVal AND v_SqlExec(lcSQLString, pcPrePack)
1115 ENDIF
1116 ENDIF
1117 ENDIF
1118 .TableClose('_TmpCursor')
1119 ENDWITH
1120
1121 IF USED(pcPrePack)
1122 SELECT (pcPrePack)
1123 INDEX ON division+STYLE+color_code+lbl_code+DIMENSION TAG OurSku
1124 ENDIF
1125
1126 SELECT(lnOldSelect)
1127 RETURN llRetVal
1128 ENDPROC
1129
1130 *************************************************************************************
1131
1132 FUNCTION GetQualifyMultiPackPrePack
1133 LPARAMETERS pcPrePack, pcMultPack
1134 LOCAL llRetVal, lnSelect, lcSQLString
1135
1136 llRetVal = True
1137 lnSelect = SELECT()
1138 SELECT * FROM (pcPrePack) INTO CURSOR _TmpCursor
1139 WITH THIS
1140 .cSQLTempTable=""
1141 IF .GenerateSQLTempTable('_TmpCursor')
1142 IF .PopulateSQLTempTable('_TmpCursor')
1143 IF !EMPTY(.cSQLTempTable)
1144
1145 *--- TR 1080606 16-8-2014 VKK changed m.* into indivdual fields to avoid error
1146 lcSQLString= "SELECT p.*,m.customer,m.mpack_code,total_qty FROM zzemppkh m " +;
1147 " JOIN " + .cSQLTempTable+ " p " +;
1148 " ON m.customer=p.customer "
1149
1150
1151 llRetVal = llRetVal AND v_SqlExec(lcSQLString, pcMultPack)
1152 ENDIF
1153 ENDIF
1154 ENDIF
1155 ENDWITH
1156
1157 THIS.lMultipack = USED(pcMultPack) AND RECCOUNT(pcMultPack) > 0
1158
1159 IF THIS.lMultipack
1160 SELECT (pcMultPack)
1161 INDEX ON STYLE+mpack_code TAG MStyPPK
1162 ENDIF
1163 .TableClose('__TmpCursor')
1164 SELECT (lnSelect)
1165 RETURN llRetVal
1166 ENDFUNC
1167
1168 ************************************************************************************
1169 * Get all Single Prepacks with prepack any logic (-See Amerex Implementation)
1170 ***********************************************************************************
1171 PROCEDURE GetSinglePrepacks
1172 LPARAMETERS pcHeader, pcDetail, pcPrePack
1173 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
1174 llRetVal = .T.
1175 lnOldSelect = SELECT()
1176
1177 SELECT DISTINCT d.division,d.STYLE FROM (pcDetail) d , (pcHeader) h ;
1178 WHERE h.pkey=d.fkey INTO CURSOR _TmpCursor && -- and !(d.Errs_Flg_D= "Y")
1179
1180 WITH THIS
1181 .cSQLTempTable=""
1182 IF .GenerateSQLTempTable('_TmpCursor')
1183 IF .PopulateSQLTempTable('_TmpCursor')
1184 IF !EMPTY(.cSQLTempTable)
1185 * Get ALL Single Prepack for valid div,style
1186 lcSQLString= "Select ph.ppk_desc, ph.pack_qty, ph.mulcllb_ok,pd.*,z.* " +;
1187 " FROM zzxppakh ph " +;
1188 " JOIN zzxppakd pd " +;
1189 " ON ph.pkey = pd.fkey " +;
1190 " JOIN zzxsizer z " +;
1191 " ON ph.division=z.division and ph.size_code=z.size_code " +;
1192 " WHERE ph.active_ok='Y' And ph.pack_qty= pd.pack_total and ph.division+ph.size_code IN " +;
1193 " (SELECT s.division + s.size_code " +;
1194 " FROM zzxscolr s " +;
1195 " JOIN " + .cSQLTempTable + " t " +;
1196 " ON (s.division=t.division And s.style=t.style) " +;
1197 " WHERE s.ppack_ok= 'Y' " +;
1198 " )"
1199 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "_PrePack")
1200 llRetVal= llRetVal AND .MakeCursorWritable("_PrePack", pcPrePack)
1201 ENDIF
1202 ENDIF
1203 ENDIF
1204 .TableClose('_TmpCursor')
1205 .TableClose('_PrePack')
1206 ENDWITH
1207
1208 * index for optimizing
1209 IF USED(pcPrePack)
1210 SELECT (pcPrePack)
1211 INDEX ON division+color_code+lbl_code+DIMENSION+ppk_code TAG ColLblDim && with prepack any process without style
1212 ENDIF
1213
1214 SELECT(lnOldSelect)
1215 RETURN llRetVal
1216 ENDPROC
1217
1218 ******************************************************************************************
1219
1220 PROCEDURE IsMultiPack
1221 LPARAMETERS pcHeader
1222 LOCAL llRetVal, lnSelect, lcSQLString
1223
1224 llRetVal = .T.
1225 lnSelect = SELECT()
1226
1227 SELECT DISTINCT customer FROM (pcHeader) INTO CURSOR __TmpCursor
1228 WITH THIS
1229 .cSQLTempTable=""
1230
1231 IF .GenerateSQLTempTable('__TmpCursor')
1232 IF .PopulateSQLTempTable('__TmpCursor')
1233 IF !EMPTY(.cSQLTempTable)
1234 lcSQLString= "select mp.* from zzemppkh mp," + .cSQLTempTable + " t " +;
1235 "Where mp.customer = t.customer "
1236
1237 llRetVal = v_SqlExec(lcSQLString, "__TmpMppk")
1238 ENDIF
1239 ENDIF
1240 ENDIF
1241 .lMultipack = USED("__TmpMppk") AND RECCOUNT("__TmpMppk") > 0
1242 ENDWITH
1243 SELECT(lnSelect)
1244 RETURN llRetVal
1245 ENDPROC
1246
1247 ******************************************************************************************
1248
1249 PROCEDURE MoreSinglePrepacksWithoutPrepackAny
1250 LPARAMETERS pcHeader, pcDetail, pcPrePack
1251 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv, cSQLTempTable , cSQLTempTable1, lcSQLString, ;
1252 lnFirstAvlBucket
1253
1254 llRetVal = .T.
1255 lnOldSelect = SELECT()
1256 cSQLTempTable = ""
1257 cSQLTempTable1 = ""
1258
1259 SELECT DISTINCT d.division,d.STYLE,d.color_code FROM (pcDetail) d , (pcHeader) h ;
1260 WHERE h.pkey=d.fkey INTO CURSOR __TmpCursor && and !(h.Errs_Flg_H= "Y")
1261
1262 SELECT DISTINCT h.customer, d.division,d.STYLE,d.color_code, d.lbl_code FROM (pcDetail) d , (pcHeader) h ;
1263 WHERE h.pkey=d.fkey INTO CURSOR __TmpCursor2
1264
1265 WITH THIS
1266 .cSQLTempTable=""
1267 IF .GenerateSQLTempTable('__TmpCursor') AND .PopulateSQLTempTable('__TmpCursor')
1268 cSQLTempTable = .cSQLTempTable
1269 ENDIF
1270
1271 .cSQLTempTable=""
1272 IF .GenerateSQLTempTable('__TmpCursor2') AND .PopulateSQLTempTable('__TmpCursor2')
1273 cSQLTempTable1 = .cSQLTempTable
1274 ENDIF
1275
1276 IF !EMPTY(cSQLTempTable) AND !EMPTY(cSQLTempTable1)
1277 *--- TR 1046757 12-AUG-2010 MANI. Added condition ph.Active_ok = 'Y' ===
1278 lcSQLString= "Select ph.ppk_desc, ph.pack_qty, ph.mulcllb_ok," +;
1279 "99 as sizebucket, ' ' as size_desc, s.sizes, s.style, s.color_code as PPK_Color, "+;
1280 "s.lbl_code as PPK_Label,s.dimension as PPK_Dimension, pd.*, z.* " +;
1281 "from zzxppakh ph, zzxppakd pd, zzxscolr s, zzxsizer z, " + cSQLTempTable + " t " +;
1282 "Where s.ppack_ok= 'Y' and s.division= t.division and " +;
1283 "s.style= t.style and s.color_code= t.color_code and " +;
1284 "s.division= ph.division and s.size_code= ph.size_code and "+;
1285 "s.dimension= ph.ppk_code and ph.pkey= pd.fkey and ph.pack_qty= pd.pack_total and " +; && Single Prepack
1286 "ph.division= z.division and ph.size_code= z.size_code and ph.Active_ok = 'Y' " +;
1287 " UNION ALL " +;
1288 "SELECT ph.ppk_desc " + ;
1289 ", ph.pack_qty " + ;
1290 ", ph.mulcllb_ok " + ;
1291 ", 99 AS sizebucket " + ;
1292 ", ' ' AS size_desc " + ;
1293 ", 'YNNNNNNNNNNNNNNNNNNNNNNN' AS sizes " + ;
1294 ", t1.style " + ;
1295 ", t1.color_code AS PPK_Color " + ;
1296 ", t1.lbl_code AS PPK_Label " + ;
1297 ", m.mpack_code AS PPK_Dimension " + ;
1298 ", pd.* " + ;
1299 ", z.* " + ;
1300 "FROM zzxppakh ph " + ;
1301 " , zzxppakd pd " + ;
1302 " ," + cSQLTempTable1 + " t1 " +;
1303 " , zzxsizer z " + ;
1304 " , zzeMPPKh m " + ;
1305 "WHERE " + ;
1306 " ph.pkey= pd.fkey " + ;
1307 " AND ph.pack_qty= pd.pack_total " + ;
1308 " AND ph.division= z.division " + ;
1309 " AND ph.size_code= z.size_code " + ;
1310 " AND m.customer = t1.customer " + ;
1311 " AND m.mpack_code = ph.ppk_code and ph.Active_ok = 'Y'" && *--- TR 1046757 12-AUG-2010 MANI. Added condition ph.Active_ok = 'Y' ===
1312
1313 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "__PrePack")
1314 llRetVal= llRetVal AND .MakeCursorWritable("__PrePack", pcPrePack)
1315
1316 SELECT (pcPrePack)
1317 SCAN
1318 * Find 1st avail buckets and desc to store prepack items latter
1319 lnFirstAvlBucket= AT("Y", sizes, 1)
1320 lnFirstAvlBucket= IIF(lnFirstAvlBucket> 0, lnFirstAvlBucket, 1) && Otherwise stuff in 1st bucket
1321 lcSizeStr= "Size"+ PADL(lnFirstAvlBucket, 2, '0')
1322 REPLACE Sizebucket WITH lnFirstAvlBucket, size_desc WITH EVAL(lcSizeStr)
1323
1324 IF Mulcllb_Ok <> "Y"
1325 REPLACE color_code WITH PPK_color, lbl_code WITH ppk_label, DIMENSION WITH PPK_dimension IN (pcPrePack)
1326 ENDIF
1327 ENDSCAN
1328 ENDIF
1329
1330 .TableClose('__TmpCursor')
1331 .TableClose('__TmpCursor2')
1332 .TableClose('__Prepack')
1333
1334 ENDWITH
1335
1336 * index for optimizing
1337 IF USED(pcPrePack)
1338 SELECT (pcPrePack)
1339 INDEX ON division+STYLE+color_code+lbl_code+DIMENSION TAG CompSKU && without prepack any process with style
1340 ENDIF
1341
1342 SELECT(lnOldSelect)
1343 RETURN llRetVal
1344 ENDPROC
1345
1346
1347 ************************************************************************************
1348 * Get all Single Prepacks with no prepack any logic (-See Alpha Implementation)
1349 ***********************************************************************************
1350 PROCEDURE GetSinglePrepacksWithoutPrepackAny
1351 LPARAMETERS pcHeader, pcDetail, pcPrePack
1352 LOCAL llRetVal, lnOldSelect, lcCurStyleDiv
1353 llRetVal = .T.
1354 lnOldSelect = SELECT()
1355
1356 SELECT DISTINCT d.division,d.STYLE,d.color_code FROM (pcDetail) d , (pcHeader) h ;
1357 WHERE h.pkey=d.fkey INTO CURSOR __TmpCursor && and !(h.Errs_Flg_H= "Y")
1358
1359 WITH THIS
1360 .cSQLTempTable=""
1361 IF .GenerateSQLTempTable('__TmpCursor')
1362 IF .PopulateSQLTempTable('__TmpCursor')
1363 IF !EMPTY(.cSQLTempTable)
1364 * Only PrePack header,details components (zzxppakh/ppakd)
1365 * Blank label prepack (otherwise, will get 2 prepack for same style/color with diff
1366 * label (--ambiguous prepack)
1367 *-- Remove s.lbl_code='' (Use to select ONLY BLANK LABEL PREPACK)
1368 *-- Now select BLANK (GENERIC) and NONE BLANK LABEL
1369 *--- TR 1046757 12-AUG-2010 MANI. Added condition ph.Active_ok = 'Y' ===
1370
1371 lcSQLString= "Select ph.ppk_desc, ph.pack_qty, ph.mulcllb_ok," +;
1372 "99 as sizebucket, ' ' as size_desc, s.sizes, s.style, s.color_code as PPK_Color, "+;
1373 "s.lbl_code as PPK_Label,s.dimension as PPK_Dimension, pd.*, z.* " +;
1374 "from zzxppakh ph, zzxppakd pd, zzxscolr s, zzxsizer z, " + .cSQLTempTable + " t " +;
1375 "Where s.ppack_ok= 'Y' and s.division= t.division and " +;
1376 "s.style= t.style and s.color_code= t.color_code and " +;
1377 "s.division= ph.division and s.size_code= ph.size_code and "+;
1378 "s.dimension= ph.ppk_code and ph.pkey= pd.fkey and ph.pack_qty= pd.pack_total and " +; && Single Prepack
1379 "ph.division= z.division and ph.size_code= z.size_code and ph.Active_ok = 'Y' "
1380 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "__PrePack")
1381 llRetVal= llRetVal AND .MakeCursorWritable("__PrePack", pcPrePack)
1382 SELECT (pcPrePack)
1383 SCAN
1384 * Find 1st avail buckets and desc to store prepack items latter
1385 lnFirstAvlBucket= AT("Y", sizes, 1)
1386 lnFirstAvlBucket= IIF(lnFirstAvlBucket> 0, lnFirstAvlBucket, 1) && Otherwise stuff in 1st bucket
1387 lcSizeStr= "Size"+ PADL(lnFirstAvlBucket, 2, '0')
1388 REPLACE Sizebucket WITH lnFirstAvlBucket, size_desc WITH EVAL(lcSizeStr)
1389 * Not Multi color/label prepack then use color and dimension from zzxscolr
1390 *--> only evaluate prepack with no label otherwise will get more than one
1391 *--> single prepack with same content (--Ambiguous prepack)
1392 *--* Allow all prepacks BLANK (GENERIC) and NONE BLANK (CUSTOMER)
1393 *--* Resolve Prepack 1st None blank then blank when use in combination (850 control)
1394 *--* Customer label and Implotion
1395 IF Mulcllb_Ok <> "Y"
1396 REPLACE color_code WITH PPK_color, lbl_code WITH ppk_label, DIMENSION WITH PPK_dimension IN (pcPrePack)
1397 ENDIF
1398 ENDSCAN
1399 ENDIF
1400 ENDIF
1401 ENDIF
1402 .TableClose('__TmpCursor')
1403 .TableClose('__Prepack')
1404 ENDWITH
1405
1406 * index for optimizing
1407 IF USED(pcPrePack)
1408 SELECT (pcPrePack)
1409 INDEX ON division+STYLE+color_code+lbl_code+DIMENSION TAG CompSKU && without prepack any process with style
1410 ENDIF
1411
1412 SELECT(lnOldSelect)
1413 RETURN llRetVal
1414 ENDPROC
1415
1416
1417 ************************************************************************************
1418 * Build horizontal work order detail to resolve prepack
1419 ***********************************************************************************
1420 PROCEDURE BuildOrderForPrepack
1421 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcOrdDtl
1422 LOCAL llRetVal, lnOldSelect
1423 llRetVal = .T.
1424 lnOldSelect = SELECT()
1425 IF TYPE(pceipcTD + ".rng_style") == 'U'
1426 SELECT DISTINCT d.division,d.STYLE,d.color_code,d.lbl_code,d.DIMENSION ;
1427 FROM (pceipcTD) d , (pceipcTH) h ;
1428 WHERE h.pkey=d.fkey AND (d.division<>'' AND d.STYLE<>'') AND !(d.Errs_Flg_D= "Y") ; && or just none error???
1429 INTO CURSOR _TmpCursor && !(d.Errs_Flg_D= "Y") SKU with no errs.
1430 ELSE
1431 SELECT DISTINCT d.division,d.STYLE,d.color_code,d.lbl_code,d.DIMENSION ;
1432 FROM (pceipcTD) d , (pceipcTH) h ;
1433 WHERE h.pkey=d.fkey AND (d.division<>'' AND d.STYLE<>'') AND !(d.Errs_Flg_D= "Y") ; && or just none error???
1434 AND d.rng_style = ' ' ;
1435 INTO CURSOR _TmpCursor && !(d.Errs_Flg_D= "Y") SKU with no errs.
1436 ENDIF
1437
1438 WITH THIS
1439 .oLog.LogEntry("Creating horizontal order cursor for Prepack Implosion.")
1440
1441 IF RECC("_TmpCursor")> 0
1442
1443 * 1. Get all none distinct prepack style for order that ready to process to live
1444 * send to server for server side join
1445 .cSQLTempTable= ""
1446 llRetVal= llRetVal AND .GenerateSQLTempTable('_TmpCursor')
1447 llRetVal= llRetVal AND .PopulateSQLTempTable('_TmpCursor')
1448 IF !EMPTY(.cSQLTempTable)
1449 * Bring in Style/color (zzxscolr) for SKU that need to implode
1450 lcSQLString= "Select s.* " +;
1451 "from zzxscolr s, " + .cSQLTempTable + " t " +;
1452 "Where (s.ppack_ok= 'N') and s.division= t.division and s.style= t.style and " +;
1453 "s.color_code= t.color_code and s.lbl_code=t.lbl_code and s.dimension=t.dimension "
1454 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "tcPPKSKU")
1455 ENDIF
1456 * 2. Get all detail line (--vertical) that require implostion to prepack
1457 *--- choices by '860 Control Resolve Label'
1458 *-- (Cust_lbl) use 860 control Customer Label (in addition to force customer label to our SKU)
1459 *-- to resolve customer label prepack (NONE BLANK LABEL) 1st then generic prepack (BLANK LABEL)
1460 IF llRetVal AND RECC("tcPPKSKU")> 0
1461
1462 *--- TR 1048865 27-Dec-2010 Goutam
1463 *SELECT d.*, IIF(h.impl_ok $ 'YO', h.impl_ok, C.impl_ok) AS impl_ok, C.lbl_code AS cust_lbl ;
1464 FROM (pceipcTD) d ;
1465 JOIN (pceipcCR) C ON d.customer= C.customer AND d.division= C.division ;
1466 JOIN tcPPKSKU s ON s.division=d.division AND s.STYLE=d.STYLE AND s.color_code=d.color_code AND ;
1467 s.lbl_code=d.lbl_code AND s.DIMENSION=d.DIMENSION ;
1468 JOIN (pceipcTH) h ON h.pkey = d.fkey ;
1469 WHERE ( h.impl_ok $ 'YO' OR (h.impl_ok = ' ' AND C.impl_ok $'YO') ) ;
1470 AND d.fkey NOT IN ;
1471 (SELECT d1.fkey FROM (pceipcTD) d1 ;
1472 WHERE d1.Errs_Flg_D = 'Y') ;
1473 ORDER BY d.fkey,d.STYLE,d.color_code,d.lbl_code,d.DIMENSION,;
1474 d.poc_cost,d.org_price ;
1475 INTO CURSOR _DtlImpl
1476
1477 SELECT d.*, IIF(h.impl_ok $ 'YO', h.impl_ok, C.impl_ok) AS impl_ok, C.lbl_code AS cust_lbl ;
1478 FROM (pceipcTD) d ;
1479 JOIN tcPPKSKU s ON s.division=d.division AND s.STYLE=d.STYLE AND s.color_code=d.color_code AND ;
1480 s.lbl_code=d.lbl_code AND s.DIMENSION=d.DIMENSION ;
1481 JOIN (pceipcTH) h ON h.pkey = d.fkey ;
1482 JOIN (pceipcCR) c ON c.pkey = h.cr_pkey ;
1483 WHERE ( h.impl_ok $ 'YO' OR (h.impl_ok = ' ' AND C.impl_ok $'YO') ) ;
1484 AND d.fkey NOT IN ;
1485 (SELECT d1.fkey FROM (pceipcTD) d1 ;
1486 WHERE d1.Errs_Flg_D = 'Y') ;
1487 ORDER BY d.fkey,d.STYLE,d.color_code,d.lbl_code,d.DIMENSION,;
1488 d.poc_cost,d.org_price ;
1489 INTO CURSOR _DtlImpl
1490 *--- TR 1048865 27-Dec-2010 Goutam
1491
1492 * 3. consolidate them to horizontal size (as if they process into live order)
1493 * for comparing to prepack
1494 *--- Added two more columns Qty_change, qualifier
1495 *- TR 1046528 FH - Added fields poc_cost and poc_price per Yuri
1496 *--- TechRec 1054692 21-Sep-2011 jisingh Added , retail2 as poc_retail2 ===
1497 lcSQLString= "Select *,bulk_key as sizebucket,color_code as size_desc,"+;
1498 "dimension as ppk_code,color_code as ppk_color,bulk_key as col_cnt,"+;
1499 "line_status as ppk_status,line_status as impl_ok, " +;
1500 AsField('C(60)') + " AS avail_ppk, 0 as Qty_change, ' ' as qualifier " + ; && 10/21 Store ambiguous ppk for new manual implosion UI
1501 ", price as poc_cost, retail1 as poc_price, retail2 as poc_retail2 " + ;
1502 "from zzoordrd where 0=1"
1503 llRetVal= llRetVal AND v_SqlExec(lcSQLString, pcOrdDtl)
1504 * index for optimizing
1505 IF USED(pcOrdDtl)
1506 SELECT (pcOrdDtl)
1507 *- Index on Str(fkey)+Style+lbl_code tag fkeystyle
1508 INDEX ON STR(fkey)+STYLE+color_code+lbl_code TAG fkeystyle
1509 ENDIF
1510
1511 lcCurrKeys= ""
1512 SELECT _DtlImpl
1513 llRetVal= .SetRelation(pceipcTD, "pkey", "_DtlImpl" , "pkey")
1514 SCAN
1515 SCATTER MEMVAR
1516 IF ! (STR(fkey)+STYLE+color_code+lbl_code+DIMENSION+;
1517 STR(poc_cost)+STR(org_price) == lcCurrKeys)
1518 * Use 1st pkey from this group as dtlpkey
1519 lnCurDtlPkey= m.pkey
1520 m.total_qty= 0
1521 m.Qty_change=0
1522 m.avail_ppk= "" && reset previous run avail_ppk
1523 *-- TR 1046794 APR-23-2010 BR
1524 lnCurDtlPrice = m.poc_cost
1525 lnCurDtlRetail = m.poc_price
1526 lnCurDtlRetail2 = m.poc_retail2 &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1527 *==
1528 *--use order work cursor LINE_STATUS to store implosion status, clear latter when done.
1529 *--- Resolve Prepack with label
1530 * m.sub_lbl= m.cust_lbl && use order work cursor SUB_LABEL to store customer label && TR 1016560 NH
1531 SELECT (pcOrdDtl)
1532 * Create order detail line when keys change
1533 APPEND BLANK
1534 GATHER MEMVAR
1535 lcCurrKeys= STR(fkey)+STYLE+color_code+lbl_code+DIMENSION+;
1536 STR(poc_cost)+STR(org_price)
1537 ENDIF
1538
1539 * DtlPkey: Use to identify group of Trans. detail (which combine into single line)
1540 * by: str(fkey)+style+color_code+lbl_code+dimension+;
1541 * str(price)+str(org_price)+po1_sku+po1_upc
1542 REPLACE dtlpkey WITH lnCurDtlPkey IN (pceipcTD)
1543
1544 * store DtlPkey to pcOrdDtl.pkey for latter remove group of trans detail
1545 REPLACE pkey WITH lnCurDtlPkey IN (pcOrdDtl)
1546
1547 *--TR 1046794 APR-23-2010 BR
1548 REPLACE price WITH lnCurDtlPrice IN (pcOrdDtl)
1549 REPLACE retail1 WITH lnCurDtlRetail IN (pcOrdDtl)
1550 REPLACE retail2 WITH lnCurDtlRetail2 IN (pcOrdDtl) &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1551 *==
1552
1553 * For each detail line write acumm. total_qty and size qty to proper bucket
1554 * ie. Replace size01_qty with size01_qty + pceipcTD..total_qty ...
1555
1556 IF EVALUATE(pceipcTD + ".Sizebucket") > 0 && 12/10/02
1557 lcSizeStr = "size" + PADL(EVALUATE(pceipcTD + ".Sizebucket"), 2, '0') + "_qty"
1558 *lcSizeQty= STR(EVALUATE(pceipcTD + ".total_qty"))
1559 lnSizeQty = EVALUATE(pceipcTD + ".Qty_change")
1560*!* lcReplaceStr= "Replace " + lcSizeStr + " With " + lcSizeStr +;
1561*!* " + " + lcSizeQty + ",Total_qty With Total_qty+ " + lcSizeQty +;
1562*!* " In " + pcOrdDtl
1563 replace (lcSizeStr) WITH EVALUATE(lcSizeStr) + lnSizeQty ,;
1564 Total_qty WITH Total_qty + lnSizeQty ;
1565 Qty_change WITH Qty_change + lnSizeQty IN (pcOrdDtl)
1566 ENDIF
1567 ENDSCAN
1568
1569 *--- 850 Multiple Prepack Implosion
1570 * 4. mark all qualify order line with same style,lable with number of colors
1571 * for Multi color pack match
1572 IF RECC(pcOrdDtl)>0
1573 GO TOP IN (pcOrdDtl)
1574 *- Group by color code as well, one color per prepack ???
1575 IF .lSingleColorMultiPrepack
1576 lcSQLString= "SELECT fkey, style, color_code, lbl_code, COUNT(*) as col_cnt FROM " + pcOrdDtl +;
1577 " GROUP BY fkey, style, color_code, lbl_code HAVING COUNT(*) > 1 "
1578 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "_MultCol",, .T.) && local
1579 SELECT _MultCol
1580 SCAN
1581 REPLACE col_cnt WITH _MultCol.col_cnt ;
1582 FOR STR(fkey)+STYLE+color_code+lbl_code= ;
1583 (STR(_MultCol.fkey)+_MultCol.STYLE+_MultCol.color_code+_MultCol.lbl_code) ;
1584 IN (pcOrdDtl)
1585 ENDSCAN
1586 ELSE
1587 lcSQLString= "SELECT fkey, style, lbl_code, COUNT(*) as col_cnt FROM " + pcOrdDtl +;
1588 " GROUP BY fkey, style, lbl_code HAVING COUNT(*) > 1 "
1589 llRetVal= llRetVal AND v_SqlExec(lcSQLString, "_MultCol",, .T.) && local
1590 SELECT _MultCol
1591 SCAN
1592 REPLACE col_cnt WITH _MultCol.col_cnt ;
1593 FOR STR(fkey)+STYLE+lbl_code= ;
1594 (STR(_MultCol.fkey)+_MultCol.STYLE+_MultCol.lbl_code) ;
1595 IN (pcOrdDtl)
1596 ENDSCAN
1597 ENDIF
1598 ENDIF
1599 ENDIF
1600 .TableClose('_TmpCursor')
1601 .TableClose('tcPPKSKU')
1602 .TableClose('_DtlImpl')
1603 .TableClose('_MultCol')
1604 ENDIF
1605 ENDWITH
1606
1607 SELECT(lnOldSelect)
1608 RETURN llRetVal
1609 ENDPROC
1610
1611 ************************************************************************************
1612 * Only for multi records color prepack match:
1613 ************************************************************************************
1614 *- Step 1. Color(Exact), Label(Exact), Dimension(Exact)
1615 *- Step 2. Color(BLANK), Label(BLANK), Dimension(Exact)
1616 *- Step 3. Color(Exact), Label("ALL"), Dimension(Exact)
1617 *- Step 4. Color("ALL"), Label(Exact), Dimension(Exact)
1618 *- Step 5. Color("ALL"), Label("ALL"), Dimension(Exact)
1619 *- Notes: Optimizing for client that does NOT USE Prepack Any logic,
1620 *- base on .lMultiPrepackAny to continue step 3- 5 or not.
1621 *
1622 * Need to record all posible match for each color within style (ambiguous)
1623 * any ambiguous (ppk_status='M') or missing color (ppk_status='F')
1624 * All evaluation base on the entire style (multi color/lbl/dim).
1625 * For any style that have no match (ppk_status='') will continue latter with single
1626 * record match
1627 *
1628 *- Use ppk_status for Multi record match:
1629 *- "1": Found one match (Good)
1630 *- "M": Found many match
1631 *- "F": Found many match but cannot use any of them
1632 *- "" : Not Found (will continue on next pass- single color prepack match)
1633 ***********************************************************************************
1634 PROCEDURE ImplosionMultiPrepack
1635 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcPrePack, pcOrdDtl
1636 LOCAL llRetVal, lnOldSelect, lcCurDtlPkey, lcPrepack, lcCurStyleColor, loOrder, ;
1637 lnPackMultiple, llFoundPrepack, lcSize_desc, lnSizeBucket, llUseCustomerLabel, ;
1638 lcCustomerLabel, lcPPKSearch, lcErrorMsg, lcMultPPKColor
1639 llRetVal = .T.
1640 lnOldSelect = SELECT()
1641 WITH THIS
1642 lcEnt_user= EDI_USER
1643 SELECT (pcPrePack)
1644 SET ORDER TO ColLblDim && resolve prepack by division,color,Label
1645 SELECT (pceipcTD)
1646 .PushRecordSet()
1647 SET ORDER TO dtlpkey && by dtlpkey
1648 .lAmbiguousPrepack= .F.
1649
1650 IF USED(pcPrePack) AND USED(pcOrdDtl) && could have nothing to do
1651 SELECT (pcOrdDtl) && Horizontal size cursor that group lines in order to find prepack
1652 * ONLY Multi Colors style order line will be qualify to for Multi color prepack match
1653 SET FILTER TO col_cnt>0
1654 GO TOP IN (pcOrdDtl)
1655 SCAN
1656 STORE "" TO lcErrorMsg, lcPPKSearch, lcPrepack, lcSize_desc, lcMultPPKColor
1657 lnSizeBucket= 0
1658 llFoundPrepack= .F.
1659 SCATTER NAME loOrder
1660
1661 *- Step 1. Color(Exact), Label(Exact), Dimension(Exact) {compare with Prepack detail}
1662 *- Label could get it label from CustSKU or 850 Control (Cust label)
1663 *- ie. col: RED, lbl: KU (KIDsR US), Dim:
1664 lcCustomerLabel= "" && loOrder.sub_lbl && store customer label from 850 control
1665 llUseCustomerLabel= !EMPTY(lcCustomerLabel)
1666 lcCustomerLabel= IIF(llUseCustomerLabel, lcCustomerLabel, loOrder.lbl_code) && or tran detail
1667 llFoundPrepack=.GetPrepack( loOrder.division, loOrder.color_code, ;
1668 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1669 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch, .T., @lcMultPPKColor)
1670 IF llFoundPrepack
1671 .UpdateResolvedPrepack(lnSizeBucket, lcSize_desc, lcPrepack, lcPPKSearch, lcMultPPKColor,;
1672 pcOrdDtl)
1673 ENDIF
1674
1675 *--- PL 11/28/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1676 *- Step 2. Color(BLANK), Label(BLANK), Dimension(Exact)
1677 *- ie. col: BLANK, lbl: BLANK, Dim: EXACT
1678 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && Prepack BLANK LABEL && TR 1016560 nh
1679 lcColorMatch= SPACE(LEN(loOrder.sub_color)) && Prepack BLANK Color
1680 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1681 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1682 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch, .T., @lcMultPPKColor)
1683 IF llFoundPrepack
1684 .UpdateResolvedPrepack(lnSizeBucket, lcSize_desc, lcPrepack, lcPPKSearch, lcMultPPKColor,;
1685 pcOrdDtl)
1686 ENDIF
1687 *=== PL 11/28/02 35734
1688
1689 *--- PL 12/06/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1690 *-- optimizing for client that does NOT USE Prepack Any logic, no need to continue step 3- 5.
1691 IF .lMultiPrepackAny
1692 *- Step 3. Color(Exact), Label("ALL"), Dimension(Exact)
1693 *- ie. col: RED, lbl: ALL , Dim:
1694 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
1695 llFoundPrepack=.GetPrepack( loOrder.division, loOrder.color_code, ;
1696 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1697 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch, .T., @lcMultPPKColor)
1698 IF llFoundPrepack
1699 .UpdateResolvedPrepack(lnSizeBucket, lcSize_desc, lcPrepack, lcPPKSearch, lcMultPPKColor,;
1700 pcOrdDtl)
1701 ENDIF
1702
1703 *--- PL 11/28/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1704 *- Step 4. Color("ALL"), Label(Exact), Dimension(Exact)
1705 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
1706 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1707 loOrder.lbl_code, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1708 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch, .T., @lcMultPPKColor)
1709 IF llFoundPrepack
1710 .UpdateResolvedPrepack(lnSizeBucket, lcSize_desc, lcPrepack, lcPPKSearch, lcMultPPKColor,;
1711 pcOrdDtl)
1712 ENDIF
1713 *=== PL 11/28/02 35734
1714
1715 *--- PL 11/28/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1716 *- Step 5. Color("ALL"), Label("ALL"), Dimension(Exact)
1717 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
1718 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
1719 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1720 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1721 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch, .T., @lcMultPPKColor)
1722 IF llFoundPrepack
1723 .UpdateResolvedPrepack(lnSizeBucket, lcSize_desc, lcPrepack, lcPPKSearch, lcMultPPKColor,;
1724 pcOrdDtl)
1725 ENDIF
1726 ENDIF && lMultiPrepackAny - only when Prepack Any logic exist
1727 *=== PL 12/06/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1728
1729 ENDSCAN
1730
1731 *--reset filter
1732 SELECT (pcOrdDtl)
1733 SET FILTER TO
1734 GO TOP IN (pcOrdDtl)
1735
1736 *--- PL 12/06/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1737 llRetVal= llRetVal AND .MultiPrepackEvaluating(pcOrdDtl, pceipcTD, pcPrePack)
1738 llRetVal= llRetVal AND .MultiPrepackAmbiguous(pcOrdDtl, pceipcTD)
1739 llRetVal= llRetVal AND .MultiPrepackMissing(pcOrdDtl, pceipcTD)
1740 *-- When run into one record Mod() to diff. number than other record for same style
1741 *-- due to resolving/narrow down of multiple match
1742 *-- then need to implement (Will take more time)
1743 *--- 39548 06/03/03 YIK
1744 *-- Verify Min_multiple by style/ resolved prepack prior implosion as the last check
1745 llRetVal= llRetVal AND .MultiPrepackMinMultiple(pcOrdDtl, pceipcTD, pcPrePack)
1746 *=
1747 llRetVal= llRetVal AND .MultiPrepackFinalize(pcOrdDtl, pceipcTD)
1748 *=== PL 12/06/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1749
1750 ENDIF
1751
1752 SELECT (pceipcTD)
1753 .PopRecordSet()
1754
1755 ENDWITH
1756 SELECT(lnOldSelect)
1757 RETURN llRetVal
1758 ENDPROC
1759
1760 ************************************************************************************
1761 * For single record match (Prepack detail with only one record) the below show steps
1762 * when it found a match and all buckets divisible evently will not continue.
1763 * Which is difference than multi records match will try to find all matches at
1764 * all levels, then eliminate by narrow down to the correct one if posible.
1765 *- Step 1. Color(Exact), Label(NONE BLANK), Dimension(Exact) {cust label from zzeipocr)
1766 *- Step 2. Color(Exact), Label(BLANK), Dimension(Exact)
1767 *- Step 3. Color(BLANK), Label(BLANK), Dimension(Exact)
1768 *- Step 4. Color(Exact), Label(ALL), Dimension(Exact)
1769 *- Step 5. Color(ALL), Label(Exact), Dimension(Exact)
1770 *- Step 6. Color(ALL), Label(ALL), Dimension(Exact)
1771 *- Notes: Optimizing for client that does NOT USE Prepack Any logic,
1772 *- base on .lSinglePrepackAny to continue step 4- 6 or not.
1773 ***********************************************************************************
1774 PROCEDURE ImplosionSinglePrepack
1775 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcPrePack, pcOrdDtl
1776 LOCAL llRetVal, lnOldSelect, lcCurDtlPkey, lcPrepack, lcCurStyleColor, loOrder, ;
1777 lnPackMultiple, llFoundPrepack, lcSize_desc, lnSizeBucket, llUseCustomerLabel, ;
1778 lcCustomerLabel, lcPPKSearch, lcErrorMsg
1779 llRetVal = .T.
1780 lnOldSelect = SELECT()
1781 WITH THIS
1782 lcEnt_user= EDI_USER
1783 SELECT (pcPrePack)
1784 SET ORDER TO ColLblDim && resolve prepack by division,color,Label
1785 SELECT (pceipcTD)
1786 .PushRecordSet()
1787 SET ORDER TO dtlpkey && by dtlpkey
1788
1789 .lAmbiguousPrepack= .F. && 28265 09/12/02
1790
1791 IF USED(pcOrdDtl) && could have nothing to do
1792 SELECT (pcOrdDtl) && Horizontal size cursor that group lines in order to find prepack
1793 SET FILTER TO col_cnt=0 && ?RON: WILL NOT SEE Multi COLOR Prepack eligigle record
1794 GO TOP
1795 SCAN
1796
1797 *--- 32617 07/10/02 PL 850 PPK Implosion - Modify logic to limit valid
1798 *--- choices by '850 Control Resolve Label'
1799 STORE "" TO lcErrorMsg, lcPPKSearch, lcPrepack, lcSize_desc
1800 lnSizeBucket= 0
1801 lcCurDtlPkey= &pcOrdDtl..pkey
1802 lcImplosion= &pcOrdDtl..impl_ok && -- added line_status && implosion status "O"pen stock, "Y", "N"
1803 *-- TR 1046794 APR-23-2010 BR
1804 lnCurDtlPrice = &pcOrdDtl..price
1805 lnCurDtlRetail = &pcOrdDtl..retail1
1806 lnCurDtlRetail2 = &pcOrdDtl..retail2 &&--- TechRec 1054692 21-Sep-2011 jisingh ===
1807 *==
1808
1809 SCATTER NAME loOrder
1810
1811 llFoundPrepack= .F.
1812 lcCustomerLabel= "" && loOrder.sub_lbl && store customer label from 850 control
1813 llUseCustomerLabel= !EMPTY(lcCustomerLabel)
1814
1815 *--- 28265 09/12/02 PL -- 850 complex Implosion
1816 *-- or 850 trans have label (SKU/UPC -> d,s,c,l (none blank),)
1817
1818 *- Step 1. Color(Exact), Label(NONE BLANK), Dimension(Exact) {compare with Prepack detail}
1819 *- Label(NONE BLANK) could get it label from CustSKU or 850 Control (Cust label)
1820 lcCustomerLabel= IIF(llUseCustomerLabel, lcCustomerLabel, loOrder.lbl_code)
1821 IF NOT EMPTY(lcCustomerLabel) && Use Customer Label From 850 control ref.
1822 llFoundPrepack=.GetPrepack( loOrder.division, loOrder.color_code, ;
1823 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1824 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1825 ENDIF
1826
1827 *- Step 2. Color(Exact), Label(BLANK), Dimension(Exact)
1828 IF NOT llFoundPrepack && NO Prepack found then
1829 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && Prepack BLANK LABEL
1830 llFoundPrepack=.GetPrepack( loOrder.division, loOrder.color_code, ;
1831 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1832 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1833 ENDIF
1834
1835 *- Step 3. Color(BLANK), Label(BLANK), Dimension(Exact)
1836 IF NOT llFoundPrepack && NO Prepack found then
1837 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && Prepack BLANK LABEL
1838 lcColorMatch= SPACE(LEN(loOrder.sub_color)) && Prepack BLANK Color
1839 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1840 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1841 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1842
1843 *--- TR 1041965 AUG-17-2009 BR
1844 IF !EMPTY(loOrder.lbl_code)
1845 lcCustomerLabel= loOrder.lbl_code
1846 ENDIF
1847 *=== TR 1041965 AUG-17-2009 BR
1848 ENDIF
1849
1850 *--- PL 12/06/02 35734 - 850 Inbound implosion of Prepack - single color with multi dimension
1851 *-- optimizing for client that does NOT USE Prepack Any logic, no need to continue step 4- 6.
1852 IF .lSinglePrepackAny
1853 *- Step 4. Color(Exact), Label(ALL), Dimension(Exact)
1854 *- ie. col: RED, lbl: ALL, Dim:
1855 IF NOT llFoundPrepack && NO Prepack found then
1856 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
1857 llFoundPrepack=.GetPrepack( loOrder.division, loOrder.color_code, ;
1858 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1859 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1860 lcCustomerLabel= loOrder.lbl_code && actual label to use from trans detail component
1861 ENDIF
1862
1863 *- Step 5. Color(ALL), Label(Exact), Dimension(Exact)
1864 *- ie. col: ALL, lbl: KU, Dim:
1865 IF NOT llFoundPrepack && NO Prepack found then
1866 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
1867 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1868 loOrder.lbl_code, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1869 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1870 ENDIF
1871
1872 *- Step 6. Color(ALL), Label(ALL), Dimension(Exact)
1873 *- ie. col: ALL, lbl: ALL, Dim:
1874 IF NOT llFoundPrepack && NO Prepack found then
1875 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
1876 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
1877 llFoundPrepack=.GetPrepack( loOrder.division, lcColorMatch, ;
1878 lcCustomerLabel, loOrder.DIMENSION, pcPrePack, pcOrdDtl, ;
1879 @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
1880 lcCustomerLabel= loOrder.lbl_code && actual label to use from trans detail component
1881 ENDIF
1882 ENDIF && .lSinglePrepackAny - only when Prepack Any logic exist
1883 *=== PL 12/06/02 35734
1884
1885 *-- Finallize the results of single record match:
1886 *-- llFoundPrepack - True: when found one or more match from the previous steps
1887 *-- lAmbiguousPrepack - True: when found more match from the previous steps.
1888 *-- Ambiguous only when find many matches at the same level.
1889 * seek to 1st record in trans. detail using dtlpkey
1890 * either replace with error message or remove them and insert with new
1891 * prepack trans. detail
1892 SELECT (pceipcTD)
1893 IF SEEK(lcCurDtlPkey, pceipcTD, "DtlPkey")
1894
1895 *-- Update trans. with error msg: No prepack found or Ambiguous prepack found:
1896 IF (NOT llFoundPrepack) OR (.lAmbiguousPrepack) && Empty(lcPrepack) && no prepack found
1897 * Only error out when Implosion set "Y", when set "O"pen stock skip error
1898 IF lcImplosion= "Y"
1899 SCAN WHILE dtlpkey= lcCurDtlPkey
1900 IF NOT llFoundPrepack
1901 lcErrorMsg= NO_PREPACK + CRLF && "Searching Prepacks below: " + CRLF + lcPPKSearch
1902 ELSE
1903 lcErrorMsg= lcPPKSearch
1904 ENDIF
1905
1906 *- 1005452 06/04/04 YIK
1907 *- Concatenate error message, not overwrite
1908 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH Errs_Msg_D + CRLF + lcErrorMsg IN (pceipcTD)
1909
1910 *--- PL 02/05/03 36302 -- check for each prepack that it resolve the SKU is in scolr
1911 IF .lAmbiguousPrepack
1912 lcTmpStr= STRTRAN(lcPPKSearch, "Ambiguous Prepacks: ", "")
1913 lcTmpStr= STRTRAN(lcTmpStr, CRLF , "")
1914 REPLACE avail_ppk WITH lcTmpStr IN (pceipcTD)
1915
1916 *--- 1050956 24-Nov-10 SK Mark as Ambiguous. Won't process further ===
1917 Replace ppk_status With 'M' In (pcOrdDtl)
1918 ENDIF
1919 *=== PL 02/05/03 36302 -- check for each prepack that it resolve the SKU is in scolr
1920
1921 ENDSCAN
1922 ENDIF
1923 ELSE
1924
1925 *-- Found prepack:
1926 * - remove all trans detail records for same detail line by DtlPkey
1927 * - insert new trans. detail from (Implode many components into single prepack)
1928 lcDoc_num= &pceipcTD..doc_num
1929 lnPkey= v_nextPkey("ZZEIPCTD") && &pceipcTD..pkey
1930 lnFkey= &pceipcTD..fkey
1931 DELETE FOR dtlpkey= lcCurDtlPkey IN (pceipcTD)
1932 SELECT (pceipcTD)
1933 APPEND BLANK
1934 GATHER NAME loOrder
1935 *- 1001378 11/24/03 YIK
1936 *- Add ..implosion with "Y" to the replace to indicate that the item was imploded.
1937 *-- TR 1046794 APR-23-2010 BR - ADDED poc_cost and poc_price
1938 *--- TechRec 1054692 21-Sep-2011 jisingh Added poc_retail2 WITH IIF(qualifier = 'AI',lnCurDtlRetail2,poc_retail2) ===
1939 REPLACE lbl_code WITH lcCustomerLabel, ; && 28265 09/12/02
1940 DIMENSION WITH lcPrepack, doc_num WITH lcDoc_num,;
1941 Sizebucket WITH lnSizeBucket, size_desc WITH lcSize_desc,;
1942 pkey WITH lnPkey, fkey WITH lnFkey, ; && done using it for customer label
1943 User_id WITH lcEnt_user, Last_mod WITH DATETIME(), ;
1944 implosion WITH "Y", ;
1945 Errs_Flg_D WITH "N", Errs_Msg_D WITH "" , ;
1946 poc_cost WITH IIF(qualifier = 'AI',lnCurDtlPrice,poc_cost) , ;
1947 poc_price WITH IIF(qualifier = 'AI',lnCurDtlRetail,poc_price), ;
1948 poc_retail2 WITH IIF(qualifier = 'AI',lnCurDtlRetail2,poc_retail2) IN (pceipcTD)
1949 ENDIF
1950 ENDIF
1951
1952 ENDSCAN && Each temp order detail
1953
1954 *--Reset filter
1955 SELECT (pcOrdDtl) && Horizontal size cursor that group lines in order to find prepack
1956 SET FILTER TO
1957 GO TOP IN (pcOrdDtl)
1958
1959 ENDIF
1960
1961 SELECT (pceipcTD)
1962 .PopRecordSet()
1963
1964 ENDWITH
1965 SELECT(lnOldSelect)
1966 RETURN llRetVal
1967 ENDPROC
1968
1969 PROCEDURE ImplosionSingleSizePrepackWithPrepackAny
1970 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcPrePack, pcOrdDtl
1971 LOCAL llRetVal, lnOldSelect, lcCurDtlPkey, lcPrepack, lcCurStyleColor, loOrder, ;
1972 lnPackMultiple, llFoundPrepack, lcSize_desc, lnSizeBucket, llUseCustomerLabel, ;
1973 lcCustomerLabel, lcPPKSearch, lcErrorMsg
1974 *- NOTE: pcPrepack contains only single-size prepacks
1975 llRetVal = .T.
1976 lnOldSelect = SELECT()
1977 WITH THIS
1978 lcEnt_user= EDI_USER
1979 SELECT (pcPrePack)
1980 SET ORDER TO CompSKU && resolve prepack by division,style,color
1981 SELECT (pceipcTD)
1982 .PushRecordSet()
1983 SET ORDER TO dtlpkey && by dtlpkey
1984 IF USED(pcOrdDtl) && could have nothing to do
1985 SELECT (pcOrdDtl) && Vertical size cursor that group lines in order to find prepack
1986 SCAN
1987 STORE "" TO lcErrorMsg, lcPPKSearch, lcPrepack, lcSize_desc
1988 lnSizeBucket= 0
1989 lnOrigSzBucket = size_bk
1990 lcCurDtlSzPkey = STR(pkey) + STR(size_bk)
1991 lcImplosion= impl_ok
1992
1993 SCATTER NAME loOrder
1994
1995 loOrder.Sizebucket = size_bk
1996 loOrder.total_qty= Qty
1997 loOrder.Qty_change = Qty
1998 IF SEEK(lcCurDtlSzPkey, pceipcTD, "DtlSzPkey")
1999 loOrder.size_desc = &pceipcTD..size_desc
2000 ENDIF
2001 llFoundPrepack= .F.
2002 .lAmbiguousPrepack = .F.
2003
2004 lcCustomerLabel= "" && loOrder.sub_lbl && store customer label from 860 control
2005 llUseCustomerLabel= !EMPTY(lcCustomerLabel)
2006 IF llUseCustomerLabel && 1st find Customer Label Prepack when 860 customer label and implotion set
2007 llFoundPrepack=.ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2008 loOrder.color_code, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2009 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2010 ENDIF
2011
2012 IF NOT llFoundPrepack && NO Prepack found then
2013 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && (GENERIC) Prepack BLANK LABEL
2014 llFoundPrepack=.ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2015 loOrder.color_code, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2016 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2017 ENDIF
2018
2019 IF NOT llFoundPrepack && NO Prepack found then
2020 lcCustomerLabel = SPACE(LEN(loOrder.sub_lbl)) && (GENERIC) Prepack BLANK LABEL
2021 lcColorMatch = SPACE(LEN(loOrder.sub_color))
2022 llFoundPrepack = .ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2023 lcColorMatch, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2024 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2025 ENDIF
2026
2027 IF NOT llFoundPrepack && NO Prepack found then
2028 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
2029 llFoundPrepack = .ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2030 loOrder.color_code, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2031 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2032 lcCustomerLabel= loOrder.lbl_code && actual label to use from trans detail component
2033 ENDIF
2034
2035 *- Step 5. Color(ALL), Label(Exact), Dimension(Exact)
2036 *- ie. col: ALL, lbl: KU, Dim:
2037 IF NOT llFoundPrepack && NO Prepack found then
2038 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
2039 llFoundPrepack = .ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2040 lcColorMatch, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2041 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2042 ENDIF
2043
2044 *- Step 6. Color(ALL), Label(ALL), Dimension(Exact)
2045 *- ie. col: ALL, lbl: ALL, Dim:
2046 IF NOT llFoundPrepack && NO Prepack found then
2047 lcCustomerLabel= PADR("ALL",LEN(loOrder.sub_lbl))
2048 lcColorMatch= PADR("ALL",LEN(loOrder.sub_color))
2049 llFoundPrepack = .ResolveSingleSizePrepackWithPrepackAny( loOrder.division, loOrder.STYLE, ;
2050 lcColorMatch, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2051 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2052 lcCustomerLabel= loOrder.lbl_code && actual label to use from trans detail component
2053 ENDIF
2054
2055
2056 * seek to 1st record in trans. detail using dtlpkey
2057 * either replace with error message or remove them and insert with new
2058 * prepack trans. detail
2059 SELECT (pceipcTD)
2060 IF SEEK(lcCurDtlSzPkey, pceipcTD, "DtlSzPkey")
2061 IF NOT llFoundPrepack && Empty(lcPrepack) && no prepack found
2062 * Only error out when Implosion to prepack set
2063 * when set "O"pen stock skip error
2064 IF lcImplosion= "Y"
2065 lcErrorMsg= NO_PREPACK + CRLF + "Searching Prepacks below: " + CRLF + lcPPKSearch
2066 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH lcErrorMsg IN (pceipcTD) && current record only
2067 ENDIF
2068 ELSE
2069 *- Can be ambiguous
2070 IF .lAmbiguousPrepack
2071 lcErrorMsg= "Ambiguous prepack." + CRLF + "Searching Prepacks below: " + CRLF + lcPPKSearch
2072 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH lcErrorMsg IN (pceipcTD) && current record only
2073 ELSE
2074 * Found prepack:
2075 * - remove all trans detail records for same detail line by DtlPkey
2076 * - insert new trans. detail from (Implode many components into single prepack)
2077 lcDoc_num= &pceipcTD..doc_num
2078 lnPkey= v_nextPkey("ZZEIPCTD") && &pceipcTD..pkey
2079 lnFkey= &pceipcTD..fkey
2080 DELETE IN (pceipcTD) && current record only
2081 SELECT (pceipcTD)
2082 APPEND BLANK
2083 GATHER NAME loOrder
2084 REPLACE DIMENSION WITH lcPrepack, doc_num WITH lcDoc_num,;
2085 Sizebucket WITH lnSizeBucket, size_desc WITH lcSize_desc,;
2086 pkey WITH lnPkey, fkey WITH lnFkey, ; && done using it for customer label
2087 User_id WITH lcEnt_user, Last_mod WITH DATETIME(), ;
2088 implosion WITH "Y", ;
2089 Errs_Flg_D WITH "N", Errs_Msg_D WITH "" IN (pceipcTD)
2090 ENDIF
2091 ENDIF
2092 ENDIF
2093 ENDSCAN && Each temp order detail
2094 ENDIF
2095
2096 SELECT (pceipcTD)
2097 .PopRecordSet()
2098
2099 ENDWITH
2100 SELECT(lnOldSelect)
2101 RETURN llRetVal
2102 ENDPROC
2103
2104 *--- Single prepack implosion without prepack any logic (--Alpha)
2105 ************************************************************************************
2106 *
2107 ***********************************************************************************
2108 PROCEDURE ImplosionSinglePrepackWithoutPrepackAny
2109 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcPrePack, pcOrdDtl
2110 LOCAL llRetVal, lnOldSelect, lcCurDtlPkey, lcPrepack, lcCurStyleColor, loOrder, ;
2111 lnPackMultiple, llFoundPrepack, lcSize_desc, lnSizeBucket, llUseCustomerLabel, ;
2112 lcCustomerLabel, lcPPKSearch, lcErrorMsg
2113 llRetVal = .T.
2114 lnOldSelect = SELECT()
2115 WITH THIS
2116 lcEnt_user= EDI_USER
2117 SELECT (pcPrePack)
2118 SET ORDER TO CompSKU && resolve prepack by division,style,color
2119 SELECT (pceipcTD)
2120 .PushRecordSet()
2121 SET ORDER TO dtlpkey && by dtlpkey
2122
2123 IF USED(pcOrdDtl) && could have nothing to do
2124 SELECT (pcOrdDtl) && Horizontal size cursor that group lines in order to find prepack
2125 SCAN
2126
2127 *--- 860 PPK Implosion - Modify logic to limit valid
2128 *--- choices by '860 Control Resolve Label'
2129 STORE "" TO lcErrorMsg, lcPPKSearch, lcPrepack, lcSize_desc
2130 lnSizeBucket= 0
2131 lcCurDtlPkey= &pcOrdDtl..pkey
2132 *- line_status is empty which causes no error message if prepack is not found
2133 *- lcImplosion= &pcOrdDtl..line_status && implosion status "O"pen stock, "Y", "N"
2134 lcImplosion= &pcOrdDtl..impl_ok
2135 *=
2136 SCATTER NAME loOrder
2137
2138 llFoundPrepack= .F.
2139 lcCustomerLabel= "" && loOrder.sub_lbl && store customer label from 850 control
2140 llUseCustomerLabel= !EMPTY(lcCustomerLabel)
2141 IF llUseCustomerLabel && 1st find Customer Label Prepack when 850 customer label and implotion set
2142 llFoundPrepack=.ResolveSinglePrepackWithoutPrepackAny( loOrder.division, loOrder.STYLE, loOrder.color_code, ;
2143 lcCustomerLabel, pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2144 ENDIF
2145
2146 IF NOT llFoundPrepack && NO Prepack found then
2147 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && (GENERIC) Prepack BLANK LABEL
2148 llFoundPrepack=.ResolveSinglePrepackWithoutPrepackAny( loOrder.division, loOrder.STYLE, loOrder.color_code, ;
2149 lcCustomerLabel, pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2150 ENDIF
2151
2152 * seek to 1st record in trans. detail using dtlpkey
2153 * either replace with error message or remove them and insert with new
2154 * prepack trans. detail
2155 SELECT (pceipcTD)
2156 IF SEEK(lcCurDtlPkey, pceipcTD, "DtlPkey")
2157 IF NOT llFoundPrepack && Empty(lcPrepack) && no prepack found
2158 * Only error out when Implosion to prepack set
2159 * when set "O"pen stock skip error
2160 IF lcImplosion= "Y"
2161 SCAN WHILE dtlpkey= lcCurDtlPkey
2162 lcErrorMsg= NO_PREPACK + CRLF + "Searching Prepacks below: " + CRLF + lcPPKSearch
2163 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH lcErrorMsg IN (pceipcTD)
2164 ENDSCAN
2165 ENDIF
2166 ELSE
2167 * Found prepack:
2168 * - remove all trans detail records for same detail line by DtlPkey
2169 * - insert new trans. detail from (Implode many components into single prepack)
2170 lcDoc_num= &pceipcTD..doc_num
2171 lnPkey= v_nextPkey("ZZEIPCTD") && &pceipcTD..pkey
2172 lnFkey= &pceipcTD..fkey
2173 DELETE FOR dtlpkey= lcCurDtlPkey IN (pceipcTD)
2174 SELECT (pceipcTD)
2175 APPEND BLANK
2176 GATHER NAME loOrder
2177 *- Add ...implosion with "Y" to the replace to indicate that the item was imploded
2178 REPLACE DIMENSION WITH lcPrepack, doc_num WITH lcDoc_num,;
2179 Sizebucket WITH lnSizeBucket, size_desc WITH lcSize_desc,;
2180 pkey WITH lnPkey, fkey WITH lnFkey, ; && done using it for customer label
2181 User_id WITH lcEnt_user, Last_mod WITH DATETIME(), ;
2182 implosion WITH "Y", ;
2183 Errs_Flg_D WITH "N", Errs_Msg_D WITH "" IN (pceipcTD)
2184 *- Remove the imploded detail from tcOrdDtl so that the next pass deals only
2185 *- with non-imploded items
2186 DELETE IN (pcOrdDtl)
2187 ENDIF
2188 ENDIF
2189 ENDSCAN && Each temp order detail
2190 ENDIF
2191
2192 SELECT (pceipcTD)
2193 .PopRecordSet()
2194
2195 ENDWITH
2196 SELECT(lnOldSelect)
2197 RETURN llRetVal
2198 ENDPROC
2199
2200 PROCEDURE BuildVerticalOrderForPrepack
2201 LPARAMETERS tcOrdDtl, tcVertOrdDtl
2202 LOCAL llRetVal, lnOldSelect
2203 llRetVal = .T.
2204 lnOldSelect = SELECT()
2205 WITH THIS
2206 llRetVal = v_SqlExec("Select * from zzxbuckt", "tcBucket")
2207 IF llRetVal AND USED(tcOrdDtl)
2208 SELECT d.*, Size_Num AS size_bk, ;
2209 d.Size01_Qty*Sz01 + d.Size02_Qty*Sz02+ ;
2210 d.Size03_Qty*Sz03 + d.Size04_Qty*Sz04+ ;
2211 d.Size05_Qty*Sz05 + d.Size06_Qty*Sz06+ ;
2212 d.Size07_Qty*Sz07 + d.Size08_Qty*Sz08+ ;
2213 d.Size09_Qty*Sz09 + d.Size10_Qty*Sz10+ ;
2214 d.Size11_Qty*Sz11 + d.Size12_Qty*Sz12+ ;
2215 d.Size13_Qty*Sz13 + d.Size14_Qty*Sz14+ ;
2216 d.Size15_Qty*Sz15 + d.Size16_Qty*Sz16+ ;
2217 d.Size17_Qty*Sz17 + d.Size18_Qty*Sz18+ ;
2218 d.Size19_Qty*Sz19 + d.Size20_Qty*Sz20+ ;
2219 d.Size21_Qty*Sz21 + d.Size22_Qty*Sz22+ ;
2220 d.Size23_Qty*Sz23 + d.Size24_Qty*Sz24 AS Qty ;
2221 FROM (tcOrdDtl) d, tcBucket b ;
2222 WHERE d.Size01_Qty*Sz01 + d.Size02_Qty*Sz02+ ;
2223 d.Size03_Qty*Sz03 + d.Size04_Qty*Sz04+ ;
2224 d.Size05_Qty*Sz05 + d.Size06_Qty*Sz06+ ;
2225 d.Size07_Qty*Sz07 + d.Size08_Qty*Sz08+ ;
2226 d.Size09_Qty*Sz09 + d.Size10_Qty*Sz10+ ;
2227 d.Size11_Qty*Sz11 + d.Size12_Qty*Sz12+ ;
2228 d.Size13_Qty*Sz13 + d.Size14_Qty*Sz14+ ;
2229 d.Size15_Qty*Sz15 + d.Size16_Qty*Sz16+ ;
2230 d.Size17_Qty*Sz17 + d.Size18_Qty*Sz18+ ;
2231 d.Size19_Qty*Sz19 + d.Size20_Qty*Sz20+ ;
2232 d.Size21_Qty*Sz21 + d.Size22_Qty*Sz22+ ;
2233 d.Size23_Qty*Sz23 + d.Size24_Qty*Sz24 > 0 ;
2234 AND d.ppk_status = ' ' ; && 1050956 24-Nov-10 SK Exclude ambiguous ppks
2235 INTO CURSOR (tcVertOrdDtl)
2236
2237 ENDIF
2238 ENDWITH
2239 SELECT(lnOldSelect)
2240 RETURN llRetVal
2241 ENDPROC
2242
2243 ***********************************************************************************************************
2244
2245 PROCEDURE ImplosionSingleSizePrepackWithoutPrepackAny
2246 LPARAMETERS pceipcTH, pceipcTD, pceipcCR, pcPrePack, pcOrdDtl
2247 LOCAL llRetVal, lnOldSelect, lcCurDtlPkey, lcPrepack, lcCurStyleColor, loOrder, ;
2248 lnPackMultiple, llFoundPrepack, lcSize_desc, lnSizeBucket, llUseCustomerLabel, ;
2249 lcCustomerLabel, lcPPKSearch, lcErrorMsg
2250 *- NOTE: pcPrepack contains only single-size prepacks
2251 llRetVal = .T.
2252 lnOldSelect = SELECT()
2253 WITH THIS
2254 lcEnt_user= EDI_USER
2255 SELECT (pcPrePack)
2256 SET ORDER TO CompSKU && resolve prepack by division,style,color
2257 SELECT (pceipcTD)
2258 .PushRecordSet()
2259 SET ORDER TO dtlpkey && by dtlpkey
2260
2261 IF USED(pcOrdDtl) && could have nothing to do
2262 SELECT (pcOrdDtl) && Vertical size cursor that group lines in order to find prepack
2263 SCAN
2264 STORE "" TO lcErrorMsg, lcPPKSearch, lcPrepack, lcSize_desc
2265 lnSizeBucket= 0
2266 lnOrigSzBucket = size_bk
2267 lcCurDtlSzPkey = STR(pkey) + STR(size_bk)
2268 lcImplosion= impl_ok
2269
2270 SCATTER NAME loOrder
2271
2272 loOrder.Sizebucket = size_bk
2273 loOrder.total_qty= Qty
2274 loOrder.Qty_change = Qty
2275 IF SEEK(lcCurDtlSzPkey, pceipcTD, "DtlSzPkey")
2276 loOrder.size_desc = &pceipcTD..size_desc
2277 ENDIF
2278 llFoundPrepack= .F.
2279 lcCustomerLabel= "" && loOrder.sub_lbl && store customer label from 850 control
2280 llUseCustomerLabel= !EMPTY(lcCustomerLabel)
2281 IF llUseCustomerLabel && 1st find Customer Label Prepack when 850 customer label and implotion set
2282 llFoundPrepack=.ResolveSingleSizePrepackWithoutPrepackAny( loOrder.division, loOrder.STYLE, ;
2283 loOrder.color_code, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2284 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2285 ENDIF
2286
2287 IF NOT llFoundPrepack && NO Prepack found then
2288 lcCustomerLabel= SPACE(LEN(loOrder.sub_lbl)) && (GENERIC) Prepack BLANK LABEL
2289 llFoundPrepack=.ResolveSingleSizePrepackWithoutPrepackAny( loOrder.division, loOrder.STYLE, ;
2290 loOrder.color_code, lcCustomerLabel, loOrder.size_bk, loOrder.size_desc, ;
2291 pcPrePack, pcOrdDtl, @lnSizeBucket, @lcSize_desc, @lcPrepack, @lcPPKSearch)
2292 ENDIF
2293 *=== 32617 07/10/02 PL
2294
2295 * seek to 1st record in trans. detail using dtlpkey
2296 * either replace with error message or remove them and insert with new
2297 * prepack trans. detail
2298 SELECT (pceipcTD)
2299 IF SEEK(lcCurDtlSzPkey, pceipcTD, "DtlSzPkey")
2300 IF NOT llFoundPrepack && Empty(lcPrepack) && no prepack found
2301 * Only error out when Implosion to prepack set
2302 * when set "O"pen stock skip error
2303 IF lcImplosion= "Y"
2304 lcErrorMsg= NO_PREPACK + CRLF + "Searching Prepacks below: " + CRLF + lcPPKSearch
2305 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH lcErrorMsg IN (pceipcTD) && current record only
2306 ENDIF
2307 ELSE
2308 * Found prepack:
2309 * - remove all trans detail records for same detail line by DtlPkey
2310 * - insert new trans. detail from (Implode many components into single prepack)
2311 lcDoc_num= &pceipcTD..doc_num
2312 lnPkey= v_nextPkey("ZZEIPCTD") && &pceipcTD..pkey
2313 lnFkey= &pceipcTD..fkey
2314 DELETE IN (pceipcTD) && current record only
2315 SELECT (pceipcTD)
2316 APPEND BLANK
2317 GATHER NAME loOrder
2318 *- 1001378 11/24/03 YIK
2319 *- Add ...implosion with "Y" to the replace to indicate that the item was imploded
2320 REPLACE DIMENSION WITH lcPrepack, doc_num WITH lcDoc_num,;
2321 Sizebucket WITH lnSizeBucket, size_desc WITH lcSize_desc,;
2322 pkey WITH lnPkey, fkey WITH lnFkey, ; && done using it for customer label
2323 User_id WITH lcEnt_user, Last_mod WITH DATETIME(), ;
2324 implosion WITH "Y", ;
2325 Errs_Flg_D WITH "N", Errs_Msg_D WITH "" IN (pceipcTD)
2326
2327 ENDIF
2328 ENDIF
2329 ENDSCAN && Each temp order detail
2330 ENDIF
2331
2332 SELECT (pceipcTD)
2333 .PopRecordSet()
2334
2335 ENDWITH
2336 SELECT(lnOldSelect)
2337 RETURN llRetVal
2338 ENDPROC
2339
2340
2341 ************************************************************************************
2342 *
2343 ***********************************************************************************
2344 PROCEDURE GetPrepack
2345 PARAMETERS pcDivision, pcColor_code, pcLbl_code, pcDimension, ;
2346 pcPrepackAlias, pcOrdDtlAlias, ;
2347 pcSizeBucket, pcSize_desc, pcPrePack, pcPPKSearch, plMultiColorComp, pcMultPPKColor
2348
2349 LOCAL llRetVal, lnOldSelect, lcPrepack, lcCurStyColLbl, lnPackMultiple, llEligiblePrepack, ;
2350 lnMatchPPK, lcCurPPK_code, lnPrepacks, lnxx, lcOurSKU, llFound
2351 llEligiblePrepack= .F.
2352 lnOldSelect = SELECT()
2353 WITH THIS
2354 pcPrePack= ""
2355 pcSize_desc= ""
2356 pcSizeBucket= 0
2357
2358 DIMENSION .aPrepacks[1]
2359 STORE .F. TO .aPrepacks
2360 lcCurPPK_code= ""
2361 lnMatchPPK= 0
2362 lnPrepacks= 0
2363
2364 lcColLblDim= pcDivision + pcColor_code + pcLbl_code + pcDimension
2365
2366 * Find prepack matching division,color,label (Group/order by fkey- diff. prepack)
2367 IF USED(pcPrepackAlias) AND SEEK(lcColLblDim, pcPrepackAlias, "ColLblDim")
2368
2369 SELECT (pcPrepackAlias)
2370 * Found prepack of same div,color,label,dimension
2371 SCAN WHILE (division + color_code + lbl_code + DIMENSION == lcColLblDim)
2372 IF NOT (ppk_code == lcCurPPK_code)
2373 lcCurPPK_code= &pcPrepackAlias..ppk_code
2374 lcCurColor_code = IIF(&pcPrepackAlias..Mulcllb_Ok='Y' AND UPPER(pcPrepackAlias)= "TCMULTPPK" ;
2375 AND !EMPTY(&pcPrepackAlias..PPK_color), ;
2376 &pcPrepackAlias..PPK_color, &pcOrdDtlAlias..color_code)
2377 ENDIF
2378
2379 * Verify total and all size bucket divide evently by prepack qty
2380 llEligiblePrepack= .VerifyPrepackBuckets(pcOrdDtlAlias, pcPrepackAlias, plMultiColorComp)
2381
2382 *--- check for each prepack that it resolve the SKU is in scolr
2383 IF llEligiblePrepack
2384 lcOurSKU= &pcOrdDtlAlias..division + &pcOrdDtlAlias..STYLE + ;
2385 lcCurColor_code + &pcOrdDtlAlias..lbl_code + lcCurPPK_code
2386
2387 *- FH 1073662 - added AND tcQPPKSKU.size_code = tcSnglPPK.size_code
2388 llFound= SEEK(lcOurSKU, .cQualPPKSkus, "OurSKU") AND tcQPPKSKU.active_ok = 'Y' AND tcQPPKSKU.size_code = EVALUATE(pcPrepackAlias + '.size_code')
2389
2390 IF !llFound AND THIS.lMultipack
2391 lcMultStylPPK = &pcOrdDtlAlias..STYLE+lcCurPPK_code
2392 llFound= SEEK(lcMultStylPPK , .cMPPK, "MStyPPK")
2393 ENDIF
2394 llEligiblePrepack= IIF(llFound, .T., .F.) && turn prepack to NOT eligible if SKU not setup
2395 ENDIF
2396 * Load all eligible prepacks to array
2397 * could have many prepacks that sastisfy this keys, but that mean ambiguous prepack
2398 * condition for ambiguous: when aPrepacks[] > 1
2399 IF llEligiblePrepack
2400 lnMatchPPK= lnMatchPPK + 1
2401 DIMENSION .aPrepacks[lnMatchPPK]
2402 .aPrepacks[lnMatchPPK]= lcCurPPK_code && store all eligible prepacks
2403 IF lnMatchPPK=1
2404 .aPrepackRecno= RECNO(pcPrepackAlias) && store 1st prepack record pointer
2405 .cPPK_color= IIF(plMultiColorComp, &pcPrepackAlias..PPK_color, "")
2406 ENDIF
2407 * logging found eligible prepack
2408 IF NOT plMultiColorComp
2409 pcPPKSearch= pcPPKSearch + IIF(EMPTY(pcPPKSearch),"", CRLF) + "Div: " + division + "," +;
2410 " Col: " + color_code + "," + " Lbl: " + lbl_code + "," + " Dim: " + DIMENSION + "," +;
2411 "PPK: " + lcCurPPK_code + " Pack Units: " + ALLT(STR(pack_qty))
2412 ELSE
2413 pcPPKSearch= pcPPKSearch + IIF(EMPTY(pcPPKSearch),"",",") + lcCurPPK_code
2414 ENDIF
2415 ENDIF
2416 ENDSCAN
2417
2418 ELSE
2419 * logging not found eligible prepack
2420 IF NOT plMultiColorComp
2421 pcPPKSearch= pcPPKSearch + IIF(EMPTY(pcPPKSearch),"", CRLF) + "Div: " + division + "," +;
2422 " Col: " + color_code + "," + " Lbl: " + lbl_code + "," + " Dim: " + DIMENSION + "," +;
2423 "PPK: (NOT FOUND)"
2424 ENDIF
2425 ENDIF
2426
2427 * aPrepack[] - have exactly one match, good single prepack to use
2428 * aPrepack[] - have more than one matches, Ambiguous Prepack error out.
2429 lnPrepacks= ALEN(.aPrepacks, 1)
2430 llEligiblePrepack= .F.
2431
2432 * need all attribute of prepacks event when multiple prepacks found
2433 IF NOT EMPTY(.aPrepacks[1])
2434 * Find 1st avail buckets and desc to store prepack items latter
2435 lnFirstAvlBucket= 1 && unable to join to scolr because of "ALL" at("Y", &pcPrepackAlias..sizes, 1)
2436 lcSizeStr= pcPrepackAlias+ ".size"+ PADL(lnFirstAvlBucket, 2, '0')
2437 pcSizeBucket= lnFirstAvlBucket
2438 IF .aPrepackRecno> 0
2439 GO (.aPrepackRecno) IN (pcPrepackAlias)
2440 ENDIF
2441 pcSize_desc= EVAL(lcSizeStr)
2442 pcPrePack= .aPrepacks[1]
2443 pcMultPPKColor= .cPPK_color
2444 ENDIF
2445
2446 * when found one eligible prepack, then load to output parameters:
2447 * pcSizeBucket, pcSize_desc, pcPrepack, pcPPKSearch
2448 IF lnPrepacks= 1
2449 llEligiblePrepack= IIF(NOT EMPTY(.aPrepacks[1]), .T., .F.)
2450 .lAmbiguousPrepack= .F.
2451 ELSE
2452 * when found multiple eligible prepack (Ambiguous prepack), then load to output paramters:
2453 * pcSizeBucket, pcSize_desc, pcPrepack with blanks,
2454 * pcPPKSearch with all prepack codes (for user to reporting and make manual adjustment)
2455 llEligiblePrepack= .T.
2456 .lAmbiguousPrepack= .T.
2457 lcAmbiguousPPK= ""
2458 FOR lnxx=1 TO lnPrepacks
2459 lcAmbiguousPPK= lcAmbiguousPPK + IIF(EMPTY(lcAmbiguousPPK), "" , ",") + .aPrepacks[lnxx]
2460 ENDFOR
2461 lcCurDtlPkey= &pcOrdDtlAlias..pkey
2462
2463 * only single color prepack match will fail for Ambiguous at this point
2464 * but not multi color prepack match, need to do more evaluation prior to this group
2465 * of prepack will fail
2466 IF plMultiColorComp
2467 pcPPKSearch= lcAmbiguousPPK
2468 ELSE
2469 pcPPKSearch= "Ambiguous Prepacks: " + lcAmbiguousPPK + CRLF
2470 ENDIF
2471 ENDIF
2472
2473 ENDWITH
2474 SELECT(lnOldSelect)
2475 RETURN llEligiblePrepack && Return TRUE when one or more than one prepack match(s)
2476 ENDPROC
2477
2478 ***********************************************************************************
2479 *
2480 ***********************************************************************************
2481 *--- 860 Inbound implosion of Prepack - single color with multi dimension
2482 PROCEDURE UpdateResolvedPrepack
2483 LPARAMETERS pnSizeBucket, pcSize_desc, pcPrePack, pcPPKSearch, pcMultPPKColor, pcOrdDtl
2484 LOCAL llRetVal, lnOldSelect, lcPrevPPK_status, lcNotes, lcPrevSinglPPK_code, lcPrevMultlPPK_code
2485 llRetVal = .T.
2486 lnOldSelect = SELECT()
2487 WITH THIS
2488
2489 * Should be on proper record in (pcOrdDtl)
2490 lcPrevPPK_status= &pcOrdDtl..ppk_status
2491 lcPrevSinglPPK_code= &pcOrdDtl..ppk_code
2492 lcPrevMultlPPK_code= &pcOrdDtl..notes
2493
2494 * consolidate all resolved prepack at difference level together.
2495 DO CASE
2496
2497 *- 1st time order line resolve to prepack, current level could be single or multiple
2498 *- as original code was prior 11/28/02
2499 *- Only one condition will be ambiguous.
2500 CASE EMPTY(lcPrevPPK_status) && 1st time updating resolved prepack
2501 IF .lAmbiguousPrepack && more than one match found for current level
2502 REPLACE ppk_status WITH "M", notes WITH pcPPKSearch IN (pcOrdDtl) && found more than one match
2503 ELSE
2504 REPLACE ppk_status WITH "1", Sizebucket WITH pnSizeBucket,;
2505 size_desc WITH pcSize_desc, ppk_code WITH pcPrePack, ;
2506 PPK_color WITH pcMultPPKColor,notes WITH pcPrePack IN (pcOrdDtl)
2507 ENDIF
2508
2509 *- previous level resolution found exact one match, and the current level resolution
2510 *- found one or more matches.
2511 *- Both condition will be ambiguous.
2512 * ie. 1st level resolve to one prepack (JP01), 2nd. level resolve to another prepack (JP04,JP05)
2513 * the horizontal order line now become ambiguous (PPK_status='M', JP01,JP04,JP05)
2514 * ie. 1st level resolve to one prepack (JP01), 2nd. level resolve to another prepack (JP05)
2515 * the horizontal order line now become ambiguous (PPK_status='M')
2516 CASE lcPrevPPK_status= "1" AND !EMPTY(lcPrevSinglPPK_code)
2517 * current level found multiple prepack matches, have to append with previous single
2518 * prepack code match (Should never resolve back to same code due to level and ckey of
2519 * prepack ref)
2520 IF .lAmbiguousPrepack && more than one match found for current level
2521 REPLACE ppk_status WITH "M", notes WITH ALLT(lcPrevSinglPPK_code) + "," +;
2522 ALLT(pcPPKSearch) IN (pcOrdDtl) && found more than one match
2523 ELSE
2524 * current level found single prepack matches, have to append with previous single
2525 * prepack code match (Should never resolve back to same code due to level and ckey of
2526 * prepack ref)
2527 REPLACE ppk_status WITH "M", notes WITH ALLT(lcPrevSinglPPK_code) + "," +;
2528 ALLT(pcPrePack) IN (pcOrdDtl)
2529 ENDIF
2530
2531 *- previous level resolution found multiple matches, and the current level resolution
2532 *- found one or more matches. Both condition will be ambiguous prepack.
2533 * (IF) 1st level resolve to many prepack (JP01,JP11),
2534 * 2nd. level resolve to another prepack (JP02,JP05)
2535 * the horizontal order line now become ambiguous (PPK_status='M', JP01,JP11,JP02,JP05)
2536 * (ELSE) 1st level resolve to many prepack (JP01,JP11),
2537 * 2nd. level resolve to another prepack (JP05)
2538 * the horizontal order line now become ambiguous (PPK_status='M', JP01,JP11,JP05)
2539 CASE lcPrevPPK_status= "M" AND !EMPTY(lcPrevMultlPPK_code)
2540 * current level found multiple prepack matches, have to append with previous multiple
2541 * prepack code match (Should never resolve back to same code due to level and ckey of
2542 * prepack ref)
2543 IF .lAmbiguousPrepack && more than one match found for current level
2544 REPLACE ppk_status WITH "M", notes WITH ALLT(lcPrevMultlPPK_code) + "," +;
2545 ALLT(pcPPKSearch) IN (pcOrdDtl) && found more than one match
2546 ELSE
2547 * current level found single prepack matches, have to append with previous multiple
2548 * prepack code match (Should never resolve back to same code due to level and ckey of
2549 * prepack ref)
2550 REPLACE ppk_status WITH "M", notes WITH ALLT(lcPrevMultlPPK_code) + "," +;
2551 ALLT(pcPrePack) IN (pcOrdDtl)
2552 ENDIF
2553
2554 ENDCASE
2555
2556 ENDWITH
2557 SELECT(lnOldSelect)
2558 RETURN llRetVal
2559 ENDPROC
2560
2561 ***********************************************************************************
2562 *
2563 ***********************************************************************************
2564 PROCEDURE MultiPrepackEvaluating
2565 LPARAMETERS pcOrdDtl, pceipcTD, pcPrePack
2566
2567 LOCAL llRetVal, lnOldSelect, lcErrorMsg, llNoPPK, lcAmbiguousPPK, lcExact, lnPPKElm, ;
2568 lnPPKMatch, lcCurDiv
2569 llRetVal = .T.
2570 lnOldSelect = SELECT()
2571
2572 WITH THIS
2573 .oLog.LogEntry("Eliminating not eligible prepack.")
2574 SELECT (pcOrdDtl)
2575 .PushRecordSet()
2576 SELECT (pceipcTD)
2577 .PushRecordSet()
2578
2579 *--Evaluating Ambiguous within same style group of colors:
2580 *- ppk_status
2581 LOCAL ARRAY laKey[1]
2582 CREATE CURSOR tcGoodPPK (color_code C(50), ppk_code C(5)) && TR 1065971 02/04/13 JIJO - Increased style/color_code field width to 50 (Automated)
2583 SELECT (pcOrdDtl)
2584 SET ORDER TO fkeystyle && Fkey,style
2585 *- 39548 YIK 6/6/03
2586 *- Scan While col_cnt> 1 and impl_ok="Y" && And (ppk_status="1" or ppk_status="M")
2587 *- 1004785 04/20/04 YIK
2588 *- Scan FOR col_cnt> 1 and impl_ok="Y" && And (ppk_status="1" or ppk_status="M")
2589 SCAN FOR col_cnt> 1 AND impl_ok <> "N" && And (ppk_status="1" or ppk_status="M")
2590 *= 1004785
2591 *- 07/13/04 1006129 YIK
2592 IF .lSingleColorMultiPrepack
2593 lcCurKeys= STR(fkey)+STYLE+color_code
2594 lcKeyExpr = "Str(fkey)+style+color_code"
2595 ELSE
2596 lcCurKeys= STR(fkey)+STYLE
2597 lcKeyExpr = "Str(fkey)+style"
2598 ENDIF
2599
2600 lnNumColors= col_cnt && number of colors per style set
2601 lcCurDiv= division && 11/28/02
2602
2603 * scan while same style that have multi color and creating cursor list
2604 * of color and all of it eligeble prepack codes
2605 SELECT (pcOrdDtl)
2606 IF SEEK(lcCurKeys, pcOrdDtl, "fkeystyle")
2607 lcPPK_code= ""
2608 lcPPK_color= ""
2609 lcSize_desc= ""
2610 lnSizeBucket= 0
2611 lnMatchPPK= 0
2612
2613 SCAN WHILE EVAL(lcKeyExpr) = lcCurKeys
2614 lcCurColor= color_code
2615 lcCurPPKs= notes
2616 IF !EMPTY(lcCurPPKs)
2617 StringToArray(lcCurPPKs, @laKey)
2618 FOR lnCnt= 1 TO ALEN(laKey)
2619 lcCurPPK= laKey[lnCnt]
2620 INSERT INTO tcGoodPPK (color_code, ppk_code ) VALUES (lcCurColor, lcCurPPK)
2621 ENDFOR
2622 ENDIF
2623
2624 * Keep one good match ppk_code,color,sizebucket... for replace all latter
2625 * This case is the norm of all client set up (90%), the reset is slower but
2626 * track for all exception (like array of (laStylePPKs) all posible ppks for
2627 * this style, or goback to prepack cursor).
2628 IF EMPTY(lcPPK_code) AND !EMPTY(ppk_code)
2629 lcPPK_code= &pcOrdDtl..ppk_code
2630 lcPPK_color= &pcOrdDtl..PPK_color
2631 lcSize_desc= &pcOrdDtl..size_desc
2632 lnSizeBucket= &pcOrdDtl..Sizebucket
2633 ENDIF
2634
2635 *--- 860 Inbound implosion of Prepack - single color with multi dimension
2636 * keep all good match ppk_code,color,sizebucket... for replace all latter when many found
2637 lnMatchPPK= lnMatchPPK + 1
2638 DIMENSION laStylePPKs[lnMatchPPK, 4]
2639 laStylePPKs[lnMatchPPK, 1]= &pcOrdDtl..ppk_code
2640 laStylePPKs[lnMatchPPK, 2]= &pcOrdDtl..PPK_color
2641 laStylePPKs[lnMatchPPK, 3]= &pcOrdDtl..size_desc
2642 laStylePPKs[lnMatchPPK, 4]= &pcOrdDtl..Sizebucket
2643 ENDSCAN
2644
2645 * After scan throught all colors for style, know if prepack is ok, not ok or
2646 * ambiguous, store record pointer of pcOrdrDtl and get back to it in mid scan
2647 SELECT (pcOrdDtl)
2648 lnRecNo = IIF(!EOF(pcOrdDtl), RECNO(), 0)
2649
2650 * For each occurence of prepack code that match lnNumColors that prepack is ok
2651 * when list of prepack ok > 1 then it is true ambiguous.
2652 LOCAL ARRAY laElgPPK[1]
2653 STORE .F. TO laElgPPK
2654 SELECT ppk_code FROM tcGoodPPK ;
2655 GROUP BY ppk_code ;
2656 HAVING COUNT(*)= lnNumColors ;
2657 INTO ARRAY laElgPPK
2658 llNoPPK= IIF(RECC("tcGoodPPK")=0, .T., .F.)
2659 DO CASE
2660
2661 *--- 860 Inbound implosion of Prepack - single color with multi dimension
2662 CASE ALEN(laElgPPK)= 1 AND !EMPTY(laElgPPK[1]) && only single prepack match use it
2663
2664 *--Most case all all color,label of same style will be single match
2665 IF laElgPPK[1]= lcPPK_code
2666 REPLACE ppk_status WITH "1", ppk_code WITH lcPPK_code, ;
2667 PPK_color WITH IIF(EMPTY(lcPPK_color),color_code,lcPPK_color), Sizebucket WITH lnSizeBucket, ; && 11/28/02
2668 size_desc WITH lcSize_desc, notes WITH "" ;
2669 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2670 ELSE
2671 *--When get to Multiple matches (all qualify for prepack substitution)
2672 *-- will try to narrow it down by:
2673
2674 *-- 1st search by array that have all posible prepack for this style:
2675 * search in array of laStylePPKs[] for match of laElgPPK[1] code before replace
2676 * multi level search may have each line ppk_code difference but other level resolve
2677 * and store in "notes" field may be the one to use after process of elimination.
2678 lcExact= SET("Exact")
2679 SET EXACT ON
2680 STORE 0 TO lnPPKElm, lnPPKMatch
2681 lnPPKElm= ASCAN(laStylePPKs, laElgPPK[1])
2682 IF lnPPKElm>0
2683 lnPPKMatch= ASUB(laStylePPKs, lnPPKElm,1)
2684 IF lnPPKMatch> 0
2685 REPLACE ppk_status WITH "1", ppk_code WITH laStylePPKs[lnPPKMatch ,1], ;
2686 PPK_color WITH IIF(EMPTY(laStylePPKs[lnPPKMatch ,2]), color_code, ;
2687 laStylePPKs[lnPPKMatch ,2]), Sizebucket WITH laStylePPKs[lnPPKMatch ,4], ;
2688 size_desc WITH laStylePPKs[lnPPKMatch ,3], notes WITH "" ;
2689 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2690 ENDIF
2691 ENDIF
2692
2693 *-- 2nd search multi color prepack cursor:
2694 * leave all resolved ppk_code,desc,sizebucket and notes for debugging
2695 IF lnPPKElm=0 OR lnPPKMatch = 0
2696 IF USED(pcPrePack) AND SEEK( (lcCurDiv + laElgPPK[1]), pcPrePack, "DivPPK")
2697 lcSize_desc= EVAL(pcPrePack + ".Size01")
2698 lcPPK_code= &pcPrePack..ppk_code
2699 lcPPK_color= &pcPrePack..PPK_color
2700 REPLACE ppk_status WITH "1", ppk_code WITH lcPPK_code, ;
2701 PPK_color WITH IIF(EMPTY(lcPPK_color),color_code,lcPPK_color), ;
2702 Sizebucket WITH 1, ;
2703 size_desc WITH lcSize_desc, notes WITH "" ;
2704 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2705 ELSE
2706 REPLACE ppk_status WITH "F", notes WITH "Unable to resolve multiple matches!" +;
2707 notes ;
2708 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2709 ENDIF
2710 ENDIF
2711 SET EXACT &lcExact
2712
2713 ENDIF
2714 CASE llNoPPK && no prepack hit at all
2715 REPLACE ppk_status WITH "" ;
2716 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2717 * will not able to show the one that it found, latter select distinct fkey,style
2718 * to mark group of colors belong same style this technique only work for all
2719 * error message of same style is the same (ambiguous check)
2720 CASE ALEN(laElgPPK)= 1 AND EMPTY(laElgPPK[1]) && only one color match in multi color ppk, fail
2721 REPLACE ppk_status WITH "F" ;
2722 FOR &lcKeyExpr = lcCurKeys IN (pcOrdDtl)
2723
2724 CASE ALEN(laElgPPK)> 1 && more than one color match in multi color ppk, fail
2725 lcAmbiguousPPK= ""
2726 FOR lnxx=1 TO ALEN(laElgPPK)
2727 lcAmbiguousPPK= lcAmbiguousPPK + IIF(EMPTY(lcAmbiguousPPK), "" , ",") + ALLTRIM(laElgPPK[lnxx])
2728 ENDFOR
2729 REPLACE ppk_status WITH "M", notes WITH "Ambiguous Multiple Color Prepacks: " + ;
2730 lcAmbiguousPPK + CRLF, avail_ppk WITH lcAmbiguousPPK ; && store all ppks for UI
2731 FOR &lcKeyExpr = lcCurKeys AND ;
2732 (ppk_status= "1" OR ppk_status= "M") IN (pcOrdDtl)
2733 ENDCASE
2734 ENDIF
2735 ZAP IN tcGoodPPK && clearout all records
2736
2737 * restore record pointer less 1 back for scan
2738 lnRecNo= lnRecNo-1
2739 IF lnRecNo> 0
2740 GO lnRecNo IN (pcOrdDtl)
2741 ENDIF
2742
2743 ENDSCAN
2744 USE IN SELECT('tcGoodPPK')
2745 SELECT (pcOrdDtl)
2746 .PopRecordSet()
2747 SELECT (pceipcTD)
2748 .PopRecordSet()
2749
2750 ENDWITH
2751 SELECT(lnOldSelect)
2752 RETURN llRetVal
2753 ENDPROC
2754
2755 ***********************************************************************************
2756 * Flag 850 transaction vertical detail within same style group of colors
2757 * that fail for ambiguous (more than one match of color prepack found)
2758 * col_cnt>1 and ppk_status="M" FIND many (Ambiguous) multi color prepack match
2759 ***********************************************************************************
2760 PROCEDURE MultiPrepackAmbiguous
2761 LPARAMETERS pcOrdDtl, pceipcTD
2762 LOCAL llRetVal, lnOldSelect, lcErrorMsg, lcAvail_ppk
2763 llRetVal = .T.
2764 lnOldSelect = SELECT()
2765
2766 WITH THIS
2767 .oLog.LogEntry("Evaluating Ambiguous Prepack.")
2768 SELECT (pcOrdDtl)
2769 .PushRecordSet()
2770 SELECT (pceipcTD)
2771 .PushRecordSet()
2772
2773 *- 1004785 04/21/04 YIK
2774 *- change impl_ok="Y" to impl_ok <> "N" to error out ambiguous prepacks
2775 SELECT DISTINCT fkey,STYLE,notes,avail_ppk FROM (pcOrdDtl) ; && 10/21 Store ambiguous ppk for new manual implosion UI
2776 WHERE col_cnt> 1 AND ppk_status="M" AND impl_ok <> "N" ;
2777 INTO CURSOR tcTemp
2778 SELECT tcTemp
2779 SCAN
2780 lcErrorMsg= tcTemp.notes
2781 lcAvail_ppk= tcTemp.avail_ppk && 10/21 Store ambiguous ppk for new manual implosion UI
2782 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH Errs_Msg_D + lcErrorMsg, ;
2783 avail_ppk WITH lcAvail_ppk ; && 10/21 Store ambiguous ppk for new manual implosion UI
2784 FOR STR(fkey)+STYLE = STR(tcTemp.fkey)+tcTemp.STYLE IN (pceipcTD)
2785 DELETE FOR STR(fkey)+STYLE = STR(tcTemp.fkey)+tcTemp.STYLE IN (pcOrdDtl)
2786 ENDSCAN
2787 USE IN SELECT("tcTemp")
2788
2789 SELECT (pcOrdDtl)
2790 .PopRecordSet()
2791 SELECT (pceipcTD)
2792 .PopRecordSet()
2793
2794 ENDWITH
2795 SELECT(lnOldSelect)
2796 RETURN llRetVal
2797 ENDPROC
2798
2799 ***********************************************************************************
2800 * Flag 850 transaction vertical detail within same style group of colors
2801 * that fail for missing color components (one or more than one color pack not found
2802 * for multi color line)
2803 * Multi Color ppk match need all color resolve to one or many match.
2804 * col_cnt>1 and ppk_status="F"
2805 ***********************************************************************************
2806 PROCEDURE MultiPrepackMissing
2807 LPARAMETERS pcOrdDtl, pceipcTD
2808 LOCAL llRetVal, lnOldSelect, lcErrorMsg
2809 llRetVal = .T.
2810 lnOldSelect = SELECT()
2811 WITH THIS
2812 .oLog.LogEntry("Verifying Missing or Un-event Prepack distribution.")
2813 SELECT (pcOrdDtl)
2814 .PushRecordSet()
2815 SELECT (pceipcTD)
2816 .PushRecordSet()
2817
2818 * flag all components as not found when NOTES is empty
2819 SELECT DISTINCT fkey,STYLE FROM (pcOrdDtl) ;
2820 WHERE col_cnt> 1 AND ppk_status="F" AND impl_ok="Y" AND EMPTY(notes) ;
2821 INTO CURSOR tcTemp
2822 SELECT tcTemp
2823 SCAN
2824 lcErrorMsg= "Missing or Not the same ratio for all components in Multi Color Prepack."
2825 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH Errs_Msg_D + lcErrorMsg + CRLF ;
2826 FOR STR(fkey)+STYLE = STR(tcTemp.fkey)+tcTemp.STYLE IN (pceipcTD)
2827 ENDSCAN
2828 USE IN SELECT("tcTemp")
2829
2830 SELECT (pcOrdDtl)
2831 .PopRecordSet()
2832 SELECT (pceipcTD)
2833 .PopRecordSet()
2834
2835 ENDWITH
2836 SELECT(lnOldSelect)
2837 RETURN llRetVal
2838 ENDPROC
2839
2840 ******************************************************************************************
2841 PROCEDURE MultiPrepackMinMultiple
2842 LPARAMETERS pcOrdDtl, pceipcTD, pcPrePack
2843 LOCAL llRetVal, lnOldSelect, lcErrorMsg, lcKeyExpr, lnTotal_qty, lnRatio, lnppk_total, lcOrdStyleColor
2844 llRetVal = .T.
2845 lnOldSelect = SELECT()
2846
2847 WITH THIS
2848 .oLog.LogEntry("Checking multiple records Prepack Min/Multiple.")
2849 SELECT (pcOrdDtl)
2850 .PushRecordSet()
2851 SELECT (pceipcTD)
2852 .PushRecordSet()
2853 *--Process when group of colors have ppk_status="1" - single multi color pack match
2854 *-- only Multi Color with match left for col_cnt>1
2855 lnCurFkeyStyle= ""
2856 SELECT (pcOrdDtl)
2857 INDEX ON STR(fkey) + STYLE + ppk_code + PPK_color TAG fkeyStyPpk
2858 SET ORDER TO fkeyStyPpk
2859 lcKeyExpr = ''
2860 llToSkip = .F.
2861 *- 1004785 04/21/04 YIK
2862 *- Scan For col_cnt> 1 and ppk_status= "1" and impl_ok="Y"
2863 SCAN FOR col_cnt> 1 AND ppk_status= "1" AND impl_ok <> "N"
2864 *= 1004785
2865 IF llToSkip AND !BOF()
2866 SKIP -1
2867 ENDIF
2868 IF NOT (lnCurFkeyStyle == STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE + &pcOrdDtl..ppk_code + &pcOrdDtl..PPK_color)
2869 lnCurFkeyStyle= STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE + &pcOrdDtl..ppk_code + &pcOrdDtl..PPK_color
2870 SCATTER NAME loOrder
2871 lnTotal_qty= 0
2872 lnRatio = 0
2873 SELECT (pcPrePack)
2874 LOCATE FOR ppk_code = loOrder.ppk_code
2875 *-- 1001635 10/23/03 YIK
2876 *- If not found - this is a single prepack and shouldn't be checked.
2877 IF FOUND()
2878 lcKeyExpr = 'ppk_code' + ;
2879 IIF(!EMPTY(PPK_color), '+ppk_color','') + ;
2880 IIF(!(EMPTY(color_code) OR ALLTR(color_code)='ALL'), '+color_code','') + ;
2881 IIF(!(EMPTY(lbl_code) OR ALLTR(lbl_code)= 'ALL'), '+lbl_code','') + ;
2882 IIF(!EMPTY(DIMENSION), '+dimension','')
2883 SELECT (pcOrdDtl)
2884 llFoundPrepack = .T.
2885 SCAN WHILE STR(fkey)+ STYLE + ppk_code + PPK_color = lnCurFkeyStyle
2886 lcKeyVal = EVAL(lcKeyExpr)
2887 SELECT (pcPrePack)
2888 LOCATE FOR &lcKeyExpr = lcKeyVal
2889 IF FOUND()
2890 lnppk_total = &pcPrePack..pack_total
2891 SELECT (pcOrdDtl)
2892 IF lnRatio = 0
2893 *IF MOD(total_qty, lnppk_total) = 0
2894 IF MOD(Qty_change, lnppk_total) = 0
2895 *lnRatio = total_qty/lnppk_total
2896 lnRatio = Qty_change/lnppk_total
2897 ELSE
2898 llFoundPrepack = .F.
2899 ENDIF
2900 ELSE
2901 *IF lnRatio <> total_qty/lnppk_total
2902 IF lnRatio <> Qty_change/lnppk_total
2903 llFoundPrepack = .F.
2904 ENDIF
2905 ENDIF
2906 ELSE
2907 llFoundPrepack = .F.
2908 ENDIF
2909 IF !llFoundPrepack
2910 lcErrorMsg= NO_PREPACK + CRLF && "Searching Prepacks below: " + CRLF + lcPPKSearch
2911 *- 1003832 03/01/04 YIK
2912 SELECT (pcOrdDtl)
2913 *=
2914 IF SEEK(lnCurFkeyStyle)
2915 SCAN WHILE STR(fkey)+ STYLE + ppk_code + PPK_color = lnCurFkeyStyle
2916 lcOrdStyleColor = STR(fkey)+ STYLE + color_code
2917 *- 1004785 04/21/04 YIK
2918 *- Add IF impl_ok = "Y"
2919
2920 IF impl_ok = "Y"
2921 *- 1005452 06/04/04 YIK
2922 *- don't put this error msg on top of another
2923 REPLACE Errs_Flg_D WITH "Y", Errs_Msg_D WITH lcErrorMsg ;
2924 FOR STR(fkey)+STYLE+ color_code = lcOrdStyleColor ;
2925 AND Errs_Flg_D <> "Y" ;
2926 IN (pceipcTD)
2927 ENDIF
2928 *- 1009508 03/24/05 YIK
2929 *- DELETE IN (pcOrdDtl)
2930 ENDSCAN
2931 ENDIF
2932 EXIT
2933 ENDIF
2934 ENDSCAN
2935 llToSkip = .T.
2936 *- 1001635 10/23/03 YIK
2937 ELSE
2938 llToSkip = .F.
2939 ENDIF
2940 *= 1001635
2941 ENDIF
2942 ENDSCAN
2943
2944 SELECT (pcOrdDtl)
2945 .PopRecordSet()
2946 SELECT (pceipcTD)
2947 .PopRecordSet()
2948
2949 ENDWITH
2950 SELECT(lnOldSelect)
2951 RETURN llRetVal
2952 ENDPROC
2953
2954 ******************************************************************************************
2955 PROCEDURE MultiPrepackFinalize
2956 LPARAMETERS pcOrdDtl, pceipcTD
2957 LOCAL llRetVal, lnOldSelect, lcErrorMsg, lcDetNotes
2958 llRetVal = .T.
2959 lnOldSelect = SELECT()
2960
2961 WITH THIS
2962 .oLog.LogEntry("Finalizing multiple records Prepack.")
2963 SELECT (pcOrdDtl)
2964 .PushRecordSet()
2965 SELECT (pceipcTD)
2966 .PushRecordSet()
2967
2968 *--Process when group of colors have ppk_status="1" - single multi color pack match
2969 *-- only Multi Color with match left for col_cnt>1
2970 lnCurFkeyStyle= ""
2971 lnCurFkeyStyClr = ""
2972 SELECT (pcOrdDtl)
2973 *- 39548 6/6/03 YIK
2974 SET ORDER TO fkeystyle
2975 INDEX ON STR(fkey)+STYLE+PPK_color+color_code+lbl_code TAG fkeyStyClr
2976 SET ORDER TO fkeyStyClr
2977 *- 1004785 04/20/04 YIK
2978 *- Scan For col_cnt> 1 and ppk_status= "1" and impl_ok="Y"
2979 SCAN FOR col_cnt> 1 AND ppk_status= "1" AND impl_ok <> "N"
2980 *=
2981 *--Creating single style and rollup all color when Multi Color prepack match to
2982 *--single record. Remove all veritcal trans detail for fkey+style and insert a new one
2983 *- 39548 05/30/03 YIK
2984 llCombine = .F.
2985 IF NOT (lnCurFkeyStyle == STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE +&pcOrdDtl..color_code ;
2986 AND lnCurFkeyStyClr == STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE +&pcOrdDtl..PPK_color)
2987 lnCurFkeyStyle= STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE + &pcOrdDtl..color_code
2988 IF !EMPTY(lnCurFkeyStyClr) AND lnCurFkeyStyClr= STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE + &pcOrdDtl..PPK_color
2989 llCombine = .T.
2990 ELSE
2991 lnCurFkeyStyClr= STR(&pcOrdDtl..fkey)+ &pcOrdDtl..STYLE + &pcOrdDtl..PPK_color
2992 ENDIF
2993
2994 *=
2995 SCATTER NAME loOrder
2996 lnTotal_qty= 0
2997 SELECT (pceipcTD)
2998 IF SEEK(lnCurFkeyStyle, pceipcTD, "GrpDetail") &&Str(fkey)+style+....
2999 lcCustomer= &pceipcTD..customer
3000 lcDoc_num= &pceipcTD..doc_num
3001 lnFkey= &pceipcTD..fkey
3002
3003 *- 1005452 05/25/04 YIK
3004 *- detail notes are not populated, because they are empty in tcOrdDtl
3005 lcDetNotes = &pceipcTD..notes
3006
3007 * remove all implode records in trans. detail
3008 *?here to verify last time for min_multiple check
3009 SELECT (pceipcTD)
3010*!* CALCULATE SUM(total_qty) TO lnTotal_qty ;
3011*!* FOR STR(fkey)+ STYLE + color_code = lnCurFkeyStyle
3012 CALCULATE SUM(Qty_change) TO lnTotal_qty ;
3013 FOR STR(fkey)+ STYLE + color_code = lnCurFkeyStyle
3014
3015 DELETE FOR STR(fkey)+ STYLE + color_code = lnCurFkeyStyle IN (pceipcTD)
3016 IF llCombine
3017 lnPpk_qty = lnPpk_qty + lnTotal_qty
3018 ELSE
3019 lnPpk_qty = lnTotal_qty
3020 APPEND BLANK
3021 lnPkey= v_nextPkey("ZZEIPCTD") && &pceipcTD..pkey
3022 GATHER NAME loOrder
3023 *- 1001378 11/24/03 YIK
3024 *- Add ..implosion with "Y" to the replace to indicate that the line was imploded.
3025 *- 1005452 05/25/04 YIK
3026 *- Add ..notes with lcDetNotes
3027 REPLACE color_code WITH loOrder.PPK_color, DIMENSION WITH loOrder.ppk_code,;
3028 Sizebucket WITH loOrder.Sizebucket, size_desc WITH loOrder.size_desc,;
3029 doc_num WITH lcDoc_num,pkey WITH lnPkey,fkey WITH lnFkey, ;
3030 customer WITH lcCustomer, ; && done using it for customer label
3031 User_id WITH lcEnt_user, Last_mod WITH DATETIME(), ;
3032 implosion WITH "Y", ;
3033 notes WITH lcDetNotes, ;
3034 Errs_Flg_D WITH "N", Errs_Msg_D WITH "" IN (pceipcTD)
3035 ENDIF
3036 ENDIF
3037
3038 ENDIF
3039 lnTotal_qty= lnPpk_qty && + loOrder.total_qty Use sum(total_qty) for ..
3040 IF llCombine
3041 SELECT (pceipcTD)
3042 LOCATE FOR STR(fkey) + STYLE + color_code = lnCurFkeyStyClr
3043 ENDIF
3044 REPLACE total_qty WITH lnTotal_qty IN (pceipcTD)
3045 REPLACE Qty_change WITH lnTotal_qty IN (pceipcTD)
3046 SELECT (pcOrdDtl)
3047 ENDSCAN
3048
3049 USE IN SELECT("_MulCol")
3050
3051 *--Done with multi color implosion
3052 *-- col_cnt>1 and ppk_status="" NOT FIND any multi color prepack match (NEXT SINGLE LEVEL MATCH)
3053 *-- reset col_cnt back to 0 for ppk_status="", in order for single level match to happend.
3054 *- 1004785 04/20/04 YIK
3055 *!* Replace col_cnt with 0 For col_cnt> 1 and ppk_status="" ;
3056 *!* and impl_ok="Y" and ppk_code="" IN (pcOrdDtl)
3057 REPLACE col_cnt WITH 0 FOR col_cnt> 1 AND ppk_status="" ;
3058 AND impl_ok <> "N" AND ppk_code="" IN (pcOrdDtl)
3059 *= 1004785
3060 SELECT (pcOrdDtl)
3061 .PopRecordSet()
3062 SELECT (pceipcTD)
3063 .PopRecordSet()
3064
3065 ENDWITH
3066 SELECT(lnOldSelect)
3067 RETURN llRetVal
3068 ENDPROC
3069
3070 ******************************************************************************************
3071
3072 PROCEDURE GetSingleSizePrepacks
3073 LPARAMETERS tcSnglPPK, tcSSizePPK
3074 LOCAL llRetVal, lnOldSelect, lnPackQty, lnxx
3075 llRetVal = .T.
3076 lnOldSelect = SELECT()
3077
3078 SELECT *, 99 AS size_bk ;
3079 FROM (tcSnglPPK) ;
3080 WHERE (Pack01_Qty = pack_total ;
3081 OR Pack02_Qty = pack_total ;
3082 OR Pack03_Qty = pack_total ;
3083 OR Pack04_Qty = pack_total ;
3084 OR Pack05_Qty = pack_total ;
3085 OR Pack06_Qty = pack_total ;
3086 OR Pack07_Qty = pack_total ;
3087 OR Pack08_Qty = pack_total ;
3088 OR Pack09_Qty = pack_total ;
3089 OR Pack10_Qty = pack_total ;
3090 OR Pack11_Qty = pack_total ;
3091 OR Pack12_Qty = pack_total ;
3092 OR Pack13_Qty = pack_total ;
3093 OR Pack14_Qty = pack_total ;
3094 OR Pack15_Qty = pack_total ;
3095 OR Pack16_Qty = pack_total ;
3096 OR Pack17_Qty = pack_total ;
3097 OR Pack18_Qty = pack_total ;
3098 OR Pack19_Qty = pack_total ;
3099 OR Pack20_Qty = pack_total ;
3100 OR Pack21_Qty = pack_total ;
3101 OR Pack22_Qty = pack_total ;
3102 OR Pack23_Qty = pack_total ;
3103 OR Pack24_Qty = pack_total) ;
3104 INTO CURSOR __SSizePPK
3105 WITH THIS
3106 llRetVal= llRetVal AND .MakeCursorWritable("__SSizePPK", tcSSizePPK)
3107 SELECT (tcSSizePPK)
3108 SCAN
3109 FOR lnxx = 1 TO goEnv.MaxBuckets
3110 lnPackQty = EVAL(.aPackStr[lnxx])
3111 IF lnPackQty > 0 && the single size bucket
3112 REPLACE size_bk WITH lnxx
3113 EXIT
3114 ENDIF
3115 ENDFOR
3116 ENDSCAN
3117 .TableClose("__SSizePPK")
3118 ENDWITH
3119
3120 * index for optimizing
3121 IF USED(tcSSizePPK)
3122 SELECT (tcSSizePPK)
3123 *- 1009508 02/24/05 YIK
3124 *- Added IF This.lSinglePrepackAny
3125 IF THIS.lSinglePrepackAny
3126 INDEX ON division+color_code+lbl_code+STR(size_bk) TAG CompSKU
3127 ELSE
3128 INDEX ON division+STYLE+color_code+lbl_code+STR(size_bk) TAG CompSKU
3129 ENDIF
3130 ENDIF
3131
3132 SELECT(lnOldSelect)
3133 RETURN llRetVal
3134 ENDPROC
3135
3136
3137 ************************************************************************************
3138 * Assume: both (pcOrdDtlAlias) and (pcPrepackAlias) point to proper record
3139 * 1. order trans work table(pcOrdDtlAlias) in horizontal size bucket
3140 * 2. prepack work table (pcPrepackAlias) found a match
3141 * the purpuse of this routine to verify Total_qty of order divide evently by prepack
3142 * qty and also all corresponding size buckets
3143 * Return: True when prepack is eligible
3144 ***********************************************************************************
3145 PROCEDURE VerifyPrepackBuckets
3146 PARAMETERS pcOrdDtlAlias, pcPrepackAlias, plMultiColorComp
3147 LOCAL llRetVal, lnOldSelect, lcPrepack, lcCurStyColLbl, lnPackMultiple, llEligiblePrepack, ;
3148 lnCurFkey
3149 llEligiblePrepack= .F.
3150 lnOldSelect = SELECT()
3151 WITH THIS
3152
3153 * order line total_qty divisible by pack_qty (single color comp, one record in prepack dtl)
3154 * pack_total (multi color comp, detail ppk many records)
3155 * Single color use header pack_qty, Multi Color use detail pack_total
3156 lnPackQty= IIF(plMultiColorComp, &pcPrepackAlias..pack_total, &pcPrepackAlias..pack_qty)
3157
3158 * If Total_qty divide evently then start evaluating all buckets qty
3159 IF MOD(&pcOrdDtlAlias..total_qty, lnPackQty) = 0
3160 llEligiblePrepack= .T.
3161 lnPackMultiple= INT(&pcOrdDtlAlias..total_qty / lnPackQty)
3162
3163 * For each order line size with qty also need to be divisible by pack size qty
3164 FOR lnxx = 1 TO goEnv.MaxBuckets
3165 lnPackQty= EVAL(pcPrepackAlias+ "." + .aPackStr[lnxx])
3166 lnSizeQty= EVAL(pcOrdDtlAlias+ "." + .aSizeStr[lnxx])
3167 IF lnSizeQty> 0 OR lnPackQty> 0
3168 * as soon as order size with qty not divisible evently by prepack size
3169 * set llEligiblePrepack to false and exit
3170 IF (lnSizeQty>0 AND lnPackQty> 0)
3171 * compare each order bucket = multiple of prepack bucket
3172 llEligiblePrepack= IIF(lnSizeQty = lnPackMultiple * lnPackQty, .T., .F.)
3173 IF NOT llEligiblePrepack
3174 pcPPKSearch= pcPPKSearch + CRLF + " Size bucket: " + ALLT(STR(lnxx)) +;
3175 " Ordr Qty: " + ALLT(STR(lnSizeQty)) + " Pack Qty: " + ALLT(STR(lnPackQty))
3176 ENDIF
3177 ELSE
3178 * No order qty for this size but prepack qty (size qty =0 but pack qty >0)
3179 * cannot use this prepack even when all other size divisible by prepack
3180 llEligiblePrepack= .F.
3181 ENDIF
3182 ENDIF
3183
3184 IF NOT llEligiblePrepack
3185 EXIT FOR && this one not eligible
3186 ENDIF
3187 ENDFOR
3188 ENDIF
3189 ENDWITH
3190
3191 SELECT(lnOldSelect)
3192 RETURN llEligiblePrepack
3193 ENDPROC
3194
3195 *-- 3 OUTPUT Parameters:
3196 *-- pcSizeBucket: Prepack Size bucket
3197 *-- pcSize_desc: Prepack size description
3198 *-- pcPrepack: Prepack code (Dimension)
3199 PROCEDURE ResolveSingleSizePrepackWithPrepackAny
3200 PARAMETERS pcDivision, pcStyle, pcColor_code, pcLbl_code, pcSize_bk, pcOrigSize_desc, pcPrepackAlias, ;
3201 pcOrdDtlAlias, pcSizeBucket, pcSize_desc, pcPrePack, pcPPKSearch
3202 LOCAL llRetVal, lnOldSelect, lcPrepack, lcCurStyColLbl, lnPackMultiple, llEligiblePrepack, llPpkExists
3203 llEligiblePrepack= .F.
3204 lnOldSelect = SELECT()
3205 WITH THIS
3206 pcPrePack= ""
3207 pcSize_desc= ""
3208 pcSizeBucket= 0
3209 *- No style for prepack any. See Phu's comments
3210 lcCurStyColLblExpr = "Division + Color_code + Lbl_code + STR(Size_bk)"
3211 lcCurStyColLbl = pcDivision + pcColor_code + pcLbl_code + STR(pcSize_bk) && exact size bucket
3212 .lAmbiguousPrepack = .F.
3213 llPpkExists = .F.
3214 * Find prepack matching division,style,color,label. There only 1 sizebucket available.
3215 IF SEEK(lcCurStyColLbl, pcPrepackAlias, "CompSKU")
3216 * veriry Found prepack of same div,style,color,label
3217 SELECT (pcPrepackAlias)
3218 SCAN FOR lcCurStyColLbl = EVALUATE(lcCurStyColLblExpr)
3219 llEligiblePrepack= .T.
3220
3221 pcPPKSearch= pcPPKSearch + IIF(EMPTY(pcPPKSearch),"", CRLF) + division + ;
3222 "/" + color_code + "/" + lbl_code + "/" + DIMENSION +;
3223 " Pack Units: " + ALLT(STR(pack_qty))
3224
3225 * order line total_qty divisible by pack_qty
3226 IF MOD(&pcOrdDtlAlias..Qty, pack_qty) = 0
3227
3228 lnPackMultiple= INT(&pcOrdDtlAlias..Qty / pack_qty)
3229 *- If already found a matching prepack (llPpkExists = .T.) and this prepack is
3230 *- also good (llEligiblePrepack = .T.) - this is Ambiguous
3231 .lAmbiguousPrepack = .lAmbiguousPrepack OR (llPpkExists AND llEligiblePrepack)
3232 IF llEligiblePrepack
3233 pcSizeBucket= 1
3234 IF vl_Sizer(&pcOrdDtlAlias..division, ,"_sizer", size_code)
3235 pcSize_desc= _sizer.size01
3236 ELSE
3237 pcSize_desc='' && default
3238 ENDIF
3239 pcPrePack = ppk_code
3240 llPpkExists = .T.
3241 ENDIF
3242
3243 ELSE
3244 llEligiblePrepack = .F.
3245 ENDIF
3246 ENDSCAN
3247 ELSE
3248 pcPPKSearch= pcPPKSearch + IIF(EMPTY(pcPPKSearch),"", CRLF) + pcDivision + "/" +;
3249 pcColor_code + "/" + pcLbl_code + ;
3250 "Size " + pcOrigSize_desc + "/ (Not Found)"
3251 ENDIF
3252 ENDWITH
3253 SELECT(lnOldSelect)
3254 RETURN llPpkExists &&llEligiblePrepack
3255 ENDPROC
3256
3257 ******************************************************************************************
3258
3259 PROCEDURE PopulatingImplosionFlag
3260 LPARAMETERS pceipcTH, pceipcCR
3261 LOCAL llRetVal, lnOldSelect,lnLastOrder && TR 1041492 JUL-20-2009 BR
3262 llRetVal = .T.
3263 lnOldSelect = SELECT()
3264 WITH THIS
3265 IF this.lPrepackConversion
3266 * set header/detail Relation
3267
3268 *--- TR 1048865 27-Dec-2010 Goutam
3269 *llRetVal = llRetVal AND .SetRelation(pceipcCR, "divcust", pceipcTH, "division + customer")
3270 llRetVal = llRetVal AND .SetRelation(pceipcCR, "pkey", pceipcTH, "cr_pkey")
3271 *=== TR 1048865 27-Dec-2010 Goutam
3272
3273 *--- TR 1041492 JUL-20-2009 BR
3274 lnLastOrder = ORDER()
3275 SET ORDER TO TAG ImplOK
3276
3277 *- TR 1072045 - FH can't SEEK on a field you're going to be doing replace on
3278*!* IF SEEK('', pceipcTH, "ImplOK")
3279*!* SCAN WHILE(impl_ok = '')
3280*!* REPLACE impl_ok WITH &pceipcCR..impl_ok IN (pceipcTH)
3281*!* ENDSCAN
3282*!* ENDIF
3283
3284 DO WHILE SEEK(' ', pceipcTH, "ImplOK") && have to use ' ', instead of '', SEEKing on '' always return .T. for some reason.
3285 REPLACE impl_ok WITH &pceipcCR..impl_ok IN (pceipcTH)
3286 ENDDO
3287 *- TR 1072045 - FH can't SEEK on a field you're going to be doing replace on
3288
3289 SET ORDER TO lnLastOrder
3290 *=== TR 1041492 JUL-20-2009 BR
3291 SET RELATION TO
3292 ENDIF
3293 ENDWITH
3294 SELECT(lnOldSelect)
3295 RETURN llRetVal
3296 ENDPROC
3297
3298 ******************************************************************************************
3299
3300 PROCEDURE GetDeleteSQLForMatchingTransHistoryPkey
3301 LPARAMETERS pcRefSql, pcRefTempTable, pctmpIpctdPkey
3302 LOCAL llRetVal, lnOldSelect
3303
3304 llRetVal = .t.
3305 lnOldSelect = SELECT()
3306 .cSQLTempTable = ""
3307 IF RECCOUNT(pctmpIpctdPkey) > 0
3308 llRetVal = llRetVal and .GenerateSQLTempTable(pctmpIpctdPkey)
3309 llRetVal = llRetVal and .PopulateSQLTempTable(pctmpIpctdPkey) and !EMPTY(.cSQLTempTable)
3310 pcRefTempTable = .cSQLTempTable
3311 IF llRetVal
3312 pcRefSql = "delete d from zzeipchd d inner join " + pcRefTempTable + " t on d.pkey = t.pkey"
3313 ENDIF
3314 ENDIF
3315
3316 SELECT(lnOldSelect)
3317 RETURN llRetVal
3318 ENDPROC
3319
3320 ******************************************************************************************
3321
3322 FUNCTION ResolveMultiPrepacks
3323 LPARAMETERS pcTransHeader, pcTransDetail, pcMppk
3324 LOCAL llRetVal, lnOldSelect, lcErrs_Msg, llMultPpkToExplode
3325
3326 llRetVal = .T.
3327 lnOldSelect = SELECT()
3328
3329 SELECT DISTINCT h.customer,d.division, d.STYLE, d.color_code, d.lbl_code, d.DIMENSION ;
3330 FROM (pcTransHeader) h, (pcTransDetail) d ;
3331 WHERE h.pkey = d.fkey AND h.Errs_flg_h= "N" AND d.Errs_Flg_D= "N" ;
3332 AND d.implosion = 'Y';
3333 ORDER BY 1,2,3,4,5 INTO CURSOR __TmpCursor
3334
3335 IF RECCOUNT("__TmpCursor") = 0
3336 SELECT(lnOldSelect)
3337 RETURN llRetVal
3338 ENDIF
3339
3340 WITH THIS
3341 .cSQLTempTable=""
3342 llRetVal = llRetVal and .GenerateSQLTempTable('__TmpCursor') AND .PopulateSQLTempTable('__TmpCursor') and NOT EMPTY(.cSQLTempTable)
3343 IF llRetVal
3344 .LogEntry("Exploding MultiPack.")
3345 lcSQLString = "select h.*,t.* from zzemppkh h," + .cSQLTempTable + " t " +;
3346 "Where h.customer = t.customer and h.mpack_code = t.dimension "
3347
3348 llRetVal = llRetVal AND v_SqlExec(lcSQLString, "__MppkH")
3349 llMultPpkToExplode = THIS.CountTotalRecs ("__MppkH")>0
3350 IF llRetVal AND llMultPpkToExplode
3351 lcSQLString = "Select d.*, t.* From zzemppkd d, zzemppkh h," + .cSQLTempTable + " t " +;
3352 "Where h.pkey = d.fkey AND h.customer = t.customer and h.mpack_code = t.dimension "
3353 llRetVal = llRetVal and v_SqlExec(lcSQLString, "__MppkD")
3354
3355 SELECT Sizebucket, size_desc, total_qty, ppk_qty , SPACE(5) AS ppk_code, 00000 AS multQty FROM (pcTransDetail) ;
3356 WHERE 0=1 INTO CURSOR __ppk2
3357 THIS.CreateCursorStructure("__MppkH", "__ppk2", "tcMppkVer")
3358
3359 IF USED("__ppk1")
3360 USE IN __ppk1
3361 ENDIF
3362 IF USED("__ppk2")
3363 USE IN __ppk2
3364 ENDIF
3365 SELECT __MppkH
3366 INDEX ON pkey TAG pkey
3367 SELECT __MppkD
3368 INDEX ON division+STYLE TAG DivStyle
3369 SELECT tcMppkVer
3370 INDEX ON division+STYLE+color_code+lbl_code+DIMENSION TAG MpackRef
3371 SET ORDER TO MpackRef
3372 THIS.ExplodeMultPackRef("__MppkH", "__MppkD", pcTransDetail, "tcMppkVer")
3373
3374 SELECT DISTINCT d.pkey ;
3375 FROM __MppkD mp, (pcTransDetail) d ;
3376 WHERE d.Errs_Flg_D= "N" ;
3377 AND mp.STYLE = d.STYLE ;
3378 AND mp.color_code = d.color_code ;
3379 AND mp.lbl_code = d.lbl_code ;
3380 AND mp.DIMENSION = d.DIMENSION;
3381 AND d.implosion = 'Y';
3382 INTO CURSOR __DtlExpl
3383
3384 llRetVal = llRetVal and .ExplodeMultiPackVertical("__DtlExpl", "tcMppkVer", pcTransDetail)
3385 ENDIF
3386 ENDIF
3387 ENDWITH
3388
3389 IF USED("__MppkH")
3390 USE IN __MppkH
3391 ENDIF
3392 IF USED("__MppkD")
3393 USE IN __MppkD
3394 ENDIF
3395 IF USED("tcMppkVer")
3396 USE IN tcMppkVer
3397 ENDIF
3398 IF USED("__DtlExpl")
3399 USE IN __DtlExpl
3400 ENDIF
3401 IF USED("__TmpCursor")
3402 USE IN __TmpCursor
3403 ENDIF
3404
3405 SELECT(lnOldSelect)
3406 RETURN llRetVal
3407
3408 ENDFUNC
3409
3410 ******************************************************************************************
3411
3412 *****************************************************************
3413 *
3414 *****************************************************************
3415 PROCEDURE ExplodeMultPackRef
3416 LPARAMETERS pcMultPackHeader, pcMultPackDetail, pcTransDetail, pcMultPackTarget
3417 LOCAL llRetVal, lnOldSele, lcSizeBucket, lcSizeName, ;
3418 lcDivStyle, lnSourceCnt, lnSizeQty, lnSizePosition, lnMultiplyQty
3419
3420 lnOldSele = SELECT()
3421 lcDivStyle = ""
3422 lnSourceCnt = THIS.CountTotalRecs (pcMultPackDetail)
3423
3424 llRetVal= .T.
3425 lnCurDtlFkey= 0
3426 lnMultiplyQty = 0
3427
3428 .oLog.LogEntry("Exploding multi pack details.")
3429
3430 SELECT (pcMultPackDetail)
3431 SET ORDER TO DivStyle
3432 SCAN
3433
3434 IF lnCurDtlFkey<> fkey
3435 lnCurDtlFkey = fkey
3436 IF SEEK(fkey, pcMultPackHeader , "PKEY")
3437 lnMultiplyQty = EVALUATE(pcMultPackHeader + " .total_qty")
3438 ELSE
3439 llRetVal = .F.
3440 EXIT
3441 ENDIF
3442 ENDIF
3443
3444
3445 * only run once per Div + Style
3446 IF !(lcDivStyle == division + STYLE)
3447 lcDivStyle = division + STYLE
3448 * Insert a record for each size bucket with a caption *
3449 IF !v_GetSizeHeadings(division, STYLE, "__xSizer")
3450 llRetVal = .F.
3451 EXIT
3452 ENDIF
3453 ENDIF
3454
3455
3456 lnSizeQty = 1
3457 SELECT (pcMultPackDetail)
3458 SCATTER MEMVAR MEMO
3459
3460 lnSizePosition = 1
3461 lcSizeBucket = "Size" + TRANS(lnSizePosition, "@L 99") && zzxsizer bucket field names
3462 lcSizeName = TRIM(EVAL("__xSizer." + lcSizeBucket)) && zzxsizer bucket Names
3463 lnSizeQty = ppk_qty
3464
3465 m.Sizebucket = lnSizePosition
3466 m.size_desc = lcSizeName
3467 m.total_qty = lnSizeQty
3468 m.multQty = lnMultiplyQty
3469 m.qty_change = lnSizeQty
3470
3471 IF lnSizeQty > 0 && Only want buckets with activity!
3472 INSERT INTO (pcMultPackTarget) FROM MEMVAR
3473 ENDIF
3474 SELECT (pcMultPackDetail)
3475
3476 ENDSCAN
3477
3478 THIS.TableClose("__xSizer")
3479 SELECT (pcMultPackDetail)
3480 SELECT (lnOldSele)
3481 RETURN llRetVal
3482 ENDPROC
3483
3484 *****************************************************************
3485 PROCEDURE ExplodeMultiPackVertical
3486 LPARAMETERS pcDetailtoExplode, pcMultDetailVert, pcTransDetail &&, pcViewTransDetail
3487 LOCAL llRetVal, lnOldSelect, lcErrs_Msg, lnMultiplier
3488 llRetVal = .T.
3489 lnOldSelect = SELECT()
3490
3491 .oLog.LogEntry("Exploding multi pack details into vertical cursor.")
3492 SELECT (pcDetailtoExplode)
3493
3494 SCAN
3495
3496 IF SEEK(pkey, pcTransDetail, "Pkey")
3497
3498 * Current working trans detail
3499 SELECT (pcTransDetail)
3500 lcCurOurSKU= division+STYLE+color_code+lbl_code+DIMENSION
3501 lnCurDtlTotal_qty= total_qty
3502
3503
3504 SCATTER NAME loTransDetail MEMO
3505 * delete current working trans detail already have image
3506 * in loTransDetail
3507 DELETE IN (pcTransDetail)
3508
3509
3510 SELECT (pcMultDetailVert)
3511 * Find 1st match of OURSKU
3512 IF SEEK(lcCurOurSKU, pcMultDetailVert, "MpackRef")
3513 lnMultiplier = lnCurDtlTotal_qty / multQty &&Need to divide by ..
3514
3515
3516 SCAN WHILE llRetVal AND !EOF(pcMultDetailVert) AND ;
3517 (lcCurOurSKU= division+ STYLE + color_code + lbl_code + DIMENSION)
3518 * Exploding detail line
3519 loTransDetail.pkey = v_nextPkey("ZZEIPCTD") && Never reassign Pkey in TD
3520 IF !EMPTY(loTransDetail.pkey)
3521
3522 SELECT (pcMultDetailVert)
3523 SCATTER NAME loVert MEMO
3524
3525 SELECT (pcTransDetail)
3526 APPEND BLANK
3527 GATHER NAME loTransDetail MEMO
3528
3529 REPLACE total_qty WITH loVert.total_qty * lnMultiplier , ;
3530 qty_change WITH loVert.total_qty * lnMultiplier, ;
3531 Sizebucket WITH loVert.Sizebucket, ;
3532 size_desc WITH loVert.size_desc, ;
3533 division WITH loVert.division, ;
3534 STYLE WITH loVert.STYLE, ;
3535 color_code WITH loVert.color_code, ;
3536 lbl_code WITH loVert.lbl_code, ;
3537 DIMENSION WITH loVert.ppk_code IN (pcTransDetail)
3538 ELSE
3539 .oLog.LogEntry("Pkey cannot be empty.")
3540 llRetVal= .F. && Cannot get Pkey from bcsysnum
3541 EXIT
3542 ENDIF
3543
3544 SELECT (pcMultDetailVert)
3545 ENDSCAN
3546 ELSE
3547 .oLog.LogEntry(" Seek Failed Not able to find SKU. "+ lcCurSKU)
3548 llRetVal= .F. && Should be in pcMultDetailVert
3549 EXIT
3550 ENDIF
3551 ENDIF
3552
3553 IF !llRetVal &&Get out of scan when have some problem
3554 EXIT
3555 ENDIF
3556 ENDSCAN
3557
3558 SELECT(lnOldSelect)
3559 RETURN llRetVal
3560 ENDPROC
3561
3562 *==== TR 1016560 NH
3563
3564 *--- TR 1021052 21-AUG-2007 HNISAR & Goutam
3565 PROCEDURE CreateNewStoreOrder
3566 LPARAMETERS taDuplicateFields
3567
3568 LOCAL llRetVal, lnOldSelect, lcErrs_Msg, lnMultiplier ,lcSqlString , ;
3569 lnOrd_num ,lnHdrPkey ,lnNextHdrPkey ,lnDtlPkey ,lnNextDtlPkey, loOrdDtl, ;
3570 lcSizeStr ,lcReplaceStr, lcUser, ldLastUpdate, lnLine_Seq, llFound, lnDtlPkey
3571
3572 llRetVal = .T.
3573 lnOldSelect = SELECT()
3574
3575 lcUser = goEnv.SV("cUser")
3576 ldLastUpdate = DATETIME()
3577
3578 WITH THIS
3579 .oLog.LogEntry("Creating New Store order.")
3580
3581 lcSqlString = " SELECT h.*, tmp.DPkey, d.pkey DtlPkey FROM ZZOORDRH h " + ;
3582 " JOIN ZZOORDRD d " + ;
3583 " ON d.fkey = h.pkey " + ;
3584 " JOIN " + .cSQLTempTable + " tmp " + ;
3585 " ON h.Customer = tmp.customer " + ;
3586 " AND h.Division = tmp.Division " + ;
3587 " AND h.Po_Num = tmp.PO_Num " + ;
3588 " AND d.Style = tmp.style " + ;
3589 " AND d.Color_code = tmp.color_code " + ;
3590 " AND d.lbl_code = tmp.lbl_code " + ;
3591 " AND d.Dimension = tmp.Dimension " + ;
3592 " WHERE tmp.HPKey = " + SQLFormatNum(tcEiPCth.pkey)+ ;
3593 " ORDER BY h.last_mod DESC"
3594
3595 llRetVal = llRetVal AND NOT .lOrderHdrFound AND v_SqlExec(lcSQLString, "tcOrdHdr") AND RECCOUNT("tcOrdHdr") > 0
3596
3597 IF llRetVal
3598 SELECT tcOrdHdr
3599 LOCATE FOR DPkey = tcEiPCtd.pkey
3600 IF FOUND()
3601 lnHdrPkey = tcOrdHdr.pkey
3602 lnDtlPkey = tcOrdHdr.Dtlpkey
3603 ELSE
3604 GO top
3605 lnHdrPkey = tcOrdHdr.pkey
3606 lnDtlPkey = tcOrdHdr.Dtlpkey
3607 ENDIF
3608 SELECT Vzzoordrh_860I
3609 LOCATE FOR Customer = tcOrdHdr.Customer AND Po_Num = tcOrdHdr.Po_Num AND Store = tcEiPCth.Store
3610 llFound = FOUND()
3611 .lOrderHdrFound = true
3612 ENDIF
3613
3614 IF .lOrderHdrFound
3615 lcSqlString = " SELECT * FROM ZZOORDRD " + ;
3616 " WHERE pkey = " + SQLFormatNum(lnDtlPkey)
3617
3618 llRetVal = v_SqlExec(lcSQLString, "tcOrdDtl") AND RECCOUNT("tcOrdDtl") > 0
3619 ENDIF
3620
3621 IF llRetVal OR .lOrderHdrFound
3622 IF NOT llFound AND llRetVal
3623 .oLog.LogEntry("Inserting New Store order header Record .")
3624
3625 lnOrd_num = v_NextId('ZZXCOMPR','ORD_NUM')
3626 lnNextHdrPkey = v_nextPkey('ZZOORDRH')
3627
3628 SELECT tcOrdHdr
3629 SCATTER NAME loOrdHdr MEMO
3630
3631 .oBPOSalesOrder.ClearShippingFields(@loOrdHdr)
3632 loOrdHdr.ack_prn = "N"
3633 loOrdHdr.Store = tcEiPCth.Store
3634 loOrdHdr.Ord_Status = 'O'
3635
3636 SELECT Vzzoordrh_860I
3637 APPEND BLANK
3638 GATHER NAME loOrdHdr MEMO
3639
3640 REPLACE pkey WITH lnNextHdrPkey, ;
3641 ord_num WITH lnOrd_num, ;
3642 ord_qty WITH 0, ;
3643 User_Id WITH lcUser, ;
3644 last_mod WITH ldLastUpdate ;
3645 IN Vzzoordrh_860I
3646
3647 .oLog.LogEntry("Copying Header Notes .")
3648
3649 lcSqlString = "select * from sysnotes where table_name = 'ZZOORDRH' " + ;
3650 " AND fkey = " + SQLFormatNum(lnHdrPkey)
3651 llRetVal = llRetVal AND v_SqlExec(lcSQLString, "tcHdrNotes")
3652
3653 SELECT tcHdrNotes
3654 SCAN
3655 SCATTER NAME loHdrNotes MEMO
3656
3657 SELECT Vnotes_zzoordrh_860I
3658
3659 APPEND BLANK
3660 GATHER NAME loHdrNotes MEMO
3661
3662 REPLACE pkey WITH v_NextPkey("SYSNOTES"), ;
3663 fkey with lnNextHdrPkey, ;
3664 User_Id WITH lcUser, ;
3665 last_mod WITH ldLastUpdate ;
3666 IN Vnotes_zzoordrh_860I
3667 ENDSCAN
3668 ELSE
3669 lnOrd_num = Vzzoordrh_860I.Ord_Num
3670 lnNextHdrPkey = Vzzoordrh_860I.Pkey
3671 llRetVal = true
3672 ENDIF
3673
3674 .oLog.LogEntry("Inserting Detail Record .")
3675
3676 lcSizeStr = ""
3677 FOR lnCnt = 1 TO .nMaxSizes
3678 lcSizeStr = lcSizeStr + "Size" + PADL(lnCnt, 2, "0") + "_Qty WITH 0 , "
3679 ENDFOR
3680
3681 lcSizeStr = lcSizeStr + " Total_Qty WITH 0 "
3682
3683 lnLine_Seq = 0
3684 IF RECCOUNT("tcOrdDtl") = 0
3685 SELECT tcOrdDtl
3686 APPEND BLANK
3687 ENDIF
3688
3689 SELECT tcOrdDtl
3690 SCAN
3691 lnDtlPkey = tcOrdDtl.pkey
3692 DELETE ALL IN Vzzoordrd_860I FOR ;
3693 Division = tcEiPCtd.Division ;
3694 AND Style = tcEiPCtd.Style ;
3695 AND Color_Code = tcEiPCtd.Color_Code ;
3696 AND Lbl_Code = tcEiPCtd.Lbl_Code ;
3697 AND Dimension = tcEiPCtd.Dimension
3698
3699 SCATTER NAME loOrdDtl MEMO
3700 loOrdDtl.Line_Status = 'O'
3701 loOrdDtl.Cncl_type = ''
3702 loOrdDtl.Cncl_rsn = ''
3703
3704 SELECT Vzzoordrd_860I
3705 APPEND BLANK
3706
3707 GATHER NAME loOrdDtl MEMO
3708
3709 SELECT tcEiPCtd
3710 SCATTER NAME loOrdDtl MEMO
3711
3712 SELECT Vzzoordrd_860I
3713 GATHER NAME loOrdDtl MEMO
3714
3715 lnNextDtlPkey = v_NextPkey("ZZOORDRD")
3716 lnLine_Seq = lnLine_Seq + 1
3717 lcReplaceStr = " REPLACE pkey with lnNextDtlPkey , " + ;
3718 " fkey with lnNextHdrPkey , " + ;
3719 " ord_num with lnOrd_num , " + ;
3720 " line_Seq with lnLine_Seq , " + ;
3721 " User_Id with lcUser, " + ;
3722 " last_mod with ldLastUpdate, " + ;
3723 lcSizeStr + ;
3724 " IN Vzzoordrd_860I "
3725
3726 &lcReplaceStr
3727
3728 Replace Vzzoordrh_860I.ord_qty WITH Vzzoordrh_860I.ord_qty+Vzzoordrd_860I.total_qty IN Vzzoordrh_860I
3729
3730 .DefaultHeaderDataToDetail("Vzzoordrh_860I","Vzzoordrd_860I", @taDuplicateFields)
3731
3732 .oLog.LogEntry("Copying Detail Notes .")
3733
3734 lcSqlString = "select * from sysnotes where table_name = 'ZZOORDRD' " + ;
3735 " AND fkey = " + SQLFormatNum(lnDtlPkey)
3736 llRetVal = llRetVal AND v_SqlExec(lcSQLString, "tcDtlNotes")
3737
3738 SELECT tcDtlNotes
3739 SCAN
3740 SCATTER NAME loDtlNotes MEMO
3741 SELECT Vnotes_zzoordrd_860I
3742
3743 APPEND BLANK
3744 GATHER NAME loDtlNotes MEMO
3745
3746 REPLACE pkey WITH v_NextPkey("SYSNOTES"), ;
3747 fkey with lnNextDtlPkey, ;
3748 User_Id WITH lcUser, ;
3749 last_mod WITH ldLastUpdate ;
3750 IN Vnotes_zzoordrd_860I
3751 ENDSCAN
3752
3753 ENDSCAN
3754
3755 ENDIF
3756 ENDWITH
3757
3758 .TableClose("tcOrdHdr")
3759 .TableClose("tcOrdDtl")
3760 .TableClose("tcHdrNotes")
3761 .TableClose("tcDtlNotes")
3762
3763 SELECT(lnOldSelect)
3764 RETURN llRetVal
3765 ENDPROC
3766 *=== TR 1021052 21-AUG-2007 HNISAR & Goutam
3767
3768 *--- TR 1023071 04/03/07 NH
3769 ***********************************************************************************
3770 *PROCEDURE PopulateTranHdrDivision
3771 PROCEDURE CheckPoAndPopulateHdrDivision
3772 LPARAMETERS pceipcth, pceipcTD, pceipcCR
3773 *--- TR 1048865 27-May-2011 Goutam. Added parameter pceipcTD, pceipcCR
3774
3775 LOCAL llRetVal, lnOldSelect, lcSql
3776 LOCAL lcCustPo
3777
3778 *--- TR 1048865 27-Dec-2010 Goutam
3779 LOCAL llEmptyDivision
3780 *=== TR 1048865 27-Dec-2010 Goutam
3781
3782 lcCustPo = ""
3783 llRetVal = .t.
3784 lnOldSelect = SELECT()
3785
3786 *--- TR 1048865 24-Dec-2010 Goutam
3787 IF .CheckUpc(pceipcTH, pceipcTD, pceipcCR) AND .CheckSKU(pceipcTH, pceipcTD) AND .CheckEAN(pceipcTH, pceipcTD)
3788 llRetVal= llRetVal AND this.UpdtHeaderDivs(pceipcTH, pceipcTD)
3789 ENDIF
3790
3791 *SELECT DISTINCT customer, po_num, division FROM (pceipcth) WHERE division = '' AND customer > '' INTO CURSOR _CustPO
3792 SELECT DISTINCT customer, po_num, division FROM (pceipcth) WHERE customer > '' INTO CURSOR _CustPO
3793 *=== TR 1048865 24-Dec-2010 Goutam
3794
3795 IF RECCOUNT("_CustPO") = 0
3796 USE IN ("_CustPO")
3797 lnOldSelect = SELECT()
3798 RETURN llRetVal
3799 ENDIF
3800 WITH this
3801
3802 this.cSQLTempTable=""
3803 llRetVal = llRetVal and .GenerateSQLTempTable('_CustPO')
3804 llRetVal = llRetVal and .PopulateSQLTempTable('_CustPO') and !EMPTY(.cSQLTempTable)
3805 lcTmpTbl = .cSQLTempTable
3806
3807 *--- TR 1048865 24-Dec-2010 Goutam
3808
3809*!* TEXT TO lcSql NOSHOW
3810*!* select distinct h.customer, h.po_num, coalesce(oh.division, '') as division
3811*!* FROM zzeipcth h left outer join zzoordrh oh (nolock)
3812*!* on h.po_num = oh.po_num and h.customer = oh.customer and oh.ord_status = 'O'
3813*!* order by h.customer,h.po_num
3814*!* ENDTEXT
3815
3816*!* lcSql = STRTRAN(lcSql,"zzeipcth",lcTmpTbl)
3817*!* lcCustPoDiv = SYS(2015)
3818*!* llRetVal = llRetVal and v_sqlexec(lcSql, lcCustPoDiv) AND USED(lcCustPoDiv)
3819
3820*!* IF llRetval
3821*!* SELECT (pceipcth)
3822*!* lnPrevIpcthOrder = ORDER()
3823*!* SET ORDER TO ("custpo")
3824*!* SELECT(lcCustPoDiv)
3825*!* SCAN
3826*!* SCATTER NAME loCustPoDiv
3827*!* lcCustPo = loCustPoDiv.customer + loCustPoDiv.po_num
3828*!* IF SEEK(lcCustPo,pceipcth,'custpo')
3829*!* SELECT (pceipcth)
3830*!* SCAN WHILE customer + po_num = lcCustPo
3831*!* IF EMPTY(loCustPoDiv.division)
3832*!* replace errs_flg_h WITH 'Y', errs_msg_h WITH errs_msg_h + 'Corresponding sales order not found.' + CRLF IN (pceipcth)
3833*!* ELSE
3834*!* replace division with loCustPoDiv.division IN (pceipcth)
3835*!* ENDIF
3836*!* ENDSCAN
3837*!* ENDIF
3838*!* ENDSCAN
3839*!* SELECT (pceipcth)
3840*!* SET ORDER TO (lnPrevIpcthOrder)
3841*!* ENDIF
3842
3843 TEXT TO lcSql NOSHOW
3844 select distinct h.customer, h.po_num, coalesce(oh.division, '') as division
3845 from zzeipcth h left join
3846 (select customer, po_num, division from zzoordrh (nolock)
3847 union
3848 select customer, po_num, division from zzoshprh (nolock)) oh
3849 on h.po_num = oh.po_num and h.customer = oh.customer
3850 ENDTEXT
3851
3852 lcSql = STRTRAN(lcSql,"zzeipcth",lcTmpTbl)
3853 lcCustPoDiv = SYS(2015)
3854 llRetVal = llRetVal and v_sqlexec(lcSql, lcCustPoDiv) AND USED(lcCustPoDiv)
3855
3856 SELECT (pceipcth)
3857 lnPrevIpcthOrder = ORDER()
3858 SET ORDER TO ("custpo")
3859
3860 SELECT * FROM (lcCustPoDiv) WHERE EMPTY(division) INTO CURSOR __tmpEmptyDivCurs
3861 IF RECCOUNT('__tmpEmptyDivCurs') > 0
3862 llEmptyDivision = true
3863 ENDIF
3864
3865 SELECT (lcCustPoDiv)
3866 SCAN FOR NOT EMPTY(division)
3867 SCATTER NAME loCustPoDiv
3868 lcCustPo = loCustPoDiv.customer + loCustPoDiv.po_num
3869 IF SEEK(lcCustPo,pceipcth,'custpo') AND EMPTY(&pceipcth..Division)
3870 replace division with loCustPoDiv.division WHILE customer + po_num = lcCustPo IN (pceipcth)
3871 ENDIF
3872 ENDSCAN
3873
3874 IF llEmptyDivision
3875 *--- TR 1054768 4-Jul-2011 Goutam. Added and oh.division = case when th.division = '' then oh.division else th.division end
3876 TEXT TO lcSql NOSHOW
3877 select distinct h.parent, h.customer, h.po_num, coalesce(oh.division, '') as division
3878 from (select c.parent, c.customer, tmp.po_num from zzxcustr c join
3879 (select distinct h.customer, h.po_num, coalesce(oh.division, '') as division
3880 from zzeipcth h left join
3881 (select customer, po_num, division from zzoordrh (nolock)
3882 union
3883 select customer, po_num, division from zzoshprh (nolock)) oh
3884 on h.po_num = oh.po_num and h.customer = oh.customer
3885 ) tmp
3886 on tmp.customer = c.parent
3887 where tmp.division = '') h left join
3888 (select customer, po_num, division from zzoordrh (nolock)
3889 union
3890 select customer, po_num, division from zzoshprh (nolock)) oh
3891 on h.po_num = oh.po_num and h.customer = oh.customer
3892 join zzeipcth th on oh.po_num = th.po_num
3893 and oh.division = case when th.division = '' then oh.division else th.division end
3894 ENDTEXT
3895
3896 lcSql = STRTRAN(lcSql,"zzeipcth",lcTmpTbl)
3897 lcCustPoDiv = SYS(2015)
3898 llRetVal = llRetVal and v_sqlexec(lcSql, lcCustPoDiv) AND USED(lcCustPoDiv)
3899
3900 IF llRetVal
3901 SELECT distinct parent, po_num FROM (lcCustPoDiv) INTO CURSOR __tmpCustPODiv
3902 SELECT * FROM __tmpEmptyDivCurs WHERE customer+po_num NOT in (SELECT parent+po_num FROM __tmpCustPODiv) INTO CURSOR __tmpNoCustCurs
3903
3904 SELECT __tmpCustPODiv
3905 SCAN
3906 lcPo_Num = Po_Num
3907 lcParent = Parent
3908 lcCustPo = lcParent + lcPo_Num
3909 SELECT * FROM (lcCustPoDiv) WHERE po_num = lcPo_Num AND Parent = lcParent AND NOT EMPTY(Division) INTO CURSOR __tmpParentCustCurs
3910 DO CASE
3911 CASE RECCOUNT('__tmpParentCustCurs') > 1
3912 SELECT __tmpParentCustCurs
3913 IF SEEK(lcCustPo,pceipcth,'custpo')
3914 replace errs_flg_h WITH 'Y', errs_msg_h WITH errs_msg_h + 'Multiple customer found for PO# : ' + ALLTRIM(lcPo_Num) + CRLF ;
3915 FOR customer + po_num = lcCustPo IN (pceipcth)
3916 SCAN
3917 IF SEEK(lcCustPo,pceipcth,'custpo')
3918 replace errs_msg_h WITH errs_msg_h + 'Customer : ' + ALLTRIM(__tmpParentCustCurs.Customer) + CRLF FOR customer + po_num = lcCustPo IN (pceipcth)
3919 ENDIF
3920 ENDSCAN
3921 ENDIF
3922 CASE RECCOUNT('__tmpParentCustCurs') = 1
3923 IF SEEK(lcCustPo,pceipcth,'custpo') AND EMPTY(&pceipcth..Division)
3924 replace division with __tmpParentCustCurs.division FOR customer + po_num = lcCustPo IN (pceipcth)
3925 ENDIF
3926 IF SEEK(lcCustPo,pceipcth,'custpo')
3927 replace Customer with __tmpParentCustCurs.Customer FOR customer + po_num = lcCustPo IN (pceipcth)
3928 ENDIF
3929 ENDCASE
3930 ENDSCAN
3931 SELECT __tmpNoCustCurs
3932 SCAN
3933 lcPo_Num = Po_Num
3934 lcParent = Customer
3935 lcCustPo = lcParent + lcPo_Num
3936 IF SEEK(lcCustPo,pceipcth,'custpo')
3937 replace errs_flg_h WITH 'Y', errs_msg_h WITH errs_msg_h + 'PO# ' + ALLTRIM(lcPo_Num) + ' is not found for the customer ' + ALLTRIM(lcParent) + CRLF FOR customer + po_num = lcCustPo IN (pceipcth)
3938 ENDIF
3939 ENDSCAN
3940
3941 USE IN SELECT("__tmpParentCustCurs")
3942 USE IN SELECT("__tmpCustPODiv")
3943 USE IN SELECT("__tmpNoCustCurs")
3944 ENDIF
3945 ENDIF
3946 .tableclose(lcCustPoDiv)
3947 .tableclose('__tmpEmptyDivCurs')
3948 SELECT (pceipcth)
3949 SET ORDER TO (lnPrevIpcthOrder)
3950 *=== TR 1048865 24-Dec-2010 Goutam
3951
3952 ENDWITH
3953 SELECT(lnOldSelect)
3954 RETURN llRetVal
3955 ENDPROC
3956 *=== TR 1023071 NH
3957
3958 *--- TR 1025576 NH
3959 *----------------------------------------------------------------------------------
3960
3961 PROCEDURE CheckForPartialPickInvoice_Hdrlevel
3962 LPARAMETERS pcEipcth
3963 LOCAL llRetVal, lnOldSelect, lcFilter, lcSQL
3964 llRetVal = .t.
3965 lnOldSelect = SELECT()
3966 *-- TR 1042936 OCT-27-2009 BR ADDED: store, ForAllStore to select statement.
3967 SELECT pkey, customer, po_num, store, ForAllStore, ' ' PICKFOUND, ' ' INVOICEFOUND FROM (pcEipcth) INTO CURSOR __temp_zzeipcth
3968
3969 IF RECCOUNT("__temp_zzeipcth") = 0
3970 SELECT(lnOldSelect)
3971 RETURN .t.
3972 ENDIF
3973 LOCAL lcZzeipcth
3974 lcZzeipcth = ""
3975 this.cSQLTempTable =""
3976 llRetVal = llRetVal and this.GenerateSQLTempTable('__temp_zzeipcth')
3977 llRetVal = llRetVal and this.PopulateSQLTempTable('__temp_zzeipcth')
3978 lcZzeipcth = this.cSQLTempTable
3979 USE IN __temp_zzeipcth
3980
3981 *-- TR 1042936 OCT-27-2009 BR
3982 TEXT TO lcSQL NOSHOW
3983 update th set PICKFOUND = 'Y' from zzeipcth Th
3984 inner join zzoordrh h WITH (NOLOCK) on h.po_num = th.po_num and h.customer = th.customer and h.ord_status = 'P'
3985 WHERE th.ForAllStore = 'P'
3986 ENDTEXT
3987 lcSQL = STRTRAN(lcSQL,"zzeipcth",lcZzeipcth)
3988 llRetVal = llRetVal and v_sqlexec(lcSQL)
3989
3990 TEXT TO lcSQL NOSHOW
3991 update th set PICKFOUND = 'Y' from zzeipcth Th
3992 inner join zzoordrh h WITH (NOLOCK) on h.po_num = th.po_num and h.customer = th.customer
3993 and h.ord_status = 'P' and h.store = th.store
3994 WHERE th.ForAllStore <> 'P'
3995 ENDTEXT
3996
3997 lcSQL = STRTRAN(lcSQL,"zzeipcth",lcZzeipcth)
3998 llRetVal = llRetVal and v_sqlexec(lcSQL)
3999
4000
4001 TEXT TO lcSQL NOSHOW
4002 update th set INVOICEFOUND = 'Y' from zzeipcth Th
4003 inner join zzoshprh h WITH (NOLOCK) on h.po_num = th.po_num and h.customer = th.customer
4004 WHERE th.ForAllStore = 'P'
4005
4006 ENDTEXT
4007 lcSQL = STRTRAN(lcSQL,"zzeipcth",lcZzeipcth)
4008 llRetVal = llRetVal and v_sqlexec(lcSQL)
4009
4010 TEXT TO lcSQL NOSHOW
4011 update th set INVOICEFOUND = 'Y' from zzeipcth Th
4012 inner join zzoshprh h WITH (NOLOCK) on h.po_num = th.po_num and h.customer = th.customer and h.store = th.store
4013 WHERE th.ForAllStore <> 'P'
4014 ENDTEXT
4015 *== TR 1042936 OCT-27-2009 BR
4016
4017 lcSQL = STRTRAN(lcSQL,"zzeipcth",lcZzeipcth)
4018 llRetVal = llRetVal and v_sqlexec(lcSQL)
4019 lcSQL = "select * from " + lcZzeipcth + " where PICKFOUND > '' OR INVOICEFOUND > ''"
4020 lcZzeipcth = SYS(2015)
4021 llRetVal = llRetVal and v_sqlexec(lcSQL,lcZzeipcth)
4022
4023 *--- update 860 transaction cursor with error
4024 UPDATE h SET errs_flg_h = 'Y', errs_msg_h = errs_msg_h + IIF(PICKFOUND == 'Y', "Pick order found for this PO." + CHR(13) + CHR(10) ,"") + ;
4025 IIF(INVOICEFOUND == 'Y',"Invoice found for this PO." + CHR(13) + CHR(10) ,"") ;
4026 from (pcEipcth) h inner join (lcZzeipcth) he on h.customer = he.customer AND h.po_num = he.po_num
4027
4028 *--- check for
4029 SELECT(lnOldSelect)
4030 RETURN llRetVal
4031 ENDPROC
4032
4033 *-----------------------------------------------------------------------------------
4034
4035 *--- TR 1027127 NH
4036 PROCEDURE CheckForEmptyStore
4037 LPARAMETERS pceipcTH
4038 LOCAL llRetVal, lnOldSelect
4039 llRetVal = .t.
4040 lnOldSelect = SELECT()
4041
4042 UPDATE h SET ERRS_FLG_H = 'Y', ERRS_MSG_H = ERRS_MSG_H + "Invalid Store code." + CRLF FROM (pceipcTH) h ;
4043 WHERE h.poc_purp <> '01' AND h.store = ' ' AND h.errs_flg_h <> 'Y' AND NOT (po_type = 'BK' OR po_type ='BL' OR po_type = 'KC')
4044
4045 SELECT(lnOldSelect)
4046 RETURN llRetVal
4047 ENDPROC
4048
4049 *=== TR 1027127 NH
4050 *-----------------------------------------------------------------------------------
4051
4052 Procedure GetVerticalOpenOrder(pcZzoordrd_orig,pcRefZzoordrdv_Orig)
4053
4054 Local llRetVal, lnOldSelect, lcUnique, lcSQL
4055 lnOldSelect = Select()
4056 llRetVal = .T.
4057 lcUnique = Sys(2015)
4058 lcZzoordrdv_orig = "#Zzoordrdv_orig" + lcUnique
4059
4060 *--- TR 1072221 27-Jun-14 SK Added field 'edipo4udf1' in the select list ===
4061 *--- need to consider cncl_rsn, cncl_type
4062 *- 1041968 08/26/10 YIK
4063 *- Added field implosion
4064 TEXT TO lcSQL NOSHOW
4065 select fkey, ord_num, pick_num, inv_num, line_seq, line_status, division, style, color_code, lbl_code, dimension,
4066 b.size_num as sizebucket, cncl_rsn, cncl_type,implosion,
4067 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 +
4068 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 +
4069 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 +
4070 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 +
4071 d.size21_qty * b.sz21 + d.size22_qty * b.sz22 + d.size23_qty * b.sz23 + d.size24_qty * b.sz24
4072 as size_qty, edipo4udf1
4073 into #Zzoordrdv_orig
4074 from #zzoordrd_orig d cross join zzxbuckt b
4075 where
4076 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 +
4077 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 +
4078 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 +
4079 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 +
4080 d.size21_qty * b.sz21 + d.size22_qty * b.sz22 + d.size23_qty * b.sz23 + d.size24_qty * b.sz24 > 0
4081 ENDTEXT
4082
4083 lcSQL = Strtran(lcSQL,"#zzoordrd_orig",pcZzoordrd_orig)
4084 lcSQL = Strtran(lcSQL,"#Zzoordrdv_orig",lcZzoordrdv_orig)
4085 llRetVal = llRetVal And v_SQLExec(lcSQL)
4086
4087 pcRefZzoordrdv_orig = lcZzoordrdv_orig
4088 Select(lnOldSelect)
4089 Return llRetVal
4090
4091 Endproc
4092
4093 *-----------------------------------------------------------------------------------------
4094
4095 *---- TR 1022030 NH
4096 Procedure RangeStyle
4097 Lparameters pcTransHeader, pcTransDetail, tcTransSAC, pceipcCR &&, pcViewTransDetail
4098 Local llRetVal, lnOldSelect, lcErrs_Msg
4099 llRetVal = .T.
4100 lnOldSelect = Select()
4101
4102 *****************************************************************************
4103 * 1st Getting all range style (hdr/dtl) that relate to the
4104 * passing order line for this run
4105
4106 * additional past for range style verification/explotion
4107 Select Distinct d.division, d.Style, d.color_code, d.lbl_code, d.Dimension ;
4108 FROM (pcTransHeader) h, (pcTransDetail) d ;
4109 WHERE h.pkey = d.fkey ; && AND h.Errs_flg_h= "N" TR 1019697
4110 And d.Errs_Flg_D= "N" And ;
4111 d.rng_style= '' ; && none exploded range style (ONLY explode range style ONCE)
4112 Order By 1,2,3,4,5 Into Cursor __TmpCursor
4113
4114 With This
4115 .cSQLTempTable=""
4116 If .GenerateSQLTempTable('__TmpCursor')
4117 If .PopulateSQLTempTable('__TmpCursor')
4118 If !Empty(.cSQLTempTable)
4119
4120 .oLog.LogEntry("Exploding range style.")
4121 * Get range style header
4122 *- 1000984 9/11/03 YIK
4123 *- do not explode range styles type 'P'rint
4124 *- Added ..and h.rng_type <> 'P'
4125 LOCAL lcTranTmp
4126 lcTranTmp = .cSQLTempTable
4127 lcSQLString= "select h.* from zzxrangh h," + lcTranTmp + " t " +;
4128 "Where h.division= t.division and h.rng_style = t.style and "+;
4129 "h.rng_color= t.color_code and h.rng_lbl= t.lbl_code and "+;
4130 "h.rng_pack= t.dimension and h.rng_type <> 'P'"
4131 *= 1000984
4132 llRetVal = v_SqlExec(lcSQLString, "__RangH")
4133
4134 * TAN 31891 - JAZ - 5/20/02
4135 * llHaveRangeStyleToExplode= Recc("__RangH")>0
4136 llHaveRangeStyleToExplode= RecCount("__RangH")>0
4137 * End TAN 31891 - JAZ - 5/20/02
4138
4139 If llHaveRangeStyleToExplode
4140
4141 * Get range style detail
4142 *- 1000984 9/11/03 YIK
4143 *- do not explode range styles type 'P'rint
4144 *- Added ..and h.rng_type <> 'P'
4145 lcSQLString= "Select * From zzxrangd where fkey in " +;
4146 "(select h.pkey from zzxrangh h," + lcTranTmp + " t " +;
4147 "Where h.division= t.division and h.rng_style = t.style and "+;
4148 "h.rng_color= t.color_code and h.rng_lbl= t.lbl_code and "+;
4149 "h.rng_pack= t.dimension and h.rng_type <> 'P')"
4150 *= 1000984
4151 llRetVal = v_SqlExec(lcSQLString, "__RangD")
4152
4153 * turn Range detail to vertical (with sizebucket,size_desc)
4154 * have to explode in vertical format
4155 This.CreateCursorStructure("__TmpCursor", "__RangH", "__Range1")
4156 Select sizebucket, size_desc, qty_change as total_qty From (pcTransDetail) ;
4157 WHERE 0=1 Into Cursor __Range2
4158 * tcRangeVer should have Rng_style,color,lbl,pack, rng_type
4159 * style,color_code,lbl_code,dimension, sizebucket, size_desc, total_qty
4160 This.CreateCursorStructure("__Range1", "__Range2", "tcRangeVer")
4161 If Used("__Range1")
4162 Use In __Range1
4163 Endif
4164 If Used("__Range2")
4165 Use In __Range2
4166 Endif
4167
4168 * Need to seek header for Rng_type, Rng_qty during ExplodeRangeRef
4169 Select __RangH
4170 Index On pkey Tag pkey
4171 Select __RangD
4172 Index On division+Style Tag DivStyle
4173 Select tcRangeVer
4174 Index On division+rng_style+rng_color+rng_lbl+rng_pack Tag RangeSKU
4175 Set Order To RangeSKU
4176 This.ExplodeRangeRef("__RangH", "__RangD", "tcRangeVer")
4177
4178 *****************************************************************************
4179 * 2). Validate "Run"- type of range style. divisible by range header qty
4180 If .ValidateRangeStyle("__RangH", pcTransDetail, pcTransHeader)
4181
4182 *****************************************************************************
4183 * 3). Explode range style only once good tran detail that have
4184 * matching range style. Vertical range style explosion
4185 Select Distinct d.pkey ;
4186 FROM __RangD r, (pcTransDetail) d ;
4187 WHERE d.Errs_Flg_D= "N" And ; &&no error
4188 d.rng_style= '' And ; &&never explode before
4189 r.division= d.division And r.rng_style = d.Style And ; && matching range
4190 r.rng_color= d.color_code And r.rng_lbl= d.lbl_code And ; && style
4191 r.rng_pack= d.Dimension ;
4192 ORDER By r.division, r.Style, r.color_code, r.lbl_code, r.Dimension ;
4193 INTO Cursor __DtlExpl
4194 llRetVal= .ExplodeRangeStyleVertical("__DtlExpl", "tcRangeVer", pcTransDetail) &&, pcViewTransDetail
4195 Endif
4196 Endif
4197 Endif
4198 Endif
4199 Endif
4200 Endwith
4201
4202 If Used("__RangH")
4203 Use In __RangH
4204 Endif
4205 If Used("__RangD")
4206 Use In __RangD
4207 Endif
4208 If Used("tcRangeVer")
4209 Use In tcRangeVer
4210 Endif
4211 If Used("__DtlExpl")
4212 Use In __DtlExpl
4213 Endif
4214 If Used("__TmpCursor")
4215 Use In __TmpCursor
4216 Endif
4217
4218 Select(lnOldSelect)
4219 Return llRetVal
4220 Endproc
4221
4222 *-----------------------------------------------------------------------------------
4223
4224 Procedure ExplodeRangeRef
4225 Lparameters pcRangeHeader, pcRangeDetail, pcRangeDetailTarget
4226 Local llRetVal, lnOldSele, lcSizeBucket, lcSizeName, ;
4227 lcDivStyle, lnSourceCnt, lnSofar, lnSizeQty, lnSizePosition
4228
4229 lnOldSele= Select()
4230 lcDivStyle= ""
4231 lnSourceCnt= RecCount(pcRangeDetail)
4232 llRetVal= .T.
4233 lnCurDtlFkey= 0
4234
4235 Select (pcRangeDetail)
4236 Set Order To DivStyle
4237 Scan
4238 If lnCurDtlFkey<> fkey
4239 lnCurDtlFkey= fkey
4240 If Seek(fkey, pcRangeHeader , "PKEY")
4241 m.rng_type = Evaluate(pcRangeHeader + ".rng_type")
4242 m.rng_qty = Evaluate(pcRangeHeader + " .rng_qty")
4243 m.coord_code = Evaluate(pcRangeHeader + ".coord_code")
4244 m.rng_type = Evaluate(pcRangeHeader + ".rng_type")
4245 Else
4246 llRetVal = .F.
4247 Exit
4248 Endif
4249 Endif
4250
4251 * only run once per Div + Style
4252 If !(lcDivStyle == division + Style)
4253 lcDivStyle = division + Style
4254 * Insert a record for each size bucket with a caption *
4255 If !v_GetSizeHeadings(division, Style, "__xSizer")
4256 llRetVal = .F.
4257 Exit
4258 Endif
4259 Endif
4260
4261 Select (pcRangeDetail)
4262 Scatter Memvar Memo
4263 For lnSizePosition = 1 To goEnv.MaxBuckets
4264 lcSizeBucket = "Size" + Trans(lnSizePosition, "@L 99") && zzxsizer bucket field names
4265 lcSizeName = Trim(Eval("__xSizer." + lcSizeBucket)) && zzxsizer bucket Names
4266 lnSizeQty = Eval(lcSizeBucket + "_qty") && zzoordrd bucket qtys
4267 m.sizebucket = lnSizePosition
4268 m.size_desc = lcSizeName
4269 m.total_qty = lnSizeQty
4270 If lnSizeQty > 0 && Only want buckets with activity!
4271 Insert Into (pcRangeDetailTarget) From Memvar
4272 Endif
4273 Endfor
4274
4275 Endscan
4276 This.TableClose("__xSizer")
4277 Select (pcRangeDetail)
4278 Select (lnOldSele)
4279 Return llRetVal
4280 Endproc
4281
4282 *-----------------------------------------------------------------------------------
4283
4284 Procedure ValidateRangeStyle
4285 Lparameters pcRangeStyle, pcTransDetail, pcTransHeader
4286 Local llRetVal, lnOldSelect, lcErrs_Msg
4287 llRetVal = .T.
4288 lnOldSelect = Select()
4289 lcErrs_Msg= "Total Units must be divisible by "
4290
4291 Select (pcRangeStyle)
4292 Index On division+rng_style+rng_color+rng_lbl+rng_pack Tag RngStyle
4293 llRetVal= .SetRelation(pcRangeStyle, "RngStyle", pcTransDetail, ;
4294 "division+style+color_code+lbl_code+dimension")
4295
4296 If llRetVal
4297 .oLog.LogEntry("Validating range style.")
4298 * Verify range style "R"un order in min multiple of rng_qty
4299 * no need for "S"et verification of range type --just explode to
4300 * range detail
4301 Scan For !Empty(__RangH.rng_style) And __RangH.rng_type="R"
4302 *- 1023438 04/06/07 YIK
4303 *- Added ..AND EMPTY(EVALUATE(pcTransDetail + ".ppk_action"))
4304 *- to skip this check for range styles type R that will have their qty converted (ex. MultiUPC)
4305 If Mod(EVALUATE(pcTransDetail + ".qty_change"), __RangH.rng_qty) > 0 AND EMPTY(EVALUATE(pcTransDetail + ".ppk_action"))
4306 Replace Errs_Msg_D With Errs_Msg_D + lcErrs_Msg + Allt(Str(__RangH.rng_qty)) + CRLF, ;
4307 Errs_Flg_D With "Y" ;
4308 IN (pcTransDetail)
4309 Endif
4310 Endscan
4311 Endif
4312
4313 Set Relation To
4314
4315 *--- Error out range style for price variance
4316 *--- User has to change the Range style Reference price to match with the price coming in flat file.
4317 llRetVal = llRetVal and .CheckRangeStylePriceVariance(pcRangeStyle, pcTransDetail, pcTransHeader)
4318
4319 Select(lnOldSelect)
4320 Return llRetVal
4321 Endproc
4322
4323 *-----------------------------------------------------------------------------------
4324
4325 PROCEDURE CheckRangeStylePriceVariance
4326 LPARAMETERS pcRangeStyle, pcTransDetail, pcTransHeader
4327
4328 *--- get customer sales ref
4329 LOCAL lcErrs_Msg, llRetVal, lnOldSelect
4330 llRetVal = .t.
4331 lnOldSelect = SELECT()
4332 lcErrs_Msg = "Cannot check price variance - Price code is missing in transaction header."
4333
4334 UPDATE h SET errs_flg_h = 'Y', Errs_msg_h = h.Errs_msg_h + lcErrs_Msg + CRLF FROM (pcTransHeader) h WHERE h.price_code = ''
4335
4336 IF !This.lRslv_pricecode_cssld && TR 1088126 8-JUL-2015 Venuk
4337
4338 UPDATE d SET Errs_flg_d = 'Y', Errs_msg_d = d.Errs_msg_d + lcErrs_Msg + CRLF ;
4339 FROM (pcTransHeader) h inner join (pcTransDetail) d on h.pkey = d.fkey ;
4340 WHERE h.price_code = ''
4341
4342 *--- compare transaction price with range style price before exploding to its component
4343
4344 UPDATE d SET errs_flg_d = 'Y', Errs_msg_d = d.Errs_msg_d + 'Range style price variance failed - Range style reference ' + h.price_code + ' price is ' + ;
4345 TRANSFORM(IIF(h.price_code = 'A', r.a_price, IIF(h.price_code = 'B', r.b_price,IIF(h.price_code = 'C', r.c_price,;
4346 IIF(h.price_code = 'D', r.d_price, IIF(h.price_code = 'E', r.e_price, 0 )))))) + ;
4347 ', but transaction line item price is ' + TRANSFORM(IIF(d.poc_cost = 0,'0',d.poc_cost)) + CRLF ;
4348 FROM (pcTransHeader) h inner join (pcTransDetail) d on h.pkey = d.fkey ;
4349 inner join (pcRangeStyle) r on r.division = d.division AND r.rng_style = d.style AND r.rng_color = d.color_code ;
4350 AND r.rng_lbl = d.lbl_code AND r.rng_pack = d.rng_pack ;
4351 WHERE d.qualifier in ('AI','RZ','PC') ;
4352 and IIF(h.price_code = 'A', r.a_price, IIF(h.price_code = 'B', r.b_price, IIF(h.price_code = 'C', r.c_price,;
4353 IIF(h.price_code = 'D', r.d_price, IIF(h.price_code = 'E', r.e_price, 0 ))))) <> d.POC_Cost ;
4354 and d.Errs_flg_d <> 'Y' AND d.rng_style = ''
4355
4356 *--- TR 1088126 8-JUL-Venuk
4357 ELSE
4358 lcErrs_Msg = "Cannot check price variance - Price code is missing in transaction detail."
4359
4360 UPDATE d SET Errs_flg_d = 'Y', Errs_msg_d = d.Errs_msg_d + lcErrs_Msg + CRLF ;
4361 FROM (pcTransHeader) h inner join (pcTransDetail) d on h.pkey = d.fkey ;
4362 WHERE d.price_code = ''
4363
4364 UPDATE d SET errs_flg_d = 'Y', Errs_msg_d = d.Errs_msg_d + 'Range style price variance failed - Range style reference ' + d.price_code + ' price is ' + ;
4365 TRANSFORM(IIF(d.price_code = 'A', r.a_price, IIF(d.price_code = 'B', r.b_price,IIF(d.price_code = 'C', r.c_price,;
4366 IIF(d.price_code = 'D', r.d_price, IIF(d.price_code = 'E', r.e_price, 0 )))))) + ;
4367 ', but transaction line item price is ' + TRANSFORM(IIF(d.poc_cost = 0,'0',d.poc_cost)) + CRLF ;
4368 FROM (pcTransHeader) h inner join (pcTransDetail) d on h.pkey = d.fkey ;
4369 inner join (pcRangeStyle) r on r.division = d.division AND r.rng_style = d.style AND r.rng_color = d.color_code ;
4370 AND r.rng_lbl = d.lbl_code AND r.rng_pack = d.rng_pack ;
4371 WHERE d.qualifier in ('AI','RZ','PC') ;
4372 and IIF(d.price_code = 'A', r.a_price, IIF(d.price_code = 'B', r.b_price, IIF(d.price_code = 'C', r.c_price,;
4373 IIF(d.price_code = 'D', r.d_price, IIF(d.price_code = 'E', r.e_price, 0 ))))) <> d.POC_Cost ;
4374 and d.Errs_flg_d <> 'Y' AND d.rng_style = ''
4375
4376 ENDIF
4377 *=== TR 1088126 8-JUL-Venuk
4378
4379 Select(lnOldSelect)
4380 Return llRetVal
4381 Endproc
4382
4383 *-----------------------------------------------------------------------------------
4384
4385 PROCEDURE SetValuesFromCustomerSalesRef
4386 LPARAMETERS pcTransHeader, pcTransDetail
4387 *--- TR 1088126 7-JUL-2015 Venuk. Added param pcTransDetail ===
4388 LOCAL llRetVal , lnOldSelect
4389 llRetVal = .t.
4390 lnOldSelect = SELECT()
4391
4392 IF goEnv.sv("RANK_PRICE_RESOLUTION","N") = 'N'
4393 this.LogEntry("Cannot resolve customer sales ref - missing necessary rank field.")
4394 RETURN llRetVal
4395 ENDIF
4396
4397 * TR 1048519 23-AUG-10 KISHOR - Added ord_type
4398 *--- TR 1053720 6-Sep-2011 Goutam. ord_type is not available so crashing here!!!
4399 *SELECT pkey, customer, store, department, division, ord_type FROM (pcTransHeader) WHERE errs_msg_h <> 'Y' INTO CURSOR __TmpCursor
4400 SELECT pkey, customer, store, department, division, po_num FROM (pcTransHeader) WHERE errs_msg_h <> 'Y' INTO CURSOR __TmpCursor
4401 *=== TR 1053720 6-Sep-2011 Goutam
4402
4403 IF RECCOUNT("__TmpCursor") = 0
4404 lcCheckVariance = .f.
4405 RETURN llRetVal
4406 ENDIF
4407
4408 WITH this
4409 .cSQLTempTable = ""
4410 llRetVal = llRetVal and .GenerateSQLTempTable('__TmpCursor') AND .PopulateSQLTempTable('__TmpCursor') and !Empty(.cSQLTempTable)
4411
4412 * TR 1048519 23-AUG-10 KISHOR - Added ord_type
4413 *--- TR 1053720 6-Sep-2011 Goutam
4414 *lcSql = " select a.rank_seq, a.* from " + ;
4415 " (select t.pkey as h_pkey, ir.* from zzxcslsr ir inner join " + .cSQLTempTable + " t on t.customer = ir.customer " + ;
4416 " and (t.store = ir.store or ir.store = '') and (t.department = ir.department or ir.department = '') " + ;
4417 " and (t.division = ir.division or ir.division = '') " + ;
4418 " and (t.ord_type = ir.ord_type or ir.ord_type = '')) a " + ;
4419 " where exists ( select b.h_pkey from " + ;
4420 " ( select t.pkey as h_pkey, ir.* from zzxcslsr ir " + ;
4421 " inner join " + .cSQLTempTable + " t on t.customer = ir.customer and (t.store = ir.store or ir.store = '') " + ;
4422 " and (t.department = ir.department or ir.department = '') " + ;
4423 " and (t.division = ir.division or ir.division = '') " + ;
4424 " and (t.ord_type = ir.ord_type or ir.ord_type = '') " + ;
4425 " ) b where b.h_pkey = a.h_pkey group by b.h_pkey having min(b.rank_seq) = a.rank_seq) " + ;
4426 " order by a.h_pkey, a.customer, a.store, a.department, a.division, a.ord_type "
4427
4428 *--- TR 1088126 7-JUL-2015 Venuk. Added ir.CRS_pkey field ===
4429 lcSql = " select a.rank_seq, a.* from " + ;
4430 " (select t.pkey as h_pkey, ir.pkey as CRS_pkey, ir.* from zzxcslsr ir inner join " + .cSQLTempTable + " t on t.customer = ir.customer " + ;
4431 " and (t.store = ir.store or ir.store = '') and (t.department = ir.department or ir.department = '') " + ;
4432 " and (t.division = ir.division or ir.division = '') " + ;
4433 " join zzoordrh oh ON(oh.po_num = t.po_num) and (oh.department = t.department or t.department = '') " + ;
4434 " and (oh.division = t.division) and (oh.customer = t.customer) and (oh.ord_type = ir.ord_type or ir.ord_type = '')) a " + ;
4435 " where exists ( select b.h_pkey from " + ;
4436 " ( select t.pkey as h_pkey, ir.* from zzxcslsr ir " + ;
4437 " inner join " + .cSQLTempTable + " t on t.customer = ir.customer and (t.store = ir.store or ir.store = '') " + ;
4438 " and (t.department = ir.department or ir.department = '') " + ;
4439 " and (t.division = ir.division or ir.division = '') " + ;
4440 " join zzoordrh oh ON(oh.po_num = t.po_num) and (oh.department = t.department or t.department = '') " + ;
4441 " and (oh.division = t.division) and (oh.customer = t.customer) and (oh.ord_type = ir.ord_type or ir.ord_type = '') " + ;
4442 " ) b where b.h_pkey = a.h_pkey group by b.h_pkey having min(b.rank_seq) = a.rank_seq) " + ;
4443 " order by a.h_pkey, a.customer, a.store, a.department, a.division, a.ord_type "
4444
4445 *=== TR 1053720 6-Sep-2011 Goutam
4446
4447 *customer, store, department, division, GROUP_TYPE
4448 lcCustSalesRef = "tcCustSalesRef" + SYS(2015)
4449 llRetVal = llRetVal and v_sqlexec(lcSql, lcCustSalesRef)
4450 IF llRetVal
4451 UPDATE h SET price_code = r.price_code FROM (pcTransHeader) h inner join (lcCustSalesRef) r on h.pkey = r.h_pkey
4452 ENDIF
4453
4454 *--- TR 1088126 7-JUL-2015 Venuk
4455 IF This.lRslv_pricecode_cssld
4456 SELECT CRS_pkey,h_pkey, d.pkey pkey , t.division, t.group_type ;
4457 , d.STYLE, d.color_code, d.lbl_code, d.DIMENSION, t.price_code ;
4458 FROM (lcCustSalesRef) t;
4459 JOIN (pcTransDetail) d ;
4460 On t.h_pkey=d.fkey ;
4461 WHERE Errs_flg_d <> 'Y' And t.CRS_pkey> 0 ;
4462 INTO CURSOR __TmpCursorDet
4463
4464 .cSQLTempTable = ""
4465 llRetVal = llRetVal and .GenerateSQLTempTable('__TmpCursorDet') AND .PopulateSQLTempTable('__TmpCursorDet') and !Empty(.cSQLTempTable)
4466
4467
4468 lcPriceCode = IIF(This.lRslv_pricecode_cssld," case when d.price_Code='' then h.price_code else d.price_code end as price_Code", ;
4469 " h.price_code")
4470 IF llRetVal
4471 lcSql = "select " + ;
4472 " case when d.price_Code='' then h.price_code else d.price_code end as price_Code, "+ ;
4473 " t.* " + ;
4474 " from " + .cSQLTempTable + " t " +;
4475 " join zzxscolr s on s.division = t.division" +;
4476 " and s.style = t.style and s.color_code = t.color_code and s.lbl_code=t.lbl_code " + ;
4477 " and s.dimension = t.dimension " + ;
4478 " join zzxcslsd d on d.fkey = t.crs_pkey and d.group_code = case t.group_type "+;
4479 " when 'A' then s.group_code1"+;
4480 " when 'B' then s.group_code2"+;
4481 " when 'C' then s.group_code3"+;
4482 " when 'D' then s.group_code4"+;
4483 " when 'E' then s.group_code5"+;
4484 " when 'F' then s.group_code6"+;
4485 " when 'G' then s.group_code7"+;
4486 " when 'H' then s.group_code8"+;
4487 " when 'I' then s.group_code9"+;
4488 " when 'J' then s.group_code10"+;
4489 " when 'K' then s.group_code11"+;
4490 " when 'L' then s.group_code12"+;
4491 " when 'M' then s.group_code13"+;
4492 " end and d.group_type = t.group_type " + ;
4493 " join zzxcslsr h on d.fkey = h.pkey "
4494
4495 llRetVal = v_sqlExec(lcSql , "tmpcslsd")
4496 Select tmpcslsd
4497 Index On pkey Tag pkey
4498 Select (pcTransDetail)
4499 llRetVal= llRetVal And .SetRelation(pcTransDetail, "pkey", "tmpcslsd", "pkey")
4500
4501 IF llRetVal
4502 REPLACE ALL price_code WITH tmpcslsd.Price_code IN (pcTransDetail)
4503 ENDIF
4504
4505 SET RELATION TO
4506 ENDIF
4507 .TableClose("tmpcslsd")
4508 .TableClose("__TmpCursorDet")
4509 ELSE
4510 UPDATE d SET price_code = h.price_code FROM (pcTransDetail) d inner join (pcTransHeader) h on h.pkey = d.fkey WHERE d.price_code=''
4511 ENDIF
4512 *=== TR 1088126 7-JUL-2015 Venuk
4513
4514 ENDWITH
4515
4516 Select(lnOldSelect)
4517 Return llRetVal
4518 Endproc
4519
4520 *-----------------------------------------------------------------------------------
4521 *- TR 1054193 FH 5/13/11
4522 PROCEDURE ValidateIfControlReferenceExist
4523 LPARAMETERS pceipcTH, pceipcCR
4524 LOCAL llRetVal, lnOldSelect, lcDivision, lcCustomer
4525 llRetVal = .t.
4526 lnOldSelect = SELECT()
4527
4528 *--- TR 1054768 4-Jul-2011 Goutam. now onwards we will take only cr_pkey for finding control record. not customer and division
4529 *Select distinct Customer, division from (pceipcTH) into cursor _tmpCustDiv
4530 Select distinct Customer, division, cr_pkey from (pceipcTH) into cursor _tmpCustDiv
4531 *=== TR 1054768 4-Jul-2011 Goutam
4532
4533 Select _tmpCustDiv
4534 SCAN
4535
4536 lcDivision = _tmpCustDiv.Division
4537 lcCustomer = _tmpCustDiv.Customer
4538
4539 *--- TR 1056420 26-Sep-11 SK Seeking for division and customer (Reverting 1054768)
4540 *--- TR 1054768 4-Jul-2011 Goutam.
4541 IF NOT SEEK(lcdivision+lccustomer, "zzeipccr", "divcust")
4542 *IF NOT (SEEK(_tmpCustDiv.cr_pkey , "zzeipccr", "pkey") AND zzeipccr.division = lcDivision)
4543 *=== TR 1054768 4-Jul-2011 Goutam.
4544 *=== TR 1056420 26-Sep-11 SK
4545
4546 *--- TR 1054768 4-Jul-2011 Goutam. Errs_Msg_H is overwriting existing error. This is wrong. we should always append error
4547 replace errs_flg_h WITH 'Y', Errs_Msg_H WITH Errs_Msg_H + 'EDI Control for Customer '+ customer +'and Division '+ ;
4548 division + ' not found.' + CRLF IN (pceipcTH) FOR CUSTOMER = lcCustomer and Division = lcDivision
4549
4550 *--- TR 1056420 26-Sep-11 SK Updating correct Pkey to CR_PKEY
4551 ELSE
4552 UPDATE (pceipcTH) SET cr_PKEY = zzeipccr.PKey WHERE division = lcdivision AND customer = lccustomer
4553 ENDIF
4554 *=== TR 1056420 26-Sep-11 SK
4555 ENDSCAN
4556
4557
4558 If Used("_tmpCustDiv")
4559 Use In _tmpCustDiv
4560 Endif
4561
4562
4563 SELECT(lnOldSelect)
4564 RETURN llRetval
4565 ENDPROC
4566 *- TR 1054193 FH 5/13/11
4567 *-----------------------------------------------------------------------------------
4568
4569 Procedure ExplodeRangeStyleVertical
4570 Lparameters pcDetailtoExplode, pcRangeDetailVert, pcTransDetail, tcTransSAC &&, pcViewTransDetail
4571 Local llRetVal, lnOldSelect, lcErrs_Msg
4572 llRetVal = .T.
4573 lnOldSelect = Select()
4574
4575 Select (pcDetailtoExplode)
4576 Scan
4577 * Find detail line that need range style exploding using PKEY
4578 If Seek(pkey, pcTransDetail, "Pkey")
4579 * Current working trans detail
4580 Select (pcTransDetail)
4581 lcCurOurSKU= division+Style+color_code+lbl_code+Dimension
4582 *lnCurDtlTotal_qty= total_qty
4583 lnCurDtlTotal_qty= qty_change
4584
4585 * PL 05/07/02 31911 - JCPenny prepack ordering process (--using range Style)
4586 *- 1009508 3/16/05 YIK
4587 *- lnRangeBucket= &pcTransDetail..Sizebucket && need to record range bucket latter
4588 lnRangeBucket = sizebucket
4589
4590 Scatter Name loTransDetail Memo
4591 * delete current working trans detail already have image
4592 * in loTransDetail
4593 Delete In (pcTransDetail)
4594 * --- TR 1018184 RLN 01/10/07
4595*!* lnDetailPkey = loTransDetail.pkey
4596*!* Select * From (tcTransSAC) Where dfkey = lnDetailPkey Into Cursor tmpRngSacs
4597 * === TR 1018184
4598
4599 Select (pcRangeDetailVert)
4600 * Find 1st match of OURSKU
4601 If Seek(lcCurOurSKU, pcRangeDetailVert , "RangeSKU")
4602 * calculate lnMultiplier regardless of rng_type
4603 * --"R"un only divisible by rng_qty will get to this point
4604 * --otherwise will stay in errs_dtl_F/msg
4605
4606 lnMultiplier= Iif(rng_type='S', lnCurDtlTotal_qty, ;
4607 lnCurDtlTotal_qty/rng_qty)
4608
4609 Scan While llRetVal And !Eof(pcRangeDetailVert) And ;
4610 (lcCurOurSKU= division+ rng_style + rng_color + rng_lbl + rng_pack)
4611 * Exploding detail line
4612 *loTransDetail.pkey = v_nextPkey("ZZEIPOID") && Never reassign Pkey in TD
4613 loTransDetail.pkey = v_nextPkey("ZZEIPCTD") && Never reassign Pkey in TD
4614 If !Empty(loTransDetail.pkey)
4615 *- 1009508 3/16/05 YIK
4616 Select (pcRangeDetailVert)
4617 Scatter Name loVert Memo
4618 *= 1009508
4619
4620 Select (pcTransDetail)
4621 Append Blank
4622 Gather Name loTransDetail Memo
4623
4624 * PL 07/18/00 4186 EDI - add Range Style price resolution (code A-E)
4625 * resolve proper a..e_price latter when have price_code(CustSalesResv)
4626 * only recording a..e_price to zzeipoth and resetting org_price
4627 *org_price with &pcRangeDetailVert..a_price,
4628
4629 *- do not zero out org_price for MultiUPC
4630 Replace rng_style With loVert.rng_style, ;
4631 rng_color With loVert.rng_color, ;
4632 rng_lbl With loVert.rng_lbl, ;
4633 rng_pack With loVert.rng_pack, ;
4634 rng_bk With lnRangeBucket, ;
4635 rng_qty With loVert.rng_qty, ;
4636 rng_type With loVert.rng_type, ;
4637 qty_change With lnMultiplier * loVert.total_qty, ;
4638 sizebucket With loVert.sizebucket, ;
4639 size_desc With loVert.size_desc, ;
4640 division With loVert.division, ;
4641 STYLE With loVert.Style, ;
4642 color_code With loVert.color_code, ;
4643 lbl_code With loVert.lbl_code, ;
4644 DIMENSION With loVert.Dimension, ;
4645 org_price WITH org_price, ; && 4186- reset org_price when exploding range style
4646 upc With '', ;
4647 sku With '' ;
4648 a_price WITH loVert.a_price,; && 4186- store a..e_price
4649 b_price WITH loVert.b_price,; && from range style detail
4650 c_price WITH loVert.c_price,; && to use latter when have
4651 d_price WITH loVert.d_price,; && price_code
4652 e_price WITH loVert.e_price ;
4653 IN (pcTransDetail)
4654 *= 1009508 03/16/05 YIK
4655 * --- TR 1018184 RLN 01/10/07
4656*!* Select tmpRngSacs
4657*!* Scan
4658*!* Scatter Name loTmpSACs Memo
4659*!* loTmpSACs.pkey = v_nextPkey("ZZEIPOISAC")
4660*!* loTmpSACs.dfkey = loTransDetail.pkey
4661*!* Insert Into (tcTransSAC) From Name loTmpSACs
4662*!* Endscan
4663 * === TR 1018184
4664 Else
4665 llRetVal= .F. && Cannot get Pkey from bcsysnum
4666 Exit
4667 Endif
4668
4669 Select (pcRangeDetailVert)
4670 Endscan
4671 Else
4672 llRetVal= .F. && Should be in pcrangdetailvert
4673 Exit
4674 Endif
4675 *Delete From (tcTransSAC) Where dfkey = lnDetailPkey
4676 Endif
4677
4678 If !llRetVal &&Get out of scan when have some problem
4679 Exit
4680 Endif
4681 Endscan
4682
4683 Select(lnOldSelect)
4684 Return llRetVal
4685 ENDPROC
4686
4687 *-----------------------------------------------------------------------------------
4688
4689 PROCEDURE ResolvePriceFromRangeStyle
4690 LPARAMETERS pcTransHeader, pcTransDetail
4691 LOCAL llRetVal, lnOldSelect, lcErrs_Msg, lcPrice_code
4692 llRetVal = .T.
4693 lnOldSelect = SELECT()
4694
4695 SELECT (pcTransDetail)
4696 SET ORDER TO
4697 llRetVal= .SetRelation(pcTransHeader, "pkey", pcTransDetail, "fkey")
4698 IF llRetVal
4699 * For each range style previously exploded if have header price_code
4700 * then start resolving proper price to org_price using a..e_price
4701 SELECT (pcTransDetail)
4702 *- 1009508 03/16/05 YIK
4703 *-- SCAN FOR !EMPTY(&pcTransDetail..rng_style) && Range style only
4704 *-- IF !EMPTY(&pcTransHeader..price_code) AND ; && empty when error on header
4705 *-- EMPTY(&pcTransDetail..org_price) && resolve only once--future could open up UI
4706 SCAN FOR !EMPTY(rng_style) && Range style only
4707 *--- TR 1088126 8-JUL-2015 Venuk.
4708 IF This.lRslv_pricecode_cssld
4709 lcPrice_code = EVALUATE(pcTransDetail + ".price_code")
4710 ELSE
4711 *=== TR 1088126 8-JUL-2015 Venuk.
4712 lcPrice_code = EVALUATE(pcTransHeader + ".price_code")
4713 ENDIF && TR 1088126 8-JUL-2015 Venuk.
4714 IF !EMPTY(lcPrice_code) AND ; && empty when error on header
4715 EMPTY(org_price) && resolve only once--future could open up UI
4716 *= 1009508
4717 lnPrice= EVAL(pcTransDetail+ "." + lcPrice_code + "_price")
4718 IF lnPrice>0
4719 *REPLACE org_price WITH lnPrice IN (pcTransDetail)
4720 REPLACE poc_cost WITH lnPrice IN (pcTransDetail)
4721 ENDIF
4722 ENDIF
4723 ENDSCAN
4724 ENDIF
4725
4726 SET RELATION TO
4727 SELECT(lnOldSelect)
4728 RETURN llRetVal
4729 ENDPROC
4730
4731 *==== TR 1022030 NH
4732 *-----------------------------------------------------------------------------------
4733
4734 *--- TR 1028744 19-FEB-2008 VKK
4735 ***********************************************************************************
4736 PROCEDURE CheckHardLink
4737 LPARAMETERS pnOrd_num
4738 LOCAL llRetVal, lnOldSelect, llCheckhardLink
4739 llRetVal= .T.
4740 lnOldSelect= SELECT()
4741
4742 WITH THIS
4743
4744 *--- TR 1048865 27-Dec-2010 Goutam
4745 *IF SEEK(Vzzoordrh_860I.division + Vzzoordrh_860I.customer , "zzeipccr","divCust")
4746 IF SEEK(Vzzoordrh_860I.cr_pkey , "zzeipccr", "pkey")
4747 *=== TR 1048865 27-Dec-2010 Goutam
4748
4749 llCheckHardlink = (zzeipccr.check_hdlk = 'Y')
4750 ENDIF
4751
4752 IF llCheckHardlink
4753 lcSQLString= "Select TOP 1 ord_num FROM zzoordud Where ord_num = " + SQLFormatNum(pnord_num)
4754
4755 llRetVal = v_SQLExec(lcSQLString, "_HardLink") AND EOF("_HardLink")
4756
4757 IF NOT llRetVal
4758 .RecordHeaderError("Order linked with Production Order cannot be changed.")
4759 ENDIF
4760
4761 .TableClose("_HardLink")
4762 ENDIF
4763
4764 ENDWITH
4765
4766 SELECT(lnOldSelect)
4767 RETURN llRetVal
4768 ENDPROC
4769
4770 *=== TR 1028744 19-FEB-2008 VKK
4771
4772 **********************************************************************************************
4773 *--- TR 1039757 18-Aug-2009 Goutam.
4774
4775 PROCEDURE MoveNZtoRZ
4776 LOCAL llRetVal, lnOldSelect, lcSql, lcFilter
4777
4778 lnOldSelect = SELECT()
4779 .cNZLocalCursor = GetUniqueFileName()
4780
4781 lcFilter = IIF (EMPTY(this.cFilterCriteria),"",THIS.cFilterCriteria)
4782 lcFilter = STRTRAN(lcFilter,"H.","TH.")
4783 lcFilter = STRTRAN(lcFilter,"Where","")
4784
4785 lcSql = "Select td.pkey from zzeipctd td join zzeipcth th on th.pkey = td.fkey " + ;
4786 "where td.qualifier = 'NZ' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)
4787 llRetVal = v_sqlexec(lcSQL, .cNZLocalCursor)
4788
4789 lcSql = "update td set td.qualifier = 'RZ' " + ;
4790 "from zzeipctd td join zzeipcth th on th.pkey = td.fkey where td.qualifier = 'NZ' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)
4791
4792 llRetVal = llRetVal and v_sqlexec(lcSQL)
4793
4794 SELECT(lnOldSelect)
4795 RETURN llRetVal
4796 ENDPROC
4797
4798 PROCEDURE RevertFromRZtoNZ
4799 LOCAL llRetVal, lnOldSelect, lcSql
4800
4801 lnOldSelect = SELECT()
4802
4803 IF .GenerateSQLTempTable(.cNZLocalCursor) AND .PopulateSQLTempTable(.cNZLocalCursor) AND !EMPTY(.cSQLTempTable)
4804 lcSQL = "update td set td.qualifier = 'NZ' from zzeipctd td join " + .cSQLTempTable + " tmp " + ;
4805 " on tmp.pkey = td.pkey where td.qualifier = 'RZ'"
4806
4807 llRetVal = v_sqlexec(lcSQL)
4808
4809 ENDIF
4810
4811 .tableclose(.cNZLocalCursor)
4812
4813 SELECT(lnOldSelect)
4814 RETURN llRetVal
4815 ENDPROC
4816
4817 PROCEDURE AddNewOrderForNZ
4818
4819 LOCAL llRetVal, lnOldSelect, lcipcth_key, lcSql, lcipcth_New, lcipctd_New, lcFilter, lcSubSql, lcUser_ID, ;
4820 ltLast_mod, lnHCount, lnDCount, lcSQLTempTable, lcInsertSql, lcDtlInsertSql, lcDtlSQL, lcUpdateSql, ;
4821 lcUpdateDtlSql, lcipcPkey_New, lcipcMain_New, lcipcOrder_New, lnTotalOrder
4822
4823 *--- TR 1048865 03-May-2011 Goutam
4824 LOCAL lcipcOrder_Exists
4825 *=== TR 1048865 03-May-2011 Goutam
4826
4827 llRetVal = true
4828 lnOldSelect = SELECT()
4829 lcUser_ID = EDI_USER
4830 ltLast_mod = DATETIME()
4831 lnTotalOrder = 1
4832
4833 IF NOT USED(.cNZLocalCursor) OR RECCOUNT(.cNZLocalCursor) = 0
4834 .tableclose(.cNZLocalCursor)
4835 RETURN llRetVal
4836 ENDIF
4837
4838 llRetVal = llRetVal and .RevertFromRZtoNZ()
4839
4840 *--- TechRec 1073669 02-Oct-2013 GSternik ---
4841 *-- This all should not be so complicated:
4842 *-- The transaction maintenance table already has ALL the matching and the new order lines.
4843 *-- the Matching ones have Ord_Num > 0, and the New ones : 0 (as you can guess)
4844 *-- So, for the matching ones we just need to replace 'NZ' with 'RZ'
4845 *-- for the new ones: replace 'NZ' with AI
4846 *-- after that we have to find the Order Stores/SKUs/Lines which are not specified in the Transaction Maint.
4847 *-- and add them to it with 'DI' qualifier.
4848 *-- the "missing ones" (in zzoordrh/d) search criteria is:
4849 *-- Same Customer, PO_Num, and SKU/Bkt exists for the different store in TM but not for SO Store.
4850 #DEFINE GS_1073669
4851 *--==============================================
4852 #IFNDEF GS_1073669 && Per Yuri's request made the TR 1073669 changes easily undoable
4853 *--==============================================
4854
4855 lcipcth_New = "#Zzeipcth_newNZ" + SYS(2015)
4856 lcipctd_New = "#Zzeipctd_newNZ" + SYS(2015)
4857 lcipcMain_New = "#ZzeipcMain_newNZ" + SYS(2015)
4858 lcipcPkey_New = "#ZzeipcPkey_newNZ" + SYS(2015)
4859 lcipcOrder_New = "#ZzeipcOrder_newNZ" + SYS(2015)
4860
4861 *--- TR 1048865 03-May-2011 Goutam
4862 lcipcOrder_Exists = "#ZzeipcOrder_ExistsNZ" + SYS(2015)
4863 *=== TR 1048865 03-May-2011 Goutam
4864
4865 lcFilter = IIF (EMPTY(this.cFilterCriteria),"",THIS.cFilterCriteria)
4866 lcFilter = STRTRAN(lcFilter,"H.","TH.")
4867 lcFilter = STRTRAN(lcFilter,"Where","")
4868
4869 *-- GS: The "query" below tries to get the Trx Details with Stores where SOD already exists, just to change NZ to RZ later.
4870 *-- lcipcOrder_Exists is used only for this purpose, so there is no need to create it.
4871 *--- TR 1048865 03-May-2011 Goutam
4872 lcSql = " select distinct tmp.pkey, tmpd.pkey as dtlPkey, t.ord_num, t.store, t.edi_store, tmpd.fkey " + ;
4873 " into " + lcipcOrder_Exists + ;
4874 " from " + ;
4875 " (select h.customer, h.po_num, h.ord_num, h.store, st.edi_store, d.division, d.style, d.color_code, d.lbl_code, d.dimension, d.Size_Bk, d.line_seq, d.total_qty " + ;
4876 " from zvoordrdv d join zzoordrh h on h.pkey = d.fkey " + ;
4877 " join zzxstorr st on st.customer = h.customer and st.store = h.store where " + ;
4878 " exists(select 1 from zzeipcth th join zzeipctd td on td.fkey = th.pkey where" + ;
4879 " td.division = d.division and td.style = d.style and td.color_code = d.color_code and " + ;
4880 " td.lbl_code = d.lbl_code and td.dimension = d.dimension and td.sizebucket = d.Size_Bk and h.po_num = th.po_num and h.customer = th.customer " + ;
4881 " and td.qualifier = 'NZ' and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter) + ;
4882 " and h.ord_status = 'O')) t" + ;
4883 " join zzeipcth tmp " + ;
4884 " join zzeipctd tmpd on tmpd.fkey = tmp.pkey " + ;
4885 " on t.division = tmp.division and t.store = tmp.store and t.customer = tmp.customer and t.po_num = tmp.po_num " + ;
4886 " and t.style = tmpd.style and t.color_code = tmpd.color_code and t.lbl_code = tmpd.lbl_code and t.dimension = tmpd.dimension and t.Size_Bk = tmpd.sizebucket "
4887
4888 llRetVal = llRetVal and v_sqlexec(lcSQL)
4889 *-- This "query" tries to get the SOD/SOH keys with matching Trx Details, but Store(!) (see subselect "t"),
4890 *-- and then joins them to TranD/H
4891 *-- the first part of this SQL is the same as the 1st one, but there is no:
4892 *-- " and t.store = tmp.store" match between the subquery "t" and zzeipcth, these recors excluded by the last EXISTS subselect.
4893 *-- Because my first SQL already marked these records as RZ, they will be excluded by default.
4894
4895 *-- the result is the catesian join between Ord_num, Store, Edi_Store from SOH and the coresponding zzeipctd Keys (by Customer,PO_Num,SKU/UPC)
4896 *-- I.E. if for the same Customer/PO/UPC my new zzeipcth/d data has 3 details with PKeys 1,2,3 for stores '01','04','05'
4897 *-- and SOH have stores '01','02','03' (ord nums 101,102,103) the result will be 4 records:
4898 *-- 2, 102, '02'; 3, 102, '02'; 2, 103, '03'; 3, 103, '03';
4899
4900 *=== TR 1048865 03-May-2011 Goutam
4901
4902 * --- TR 1048874 9/23/10 CM --- Added tmpd.fkey
4903 *--- TR 1048865 26-Apr-2011 Goutam. Removed zzoordrd from the following sql and replaced with zvoordrdv and additional join with sizebucket = Size_Bk
4904 lcSql = " select distinct tmp.pkey, tmpd.pkey as dtlPkey, t.ord_num, t.store, t.edi_store, tmpd.fkey " + ;
4905 " into " + lcipcMain_New + ;
4906 " from " + ;
4907 " (select h.customer, h.po_num, h.ord_num, h.store, st.edi_store, d.division, d.style, d.color_code, d.lbl_code, d.dimension, d.Size_Bk, d.line_seq, d.total_qty " + ;
4908 " from zvoordrdv d join zzoordrh h on h.pkey = d.fkey " + ;
4909 " join zzxstorr st on st.customer = h.customer and st.store = h.store where " + ;
4910 " exists(select 1 from zzeipcth th join zzeipctd td on td.fkey = th.pkey where" + ;
4911 " td.division = d.division and td.style = d.style and td.color_code = d.color_code and " + ;
4912 " td.lbl_code = d.lbl_code and td.dimension = d.dimension and td.sizebucket = d.Size_Bk and h.po_num = th.po_num and h.customer = th.customer " + ;
4913 " and td.qualifier = 'NZ' and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter) + ;
4914 " and h.ord_status = 'O')) t" + ;
4915 " join zzeipcth tmp " + ;
4916 " join zzeipctd tmpd on tmpd.fkey = tmp.pkey " + ;
4917 " on t.division = tmp.division and t.customer = tmp.customer and t.po_num = tmp.po_num " + ;
4918 " and t.style = tmpd.style and t.color_code = tmpd.color_code and t.lbl_code = tmpd.lbl_code and t.dimension = tmpd.dimension and t.Size_Bk = tmpd.sizebucket " + ;
4919 " where not exists(select 1 from zzeipcth th join zzeipctd td on td.fkey = th.pkey where " + ;
4920 " td.division = t.division and td.style = t.style and td.color_code = t.color_code and " + ;
4921 " td.lbl_code = t.lbl_code and td.dimension = t.dimension and td.sizebucket = t.Size_Bk and th.po_num = t.po_num and th.customer = t.customer " + ;
4922 " and th.store = t.store and th.edi_store = t.edi_store and td.qualifier = 'NZ' and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter) + ")"
4923
4924 llRetVal = llRetVal and v_sqlexec(lcSQL)
4925
4926
4927 *-- GS: this query enumerates the existing orders with no zzeipctd/h match
4928 lcSql = " select distinct counter = IDENTITY(int,1,1), ord_num, store, edi_store " + ;
4929 " into " + lcipcOrder_New + " from " + lcipcMain_New + " select @@Rowcount as TotalOrder"
4930 llRetVal = llRetVal and v_sqlexec(lcSQL, "__TotalOrderCursor")
4931
4932 IF llRetVal
4933 lnTotalOrder = IIF(__TotalOrderCursor.TotalOrder = 0, 1, __TotalOrderCursor.TotalOrder)
4934 ENDIF
4935
4936 *-- GS: this query enumerates the new orders(stores) from zzeipctH/D with no SOH match which can be covered by the SOH/SOD orders we do not need anymore
4937
4938 * --- TR 1048874 9/23/10 CM --- Added fkey
4939 * By adding fkey, this query can be used to cover more angles when we determine whether we need to
4940 * add details to PO's or delete them.
4941*!* lcSql = " select distinct top " + ALLTRIM(STR(lnTotalOrder)) + " counter = IDENTITY(int,1,1), pkey, dtlPkey " + ;
4942*!* " into " + lcipcPkey_New + " from " + lcipcMain_New
4943 lcSql = " select distinct top " + ALLTRIM(STR(lnTotalOrder)) + " counter = IDENTITY(int,1,1), pkey, dtlPkey, fkey " + ;
4944 " into " + lcipcPkey_New + " from " + lcipcMain_New
4945 llRetVal = llRetVal and v_sqlexec(lcSQL)
4946 * === TR 1048874 9/23/10 CM
4947
4948 *-- GS: Trx Headers to match to the existing non-matching orders (query simplified):
4949 *lcSubSql = "select 1 from " + lcipcPkey_New + " where pkey = h.pkey"
4950 *lcSQL = "SELECT * into " + lcipcth_New + " FROM zzeipcth h where exists(" + lcSubSql + ") "
4951 lcSQL = "SELECT * into " + lcipcth_New + " FROM zzeipcth h where exists (select 1 from " + lcipcPkey_New + " where pkey = h.pkey) "
4952
4953 llRetVal = llRetVal and v_sqlexec(lcSQL)
4954
4955
4956 *-- GS: WTF is this????
4957 * --- TR 1048874 9/23/10 CM --- We could be deleting more than 1 detail at a time for
4958 * the same po, before the process was not able to handle this.
4959*!* lcSubSql = "select 1 from " + lcipcPkey_New + " where dtlPkey = d.pkey"
4960 lcSubSql = "Select * from " + lcipcPkey_New + " where fkey = d.fkey"
4961 * === TR 1048874 9/23/10 CM
4962
4963 *--- TR 1048865 21-Apr-2011 Goutam
4964 *lcSQL = "SELECT * into " + lcipctd_New + " FROM zzeipctd d where exists(" + lcSubSql + ") "
4965 lcSQL = "SELECT * into " + lcipctd_New + " FROM zzeipctd d where exists(" + lcSubSql + ") " + ;
4966 " and pkey = (select top 1 pkey from zzeipctd td where td.FKEY = d.FKEY)"
4967 *=== TR 1048865 21-Apr-2011 Goutam
4968
4969 *-- GS: in other words:
4970 lcSQL = ;
4971 "select *"+;
4972 " into " + lcipctd_New +;
4973 " from zzeipctd d"+;
4974 " where exists ( "+;
4975 "select *"+;
4976 " from " + lcipcPkey_New +;
4977 " where fkey = d.pkey) "+;
4978 " and pkey = ("+;
4979 "select top 1 pkey"+;
4980 " from zzeipctd td"+;
4981 " where td.FKEY = d.FKEY)"
4982
4983 llRetVal = llRetVal and v_sqlexec(lcSQL)
4984
4985 lcSQL = "UPDATE h SET store = oh.store, edi_store = oh.edi_store, ord_num = oh.ord_num " + ;
4986 ", User_ID = " + sqlformatchar(lcUser_ID) + ", Last_mod = " + sqlformatts(ltLast_mod) + ;
4987 " FROM " + lcipcth_New + " h join " + lcipcPkey_New + " tmp " + ;
4988 " on tmp.pkey = h.pkey join " + lcipcOrder_New + " oh on oh.counter=tmp.counter"
4989
4990 llRetVal = llRetVal and v_sqlexec(lcSQL)
4991
4992 *--- TR 1048865 21-Apr-2011 Goutam. Deleted below
4993*!* lcSQL = "Select pkey, pkey-pkey as newPkey, (select COUNT(*) from " + lcipctd_New + ") as Rec_Count from " + lcipctd_New
4994*!* llRetVal = llRetVal and v_sqlexec(lcSQL, '__tmpDPkeyUpdate')
4995
4996*!* lcSQL = "Select pkey, pkey-pkey as newPkey, (select COUNT(*) from " + lcipcth_New + ") as Rec_Count from " + lcipcth_New
4997*!* llRetVal = llRetVal and v_sqlexec(lcSQL, '__tmpHPkeyUpdate')
4998
4999*!* IF llRetVal
5000*!* lnHCount = __tmpHPkeyUpdate.Rec_Count
5001*!* lnDCount = __tmpDPkeyUpdate.Rec_Count
5002*!* ENDIF
5003
5004
5005*!* IF llRetVal AND lnHCount > 0 AND lnDCount > 0
5006
5007*!* lnMaxNumber = v_nextPkey("zzeipcth",lnHCount)
5008*!* SELECT __tmpHPkeyUpdate
5009*!* replace ALL newPkey WITH (lnMaxNumber-lnHCount+RECNO()) IN __tmpHPkeyUpdate
5010*!*
5011*!* lnMaxNumber = v_nextPkey("zzeipctd",lnDCount)
5012*!* SELECT __tmpDPkeyUpdate
5013*!* replace ALL newPkey WITH (lnMaxNumber-lnDCount+RECNO()) IN __tmpDPkeyUpdate
5014
5015*!* .cSQLTempTable=""
5016*!* llRetVal = llRetVal and ;
5017*!* .GenerateSQLTempTable('__tmpHPkeyUpdate') AND .PopulateSQLTempTable('__tmpHPkeyUpdate') AND !EMPTY(.cSQLTempTable)
5018*!* IF llRetVal
5019*!* lcSQLTempTable = .cSQLTempTable
5020*!* lcSQL = "Update th set th.pkey = tmp.newPkey " + ;
5021*!* " From " + lcipcth_New + " th join " + lcSQLTempTable + " tmp " + ;
5022*!* " on tmp.pkey = th.pkey"
5023*!*
5024*!* lcInsertSql = "insert into zzeipcth select * from " + lcipcth_New
5025
5026*!* ENDIF
5027
5028*!* .cSQLTempTable=""
5029*!* llRetVal = llRetVal and ;
5030*!* .GenerateSQLTempTable('__tmpDPkeyUpdate') AND .PopulateSQLTempTable('__tmpDPkeyUpdate') AND !EMPTY(.cSQLTempTable)
5031*!* IF llRetVal
5032*!* lcDtlSQL = "Update td set td.pkey = tmp.newPkey " + ;
5033*!* " From " + lcipctd_New + " td join " + .cSQLTempTable + " tmp " + ;
5034*!* " on tmp.pkey = td.pkey"
5035*!*
5036*!* lcUpdateSql = "update td set td.fkey = tmp.newpkey, td.qualifier = 'DI' " + ;
5037*!* " from " + lcSQLTempTable + " tmp " + ;
5038*!* " join " + lcipctd_New + " td " + ;
5039*!* " on td.fkey = tmp.pkey "
5040
5041*!* lcDtlInsertSql = "insert into zzeipctd select * from " + lcipctd_New
5042
5043*!* lcSubSql = "Select 1 from zzeipcth th where pkey = td.fkey and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)
5044*!* lcUpdateDtlSql = "Update td set td.qualifier = 'RZ' " + ;
5045*!* " From zzeipctd td where td.qualifier = 'NZ' " + ;
5046*!* " and exists( " + lcSubSql + ")"
5047*!* ENDIF
5048
5049 IF llRetVal
5050
5051 lcSubSql = "Select 1 from zzeipcth th where pkey = td.fkey and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)
5052 lcUpdateSql = "Update td set td.qualifier = 'RZ' " + ;
5053 " From zzeipctd td where td.qualifier = 'NZ' " + ;
5054 " and exists(select 1 from " + lcipcOrder_Exists + " where dtlpkey = td.pkey) " + ;
5055 " and exists( " + lcSubSql + ")"
5056
5057 lcSubSql = "Select 1 from zzeipcth th where pkey = td.fkey and th.errs_flg_h <> 'Y' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)
5058 lcUpdateDtlSql = "Update td set td.qualifier = 'AI' " + ;
5059 " From zzeipctd td where td.qualifier = 'NZ' " + ;
5060 " and exists( " + lcSubSql + ")"
5061 *=== TR 1048865 21-Apr-2011 Goutam. Added above and Deleted before added above
5062
5063 IF llRetVal
5064
5065 llBeganTransaction = THIS.BeginTransaction()
5066
5067 *--- TechRec 1073669 02-Oct-2013 GSternik : What if the transaction alredy started before????
5068 IF llBeganTransaction
5069
5070 *--- TR 1048865 13-Apr-2011 Goutam
5071*!* llRetVal = llRetVal and v_sqlexec(lcSQL)
5072*!* llRetVal = llRetVal and v_sqlexec(lcDtlSQL)
5073*!* llRetVal = llRetVal and v_sqlexec(lcUpdateSql)
5074*!* llRetVal = llRetVal and v_sqlexec(lcInsertSql)
5075*!* llRetVal = llRetVal and v_sqlexec(lcDtlInsertSql)
5076
5077 llRetVal = llRetVal and v_sqlexec(lcUpdateSql)
5078 llRetVal = llRetVal and v_sqlexec(lcUpdateDtlSql)
5079 llRetVal = llRetVal and .InsertExtraRecordFromSO(lcFilter, lcipcOrder_New, lcipcth_New, lcipctd_New)
5080 *=== TR 1048865 13-Apr-2011 Goutam
5081
5082 IF llRetVal
5083 THIS.EndTransaction()
5084 ELSE
5085 THIS.RollbackTransaction()
5086 ENDIF
5087 ENDIF
5088 ENDIF
5089
5090 ENDIF
5091
5092 *--- TechRec 1073669 04-Nov-2013 GSternik ---
5093 *-- Per Yuri's request made the TR 1073669 Changes easily undoable
5094 *--==============================================
5095 #ELSE
5096 *--==============================================
5097
5098 lcFilter = Iif(Empty(this.cFilterCriteria),"",This.cFilterCriteria)
5099 *-- Not sure if this is needed:
5100 lcFilter = StrTran(lcFilter, "where", "", 1, 1, 1)
5101
5102
5103 *-- Let's replace 'NZ' with 'RZ' for the existing ones, and replace 'NZ' with 'AI' for the new ones
5104 lcSQL = ;
5105 "update d"+;
5106 " set d.Qualifier = case"+;
5107 " when h.Ord_Num > 0 then 'RZ'"+;
5108 " else 'AI'"+;
5109 " end"+;
5110 " from zzeipctd d"+;
5111 " join zzeipcth h"+;
5112 " on h.PKey = d.FKey"+;
5113 " where d.Qualifier = 'NZ'"+;
5114 " and h.Errs_Flg_H < 'Y' " +;
5115 Iif(Empty(lcFilter), "", "and " + lcFilter)
5116
5117
5118 Local lcTmpDtl, lcTmpHdr
5119 lcTmpDtl = SubStr(SYS(2015), 6)
5120 lcTmpHdr = Iif(Version(2)=2,"##","#") + "DI_HDR_" + lcTmpDtl
5121 lcTmpDtl = Iif(Version(2)=2,"##","#") + "DI_DTL_" + lcTmpDtl
5122
5123 *-- Let's find the missing UPC/SKUs:
5124 &&--- TechRec 1073591 16-Feb-2014 TShenbagavalli added noshow existing issue fixed ===
5125 Text to lcDtlSql Flags 1 noshow
5126; with m as (
5127select b.Size_Num as SizeBucket
5128 , Size01_Qty*Sz01+Size02_Qty*Sz02+Size03_Qty*Sz03+Size04_Qty*Sz04
5129 +Size05_Qty*Sz05+Size06_Qty*Sz06+Size07_Qty*Sz07+Size08_Qty*Sz08
5130 +Size09_Qty*Sz09+Size10_Qty*Sz10+Size11_Qty*Sz11+Size12_Qty*Sz12
5131 +Size13_Qty*Sz13+Size14_Qty*Sz14+Size15_Qty*Sz15+Size16_Qty*Sz16
5132 +Size17_Qty*Sz17+Size18_Qty*Sz18+Size19_Qty*Sz19+Size20_Qty*Sz20
5133 +Size21_Qty*Sz21+Size22_Qty*Sz22+Size23_Qty*Sz23+Size24_Qty*Sz24 as Qty_Change
5134 , od.*
5135 from zzoordrh oh
5136 join zzoordrd od
5137 on od.FKey = oh.PKey
5138 join zzxBuckt b
5139 on Size01_Qty*Sz01+Size02_Qty*Sz02+Size03_Qty*Sz03+Size04_Qty*Sz04
5140 +Size05_Qty*Sz05+Size06_Qty*Sz06+Size07_Qty*Sz07+Size08_Qty*Sz08
5141 +Size09_Qty*Sz09+Size10_Qty*Sz10+Size11_Qty*Sz11+Size12_Qty*Sz12
5142 +Size13_Qty*Sz13+Size14_Qty*Sz14+Size15_Qty*Sz15+Size16_Qty*Sz16
5143 +Size17_Qty*Sz17+Size18_Qty*Sz18+Size19_Qty*Sz19+Size20_Qty*Sz20
5144 +Size21_Qty*Sz21+Size22_Qty*Sz22+Size23_Qty*Sz23+Size24_Qty*Sz24 > 0
5145 where od.Line_Status = 'O'
5146 and exists (
5147select NULL
5148 from zzeipcth h
5149 join zzeipctd d
5150 on d.FKey = h.PKey
5151 where h.Customer = oh.Customer
5152 and h.PO_Num = oh.PO_Num
5153 and d.Qualifier = 'NZ'
5154 --- No Store included in this lookup
5155 and d.Division = od.Division
5156 and d.Style = od.Style
5157 and d.Color_Code = od.Color_Code
5158 and d.Lbl_Code = od.Lbl_Code
5159 and d.Dimension = od.Dimension
5160 and d.SizeBucket = b.Size_Num
5161 --- Filter
5162 )
5163 and not exists (
5164 select NULL
5165 from zzeipcth h
5166 join zzeipctd d
5167 on d.FKey = h.PKey
5168 where h.Customer = oh.Customer
5169 and h.PO_Num = oh.PO_Num
5170 and h.Store = oh.Store -- here is the difference
5171 and d.Qualifier = 'NZ'
5172 and d.Division = od.Division
5173 and d.Style = od.Style
5174 and d.Color_Code = od.Color_Code
5175 and d.Lbl_Code = od.Lbl_Code
5176 and d.Dimension = od.Dimension
5177 and d.SizeBucket = b.Size_Num
5178 --- Filter
5179 )
5180)
5181select UPC, u.Size_Desc, 'DI' AS Qualifier, m.*
5182 ---- into
5183 from m
5184 left join zveupcnr u
5185 on u.Division = m.Division
5186 and u.Style = m.Style
5187 and u.Color_Code = m.Color_Code
5188 and u.Lbl_Code = m.Lbl_Code
5189 and u.Dimension = m.Dimension
5190 and u.SizeBucket = m.SizeBucket
5191;
5192select @@RowCount as Cnt
5193EndText
5194
5195 lcDtlSql = StrTran(lcDtlSql, "---- into", "into " + lcTmpDtl)
5196
5197 If !Empty(lcFilter)
5198 lcDtlSql = StrTran(lcDtlSql, "--- Filter", "and " + lcFilter)
5199 EndIf
5200
5201 *--- TechRec 1075895 17-Mar-2014 vkrishnamurthy ---
5202 lcFieldList = this.oApplyPoChange.GetSOFieldListWithoutUDF("oh.", "zzoordrh")
5203 *=== TechRec 1075895 17-Mar-2014 vkrishnamurthy ===
5204
5205 *-- Let's find the missing Headers for the found UPC/SKUs:
5206 &&--- TechRec 1075895 17-Mar-2014 vkrishnamurthy === added lcFieldList
5207 lcHdrSql =;
5208 "select "+ lcFieldList +", EDI_Store "+;
5209 " into " + lcTmpHdr +;
5210 " from zzoordrh oh"+;
5211 " join zzxStorR s" +;
5212 " on s.Customer = oh.Customer" +;
5213 " and s.Store = oh.Store" +;
5214 " where exists ( "+;
5215 "select NULL"+;
5216 " from " + lcTmpDtl + " d"+;
5217 " where d.FKey = oh.PKey)"+;
5218 " and not exists ( "+;
5219 "select NULL"+;
5220 " from zzeipcth h"+;
5221 " where h.Customer = oh.Customer"+;
5222 " and h.PO_Num = oh.PO_Num"+;
5223 " and h.Ord_num = oh.Ord_num)" +;
5224 "; select @@RowCount as Cnt"
5225
5226 Local lnDtlDICount, lnHdrDICount
5227 This.oLog.LogEntry("Looking for SKU/Buckets existing in both 860 and Open Orders(OO) for the Stores in OO but not in 860.")
5228 llRetVal = llRetVal and v_SqlExec(lcDtlSql, "RowCount")
5229 If llRetVal
5230 lnDtlDICount = RowCount.Cnt
5231 If lnDtlDICount > 0
5232 This.oLog.LogEntry("Found " + Transform(lnDtlDICount) + " open orders SKU/Buckets to delete.")
5233 Else
5234 This.oLog.LogEntry("Not found any open orders SKU/Buckets to delete.")
5235 EndIf
5236 Else
5237 lnDtlDICount = 0
5238 EndIf
5239
5240 lnHdrDICount = 0
5241 If lnDtlDICount > 0
5242 llRetVal = llRetVal and v_SqlExec(lcHdrSql, "RowCount")
5243 If llRetVal
5244 lnHdrDICount = RowCount.Cnt
5245 This.oLog.LogEntry("Found " + Transform(RowCount.Cnt) + " open order headers to delete.")
5246 EndIf
5247 EndIf
5248
5249 If llRetVal and lnDtlDICount > 0
5250 WITH this
5251
5252 *------ Let's Use the SQL String Builder ------*
5253 If lnHdrDICount > 0
5254 .oGenStr.SB_Reset()
5255
5256 .oGenStr.cSB_Target = "ZZEIPCTH"
5257 .oGenStr.cSB_Source = lcTmpHdr
5258 .oGenStr.cSB_SourceAlias = "th"
5259
5260 llRetVal = .oGenStr.SB_GenerateSQLInsertString()
5261
5262 If llRetVal
5263 lcInsertSql = .oGenStr.cSQLString
5264 Else
5265 lcMessage = "Failed to generate SQL string for 860(i) header NZ Qualifier. Cannot continue."
5266 .oLog.LogEntry(lcMessage)
5267 EndIf
5268 EndIf
5269
5270 If llRetVal
5271 .oGenStr.SB_Reset()
5272
5273 .oGenStr.cSB_Target = "ZZEIPCTD"
5274 .oGenStr.cSB_Source = lcTmpDtl
5275 .oGenStr.cSB_SourceAlias = "td"
5276
5277 *-- Maybe Ord_Num would be enough here?
5278 *-- the LEFT join to ZZEIPCTH is used to ensure that the BC_KeySet (new PKeys) is
5279 *-- properly generated for the details (ZZEIPCTD) BEFORE the new headers inserted (if any)!
5280 .oGenStr.cSB_FROMExpandedString = ;
5281 " join zzoordrd d on d.PKey = td.PKey" +;
5282 " join zzoordrh h on h.PKey = td.FKey" +;
5283 " LEFT join zzeipcth th on th.Ord_Num = h.Ord_Num and th.PO_Num = h.PO_Num and th.Store = h.Store"
5284
5285 .oGenStr.SB_SetLiteralFieldValue("fkey","th.PKey")
5286
5287 llRetVal = .oGenStr.SB_GenerateSQLInsertString()
5288
5289 If llRetVal
5290 lcDtlInsertSql = .oGenStr.cSQLString
5291 Else
5292 lcMessage = "Failed to generate SQL string for 860(i) detail NZ Qualifier. Cannot continue."
5293 .oLog.LogEntry(lcMessage)
5294 EndIf
5295 EndIf && llRetVal
5296 EndWith
5297
5298
5299 If llRetVal
5300 If TxnLevel() > 0
5301 llBeganTransaction = .F.
5302 Else
5303 llBeganTransaction = This.BeginTransaction()
5304 If !llBeganTransaction
5305 llRetVal = .F.
5306 EndIf
5307 EndIf
5308 EndIf
5309
5310 If llRetVal
5311 *-- replace 'NZ' with 'RZ' or 'AI'
5312 llRetVal = v_SqlExec(lcSQL)
5313 If lnHdrDICount > 0
5314 *-- Insert the headers to delete
5315 llRetVal = llRetVal and v_SqlExec(lcInsertSql )
5316 EndIf
5317 *-- Insert the Details to delete ('DI')
5318 llRetVal = llRetVal and v_SqlExec(lcDtlInsertSql)
5319 EndIf && llRetVal: Trx Started
5320
5321 If llBeganTransaction
5322 If llRetVal
5323 This.EndTransaction()
5324 ELSE
5325 This.RollbackTransaction()
5326 EndIf
5327 EndIf
5328
5329 EndIf && Found detal(s) for DI (lnDtlDICount > 0)
5330
5331 Use in Select("RowCount")
5332
5333 *-- Per Yuri's request made the TR 1073669 Changes easily undoable
5334 *--==============================================
5335 #ENDIF
5336 *--==============================================
5337 *=== TechRec 1073669 04-Nov-2013 GSternik ===
5338
5339
5340 IF llRetVal
5341 *-- GS what is this for?:
5342 REQUERY('Vzzeipcth_ipcproc')
5343 SELECT ('Vzzeipcth_ipcproc')
5344 SCAN
5345 SCATTER NAME loEiPCth MEMO
5346 SELECT tceipcTH
5347 IF SEEK(loEiPCth.pkey,'tceipcTH','PKEY')
5348 GATHER NAME loEiPCth MEMO
5349 ELSE
5350 APPEND BLANK
5351 GATHER NAME loEiPCth MEMO
5352 ENDIF
5353 ENDSCAN
5354
5355 REQUERY('Vzzeipctd_ipcproc')
5356 SELECT Vzzeipctd_ipcproc
5357 SCAN
5358 SCATTER NAME loEiPCtd MEMO
5359 SELECT tceipcTD
5360 IF SEEK(loEiPCtd.pkey,'tceipcTD','PKEY')
5361 GATHER NAME loEiPCtd MEMO
5362 ELSE
5363 APPEND BLANK
5364 GATHER NAME loEiPCtd MEMO
5365 ENDIF
5366
5367 ENDSCAN
5368 ENDIF
5369
5370 #IFDEF GS_1073669
5371 .dropTempTable(lcTmpDtl, .T.)
5372 .dropTempTable(lcTmpHdr, .T.)
5373 #ELSE
5374 .dropTempTable(lcipcth_New, true)
5375 .dropTempTable(lcipctd_New, true)
5376 .dropTempTable(lcipcPkey_New, true)
5377 .dropTempTable(lcipcMain_New, true)
5378 .dropTempTable(lcipcOrder_New, true)
5379
5380 *--- TR 1048865 03-May-2011 Goutam
5381 .dropTempTable(lcipcOrder_Exists, true)
5382 *--- TR 1048865 03-May-2011 Goutam
5383
5384 .tableclose("__tmpDPkeyUpdate")
5385 .tableclose("__tmpHPkeyUpdate")
5386 .tableclose("__TotalOrderCursor")
5387 #ENDIF
5388
5389 SELECT(lnOldSelect)
5390 RETURN llRetVal
5391 ENDPROC
5392 *=== TR 1039757 18-Aug-2009 Goutam.
5393
5394* --- TR 1047609 7/7/10 CM
5395************************************************************************************
5396* Resolve BC SKU from SLN records and create customer style data.
5397************************************************************************************
5398 Procedure ResolveBCSkuFromSLN
5399 &&--- TechRec 1073591 27-Oct-2013 TShenbagavalli added pceipcTWHSE ===
5400 Lparameters pceipcTH, pceipcTD, pceipcTS, pceipcCR, pceipcTWHSE
5401
5402 Local llRetVal, lnOldSelect, lcDivision, lcStyle, lcColor_Code, ;
5403 lcLbl_Code, lcDimension, loEiPCTS, lcErrs_Msg, lcOldCust, lcOldUPC
5404
5405 lnOldSelect = Select()
5406
5407 lcErrs_Msg = ""
5408 lcDivision = ""
5409
5410 This.cSQLTempTable = ""
5411 If .GenerateSQLTempTable(pceipcTS) AND .PopulateSQLTempTable(pceipcTS) AND !Empty(.cSQLTempTable)
5412 This.cTmpSLNTable = .cSQLTempTable
5413 Endif
5414
5415 *-- #1 Resolve SLN SKUs
5416 *--- TR 1048865 27-Dec-2010 Goutam, Added h.cr_pkey
5417 select h.Customer;
5418 , s.FKey;
5419 , s.SLN_UPC as UPC;
5420 , s.SLN_SKU as SKU ;
5421 , h.department ;
5422 , h.store ;
5423 , s.PKey;
5424 , .F. as SLN_Error;
5425 , Empty(d.SizeBucket) as Unresolved;
5426 , s.Division;
5427 , s.Style;
5428 , s.Color_Code;
5429 , s.SizeBucket;
5430 , d.Pkey as dtlPkey;
5431 , 'N' as IsPPK;
5432 , SPACE(5) as ppk_code;
5433 , h.cr_pkey ;
5434 from (pceipcTH) h;
5435 join (pceipcTD) d ;
5436 on d.FKey = h.PKey;
5437 join (pceipcTS) s ;
5438 on s.FKey = d.PKey ;
5439 where !Empty(h.Customer) ;
5440 order by 1, 2;
5441 into Cursor tmpCurs ReadWrite
5442
5443 Select tmpCurs
5444 If This.lUserInterface
5445 This.UpdateThermoCaption("Validating SLN UPC(s)...")
5446 This.InitThermo(RecCount())
5447 EndIf
5448
5449 lcOldCust = ""
5450 lcOldUPC = ""
5451 lcOldItem = ''
5452 Local lcSku_resolv, lcOldSku_resolv
5453 lcSku_resolv = ""
5454 *=
5455
5456 Scan for (Empty(Division) or Empty(Style) or Empty(Color_Code) or SizeBucket = 0)
5457 If This.lUserInterface
5458 * Advance progress bar, if we're using one.
5459 This.AdvanceThermo(RecNo())
5460 EndIf
5461 IF !EMPTY(tmpCurs.UPC)
5462
5463 If !(tmpCurs.Customer == lcOldCust And tmpCurs.UPC == lcOldUPC)
5464 lcErrs_Msg = ""
5465 lcOldCust = tmpCurs.Customer
5466 lcOldUPC = tmpCurs.UPC
5467
5468 If This.oBPOSalesOrder.ValidCustomerUPC(@lcErrs_Msg, lcOldCust, lcOldUPC, "tmpCstdr")
5469 lcDivision = tmpCstdr.division
5470 lcStyle = tmpCstdr.Style
5471 lcColor_Code = tmpCstdr.Color_Code
5472 lcLbl_Code = tmpCstdr.Lbl_Code
5473 lcDimension = tmpCstdr.Dimension
5474 lnSizeBucket = tmpCstdr.Size_Bk
5475 lnSize_Desc = tmpCstdr.Size_Desc
5476 Else
5477 lcErrs_Msg = ""
5478 If This.oBPOSalesOrder.ValidUPC(@lcErrs_Msg, tmpCurs.upc, "tmpUpcnr")
5479 lcDivision = tmpUpcnr.Division
5480 lcStyle = tmpUpcnr.Style
5481 lcColor_Code = tmpUpcnr.Color_Code
5482 lcLbl_Code = tmpUpcnr.Lbl_Code
5483 lcDimension = tmpUpcnr.Dimension
5484 lnSizeBucket = tmpUpcnr.SizeBucket
5485 lnSize_Desc = tmpUpcnr.Size_Desc
5486 Else
5487 lcErrs_Msg = lcErrs_Msg + CRLF
5488 Store "" To lcDivision, lcStyle, lcColor_code, lcLbl_code, lcDimension, lnSize_desc
5489 lnSizeBucket = 0
5490 Endif
5491 Endif
5492 Endif && level break
5493 *- Added resolution on SKU
5494 ENDIF && TmpCurs.UPC
5495 *- Resolve based on SKU if only SKU is sent or both UPC and SKU are sent,
5496 *- but UPC resolution failed.
5497 IF !EMPTY(tmpCurs.SKU) AND ( EMPTY(tmpCurs.UPC) OR EMPTY(lcStyle) )
5498
5499 If !(tmpCurs.customer == lcOldCust And tmpCurs.sku == lcOldItem )
5500 lcErrs_Msg = ""
5501 lcOldCust = tmpCurs.customer
5502 lcOldItem = tmpCurs.sku
5503 If This.oBPOSalesOrder.ValidCustomerSKU(@lcErrs_Msg, tmpCurs.customer, tmpCurs.sku, "tmpCstdr", ;
5504 lcSku_resolv, tmpCurs.department, tmpCurs.Store)
5505
5506 lcDivision = tmpCstdr.division
5507 lcStyle = tmpCstdr.Style
5508 lcColor_code = tmpCstdr.color_code
5509 lcLbl_code = tmpCstdr.lbl_code
5510 lcDimension = tmpCstdr.Dimension
5511 lnSizeBucket = tmpCstdr.size_bk
5512 lnSize_desc = tmpCstdr.size_desc
5513 Else
5514 lcErrs_Msg = lcErrs_Msg + CRLF
5515 Store "" To lcDivision, lcStyle, lcColor_code, lcLbl_code, lcDimension, lnSize_desc
5516 Store 0 To lnSizeBucket
5517 Endif
5518
5519 ENDIF
5520 ENDIF
5521
5522 Select (pceipcTS)
5523 =Seek(tmpCurs.PKey, pceipcTS, "PKey")
5524
5525 Scatter Name loEiPCTS Memo
5526 If !Empty(lcErrs_Msg)
5527 loEiPCTS.Errs_Msg_S = Alltrim(loEiPCTS.Errs_Msg_S) + lcErrs_Msg
5528 loEiPCTS.Errs_Flg_S = "Y"
5529 replace Sln_Error with .T. in tmpCurs
5530 Else
5531 replace Division with lcDivision in tmpCurs
5532 Endif
5533
5534 If !Empty(lcDivision) && update w/ style if found, no matter good or bad
5535 loEiPCTS.Division = lcDivision
5536 loEiPCTS.Style = lcStyle
5537 loEiPCTS.Color_Code = lcColor_code
5538 loEiPCTS.Lbl_Code = lcLbl_code
5539 loEiPCTS.Dimension = lcDimension
5540 loEiPCTS.SizeBucket = lnSizeBucket
5541 loEiPCTS.Size_Desc = lnSize_Desc
5542 Endif
5543
5544 Gather Name loEiPCTS Memo
5545
5546 ENDSCAN
5547
5548 SELECT tmpCurs
5549 SCAN FOR IsPPK = 'N'
5550 Select (pceipcTS)
5551 =Seek(tmpCurs.PKey, pceipcTS, "PKey")
5552 Scatter Name loEiPCTS Memo
5553
5554 IF NOT EMPTY(loEiPCTS.Dimension)
5555 lcppk_code = vl_ppakh(loEiPCTS.Division,'PPK_CODE',, vl_stylr(loEiPCTS.Division,'size_code',,loEiPCTS.Style), loEiPCTS.Dimension)
5556 IF !EMPTY(lcppk_code)
5557 replace IsPPK WITH 'Y', ppk_code WITH lcppk_code IN tmpCurs
5558 ENDIF
5559 ENDIF
5560
5561 *--- TechRec 1071427 03-Jun-2013 jjanand === Added AND loEiPCTS.Errs_Flg_S != 'Y'
5562 *- TR 1073826 FH - added USED('__tmpDimCurs')
5563 *IF tmpCurs.IsPPK = 'N' AND loEiPCTS.Errs_Flg_S != 'Y' AND vl_scolr(loEiPCTS.Division,,'__tmpDimCurs' ,loEiPCTS.Style, loEiPCTS.Color_Code, loEiPCTS.Lbl_Code) AND USED('__tmpDimCurs')
5564 IF tmpCurs.IsPPK = 'N' AND vl_scolr(loEiPCTS.Division,,'__tmpDimCurs' ,loEiPCTS.Style, loEiPCTS.Color_Code, loEiPCTS.Lbl_Code) AND USED("__tmpDimCurs") && *--- TR 1080606/1078492 16-8-2014 VKK
5565
5566 SELECT __tmpDimCurs
5567 LOCATE FOR ppack_ok = 'Y' AND !EMPTY(dimension)
5568 lcppk_code = dimension
5569 USE IN SELECT('__tmpDimCurs')
5570 IF !EMPTY(lcppk_code) AND vl_ppakd(loEiPCTS.Division,,'__tmpDimCurs', vl_stylr(loEiPCTS.Division,'size_code',,loEiPCTS.Style), lcppk_code, loEiPCTS.Color_Code, loEiPCTS.Lbl_Code,loEiPCTS.dimension)
5571 SELECT __tmpDimCurs
5572 IF RECCOUNT('__tmpDimCurs') = 1 AND loEiPCTS.SizeBucket > 0 AND EVALUATE("pack" + PADL(loEiPCTS.SizeBucket, 2, '0') + "_qty") > 0
5573 replace IsPPK WITH 'Y', ppk_code WITH lcppk_code IN tmpCurs
5574 ENDIF
5575 USE IN SELECT('__tmpDimCurs')
5576 ENDIF
5577 ENDIF
5578 ENDSCAN
5579
5580 UPDATE td SET Style_SLN_OK = 'N' ;
5581 FROM (pceipcTD) td INNER JOIN (pceipcTS) ts on td.pkey = ts.fkey ;
5582 WHERE ts.errs_flg_s ='Y'
5583
5584 llRetVal = This.CreateCursorSLNToDtl(pceipcTD, pceipcCR, "tmpCurs")
5585 &&--- TechRec 1073591 27-Oct-2013 TShenbagavalli added pceipcTWHSE ===
5586 llRetVal = llRetVal AND This.MoveSLNToDTLs(pceipcTH, pceipcTD, pceipcTS, pceipcCR, pceipcTWHSE )
5587 llRetVal = llRetVal AND This.ResolvePPKSkuAndUpdateDetail(pceipcTH, pceipcTD, pceipcTS, pceipcCR, "tmpCurs")
5588 llRetVal = llRetVal AND This.ResolveSingleSLNDetail(pceipcTH, pceipcTD, pceipcTS, pceipcCR, "tmpCurs")
5589 llRetVal = llRetVal AND This.CreateSingleSLNCursor("tmpCurs")
5590 &&--- TechRec 1073591 27-Oct-2013 TShenbagavalli added pceipcTWHSE ===
5591 llRetVal = llRetVal AND This.MoveSLNToDTLs(pceipcTH, pceipcTD, pceipcTS, pceipcCR, pceipcTWHSE )
5592
5593 This.TableClose("tmpCurs")
5594
5595 ENDPROC
5596
5597 *--- This is the splited function from MoveSLNToDTLs
5598 PROCEDURE CreateCursorSLNToDtl
5599 LPARAMETERS pceipcTD, pceipcCR, pcTmpCursor
5600
5601 LOCAL llRetVal, lnOldSelect
5602 lnOldSelect = SELECT()
5603 llRetVal = true
5604
5605 *--- TR 1048865 27-Dec-2010 Goutam. Changed the join of (pcTmpCursor) and zzeipccr from division and customer to pkey = cr_pkey
5606 select t.Customer ;
5607 , t.FKey ;
5608 , t.PKey ;
5609 from (pcTmpCursor) t ;
5610 join zzeipccr c ;
5611 on c.pkey = t.cr_pkey ;
5612 join (pceipcTD) d ;
5613 on d.pkey = t.dtlPkey ;
5614 where c.slntodtl = 'Y' ;
5615 and d.slntodtl <> 'Y' ;
5616 into Cursor __tmpipcts ;
5617 order by t.fkey, t.Customer, t.PKey
5618
5619 SELECT(lnOldSelect)
5620 RETURN llRetVal
5621
5622 ENDPROC
5623
5624 PROCEDURE MoveSLNToDTLs
5625 &&--- TechRec 1073591 27-Oct-2013 TShenbagavalli added pceipcTWHSE ===
5626 LPARAMETERS pceipcTH, pceipcTD, pceipcTS, pceipcCR, pceipcTWHSE
5627
5628 Local llRetVal, lnOldSelect, lnPSFkey, lnSkipedPSFkey, lnStartPkey, lnDetailPrice, ;
5629 lnLine_Seq
5630
5631 LOCAL lcSQL ,loIPCtdn
5632
5633 LOCAL lnTotSLNQty
5634
5635 llRetVal = true
5636 lnOldSelect = Select()
5637 lnDetailPrice = 0
5638
5639 *-- #1 Create detail record from pceipcTS
5640 SELECT __tmpipcts
5641 lnStartPkey = v_nextPkey("ZZEIPCTD", RECCOUNT("__tmpipcts")) - RECCOUNT("__tmpipcts")
5642 GO top
5643 lnSkipedPSFkey = 0
5644 lnPSFkey = 0
5645 lnLine_Seq = 0
5646 lnTotSLNQty = 0
5647
5648 IF SEEK(__tmpipcts.Fkey, pceipcTD, "PKey") AND Seek(__tmpipcts.PKey, pceipcTS, "PKey")
5649 lnDetailPrice = .getPriceFromIPCts(pceipcTS, &pceipcTD..Org_Price)
5650 ENDIF
5651 DO WHILE NOT EOF()
5652 lnPSFkey = Fkey
5653 IF lnPSFkey <> lnSkipedPSFkey
5654 lnTotSLNQty = This.GetTotSLNQty(lnPSFkey, pceipcTS)
5655 ENDIF
5656 lnStartPkey = lnStartPkey + 1
5657 IF SEEK(lnPSFkey, pceipcTD, "PKey") AND Seek(__tmpipcts.PKey, pceipcTS, "PKey")
5658 lnLine_Seq = lnLine_Seq + 1
5659 SELECT (pceipcTD)
5660 SCATTER NAME loIPCtd MEMO
5661 loIPCtd.pkey = lnStartPkey
5662 loIPCtd.Line_Seq = lnLine_Seq
5663
5664 *--- TechRec 1073591 27-Oct-2013 TShenbagavalli ---
5665 IF SEEK(STR(loIPCtd.doc_num)+loIPCtd.po1_line, pceipcTWHSE, "SLN_Line")
5666 SELECT (pceipcTWHSE)
5667 lnDocNum = doc_num
5668 lnEdiLine = edi_line
5669 lnSlnLine = sln_line
5670
5671 REPLACE line_seq WITH loIPCtd.line_seq, sizebucket WITH &pceipcTS..sizebucket, ;
5672 dfkey WITH loIPCtd.pkey, sfkey WITH &pceipcTS..pkey IN (pceipcTWHSE) ;
5673 FOR doc_num = lnDocNum AND edi_line = lnEdiLine AND sln_line = lnSlnLine
5674
5675 SELECT (pceipcTD)
5676 ENDIF
5677 *=== TechRec 1073591 27-Oct-2013 TShenbagavalli ===
5678
5679 loIPCtd.slntodtl = 'Y'
5680 IF EMPTY(loIPCtd.Assortment) AND EMPTY(loIPCtd.assort_qty)
5681 loIPCtd.Assortment = ALLTRIM(loIPCtd.UPC) +"@"+ ALLTRIM(loIPCtd.SKU) +"@"+ ALLTRIM(loIPCtd.po1_line)
5682 loIPCtd.assort_qty = loIPCtd.qty_change
5683 ENDIF
5684 loIPCtd.PO1_UPC = loIPCtd.UPC
5685 loIPCtd.PO1_SKU = loIPCtd.SKU
5686 loIPCtd.Qualifier = loIPCtd.Qualifier
5687 loIPCtd.po1_price = loIPCtd.org_price
5688 loIPCtd.Division = &pceipcTS..Division
5689 loIPCtd.Style = &pceipcTS..Style
5690 loIPCtd.Color_code = &pceipcTS..Color_code
5691 loIPCtd.Lbl_Code = &pceipcTS..Lbl_Code
5692 loIPCtd.Dimension = &pceipcTS..Dimension
5693 loIPCtd.SizeBucket = &pceipcTS..SizeBucket
5694 loIPCtd.Size_Desc = &pceipcTS..Size_Desc
5695 loIPCtd.UPC = &pceipcTS..SLN_UPC
5696 loIPCtd.SKU = &pceipcTS..SLN_SKU
5697
5698 DO CASE
5699 CASE loIPCtd.ppk_action = 'B'
5700
5701 loIPCtd.qty_change = &pceipcTS..SLN_Qty * loIPCtd.qty_change
5702 loIPCtd.ppk_action = 'X'
5703 lnDetailPrice = loIPCtd.Org_Price/ lnTotSLNQty
5704 loIPCtd.poc_price = loIPCtd.poc_price / lnTotSLNQty
5705 loIPCtd.poc_retail2 = loIPCtd.poc_retail2 / lnTotSLNQty &&--- TechRec 1054692 21-Sep-2011 jisingh ===
5706 loIPCtd.ppk_qty = loIPCtd.qty_change
5707
5708 CASE loIPCtd.ppk_action = 'Q'
5709
5710 loIPCtd.qty_change = &pceipcTS..SLN_Qty * loIPCtd.qty_change
5711
5712 IF loIPCtd.ppk_action = 'Q'
5713 loIPCtd.ppk_action = 'M'
5714 ENDIF
5715
5716 loIPCtd.ppk_qty = loIPCtd.qty_change
5717 lnDetailPrice = &pceipcTD..Org_Price
5718
5719 CASE loIPCtd.ppk_action = 'P'
5720 loIPCtd.qty_change = (loIPCtd.qty_change/lnTotSLNQty) * &pceipcTS..SLN_Qty
5721 loIPCtd.ppk_action = 'D'
5722 lnDetailPrice = loIPCtd. Org_Price/ lnTotSLNQty
5723
5724 *--- TR 1050827 25-NOV-2010 HNISAR
5725 * Retail Field is not available. Here Retail1 is POC_price
5726*!* loIPCtd.Retail1 = loIPCtd.retail1 / lnTotSLNQty
5727 loIPCtd.poc_price = loIPCtd.poc_price / lnTotSLNQty
5728 loIPCtd.poc_retail2 = loIPCtd.poc_retail2 / lnTotSLNQty &&--- TechRec 1054692 21-Sep-2011 jisingh ===
5729 *=== TR 1050827 25-NOV-2010 HNISAR
5730
5731 OTHERWISE
5732 loIPCtd.qty_change = (loIPCtd.qty_change/lnTotSLNQty) * &pceipcTS..SLN_Qty
5733 lnDetailPrice = &pceipcTD..Org_Price
5734 loIPCtd.ppk_qty = lnTotSLNQty
5735 ENDCASE
5736
5737 loIPCtd.org_Price = IIF(&pceipcTS..Poc_Cost=0, lnDetailPrice, NVL(&pceipcTS..Poc_Cost,0))
5738 loIPCtd.poc_cost = loIPCtd.org_Price
5739 loIPCtd.Line_id = IIF(!EMPTY(loIPCtd.Assortment), loIPCtd.Assortment, &pceipcTS..Line_id)
5740
5741 loIPCtd.Errs_flg_d = "N"
5742 loIPCtd.Errs_msg_d = ""
5743
5744 APPEND BLANK
5745 GATHER NAME loIPCtd MEMO
5746
5747
5748 * Deleting SLNs now because we just created DTLs from
5749 * SLNs so, SLNs are no longer needed.
5750 Select (pceipcTS)
5751 If Seek(__tmpipcts.PKey, pceipcTS, "PKey")
5752 Delete In (pceipcTS)
5753 Endif
5754
5755 ENDIF
5756
5757
5758 *--- TR 1050827 30-NOV-2010 HNISAR
5759*!* SELECT __tmpipcts
5760*!* SKIP IN __tmpipcts
5761*!* lnSkipedPSFkey = Fkey
5762*!* IF (lnPSFkey <> lnSkipedPSFkey) AND SEEK(lnPSFkey, pceipcTD, "PKey")
5763*!*
5764 SELECT __tmpipcts
5765 lnSkipedPSFkey = Fkey
5766 SKIP IN __tmpipcts
5767
5768 IF (lnPSFkey <> __tmpipcts.Fkey) AND SEEK(lnPSFkey, pceipcTD, "PKey")
5769 *=== TR 1050827 30-NOV-2010 HNISAR
5770 DELETE IN (pceipcTD)
5771
5772 IF SEEK(__tmpipcts.Fkey, pceipcTD, "PKey") AND Seek(__tmpipcts.PKey, pceipcTS, "PKey")
5773 lnDetailPrice = .getPriceFromIPCts(pceipcTS, &pceipcTD..Org_Price)
5774 ENDIF
5775 lnLine_Seq = 0
5776 ENDIF
5777 ENDDO
5778
5779 * Delete SLNs from the server since we've already created
5780 * details from our SLNs.
5781 This.cSQLTempTable = ""
5782 If .GenerateSQLTempTable(pceipcTD) AND .PopulateSQLTempTable(pceipcTD) AND !Empty(This.cSQLTempTable)
5783 lcSQL = "DELETE s " + ;
5784 "FROM zzeipcts s " + ;
5785 "WHERE NOT EXISTS (" + ;
5786 "SELECT * FROM " + This.cSQLTempTable + " t " + ;
5787 "WHERE s.fkey = t.pkey) "
5788
5789 llRetVal = llRetVal And v_SQLExec(lcSQL)
5790 ENDIF
5791
5792 USE IN __tmpipcts
5793
5794 SELECT (lnOldSelect)
5795 RETURN llRetVal
5796 ENDPROC
5797
5798 *---- get total sln qty for a detail line
5799 FUNCTION getPriceFromIPCts
5800 LPARAMETERS pceipcTS, pnPrice
5801 LOCAL lnOldSelect, lnSLNQty, lnSLNTotalQty, lnUnitPrice, lnFkey
5802 lnUnitPrice = 0
5803 IF pnPrice > 0
5804 lnOldSelect = SELECT()
5805
5806 SELECT (pceipcTS)
5807 lnFkey = Fkey
5808 lnSLNQty = SLN_Qty
5809 .PushRecordSet()
5810 SUM SLN_Qty FOR fkey = lnFkey TO lnSLNTotalQty
5811 lnUnitPrice = pnPrice/lnSLNTotalQty
5812 .PopRecordSet()
5813
5814 SELECT (lnOldSelect)
5815 ENDIF
5816
5817 RETURN lnUnitPrice
5818 ENDFUNC
5819
5820 PROCEDURE ResolvePPKSkuAndUpdateDetail
5821 LPARAMETERS pceipcTH, pceipcTD, pceipcTS, pceipcCR, tmpCurs
5822
5823 LOCAL llRetVal, lnOldSelect, lcSql, i, lnPackTotal, lnQtyChange,;
5824 lcDivision, lcStyle, lcColor_Code, lcLbl_Code, lcDimension, loEiPCTS,;
5825 lcOldCust, lcOldUPC, lcOldSKU, lnFKey, llDeleteSLN, lcOldOrder, llImplodeOK, llProcess
5826
5827 llRetVal = .T.
5828 lnOldSelect = SELECT()
5829
5830 *-- Remove SLN Records which should not be used for Detail Prepack resolution:
5831 SELECT tmpCurs
5832 lnFKey = 0
5833
5834 DIMENSION laBuckets(goEnv.MaxBuckets)
5835
5836 *-- Remove SLNs where exists error for the same FKey, or Resolve PPK from SLN not required:
5837 SCAN
5838 IF FKey # lnFKey
5839 lnFKey = FKey
5840
5841 IF SLN_Error or !Unresolved
5842 llDeleteSLN = .T.
5843 ELSE
5844
5845 *--- TR 1048865 27-Dec-2010 Goutam
5846 *llDeleteSLN = !Seek(Division+Customer, pceipcCR, "DivCust")
5847 llDeleteSLN = !Seek(cr_pkey, pceipcCR, "pkey")
5848 *=== TR 1048865 27-Dec-2010 Goutam
5849
5850 IF !llDeleteSLN
5851 SELECT (pceipcCR)
5852 llDeleteSLN = ((StyleFromSLN < "Y") and (StyleFromSLN <> "O"))
5853
5854 Select tmpCurs
5855 EndIf
5856 EndIf
5857
5858 If !llDeleteSLN
5859 lnRecNo = RecNo()
5860
5861 Scan while FKey = lnFKey
5862 If SLN_Error
5863 *-- One SLN with error exists.
5864 llDeleteSLN = .T.
5865 Exit
5866 EndIf
5867 EndScan
5868
5869 Go lnRecNo
5870 EndIf
5871 EndIf
5872
5873 If llDeleteSLN
5874 Delete
5875 EndIf
5876 EndScan
5877
5878
5879 *-- #3 -- Updating Details with PPK BC SKU:
5880 lcOldCust = ""
5881 lcOldSKU = ""
5882 lnFKey = 0
5883 lnRecNo = This.CountTotalRecs('tmpCurs')
5884
5885 If lnRecNo > 0
5886 *-- Need for optimization:
5887
5888 If This.lUserInterface
5889 This.UpdateThermoCaption("Resolving Style From SLN...")
5890 This.InitThermo(lnRecNo + 1)
5891 lnRecNo = 1
5892 Endif
5893 v_SQLExec("create table #ImplodeSLN " + ;
5894 "( Color_Code Char(50), Lbl_Code Char(7), Dimension Char(5), SizeBucket Int, " + ; && TR 1065971 02/04/13 JIJO - Increased style/color_code field width to 50 (Automated)
5895 " Size_Desc Char(10), Qty Int, PKey Int)")
5896
5897 Select (pceipcTD)
5898 lcOldOrder = Order()
5899
5900 Index on Customer+SKU+UPC tag CustSKU
5901 lcOldUPC = ''
5902 *==
5903
5904 If This.lUserInterface
5905 This.AdvanceThermo(lnRecNo)
5906 EndIf
5907
5908 Select tmpCurs
5909 Locate
5910
5911 Do while .T. && Scan replacement
5912 if FKey # lnFKey
5913 If llProcess
5914 If llImplodeOK
5915
5916 *- This is a modified SQL from Perform_Implosion()
5917 *- Added LEFT JOIN #ImplodeSLN and
5918 *- the last 'not exist' to check for exact match (by ratio) between #ImplodeSLN and prepacks.
5919 = v_SqlExec(;
5920 "select c.Dimension as PPk, c.Color_Code as PPK_Color, c.Lbl_Code as PPK_Lbl, Size_Num,"+;
5921 " Sz01*Pack01_Qty+Sz02*Pack02_Qty+Sz03*Pack03_Qty+"+;
5922 " Sz04*Pack04_Qty+Sz05*Pack05_Qty+Sz06*Pack06_Qty+Sz07*Pack07_Qty+"+;
5923 " Sz08*Pack08_Qty+Sz09*Pack09_Qty+Sz10*Pack10_Qty+Sz11*Pack11_Qty+"+;
5924 " Sz12*Pack12_Qty+Sz13*Pack13_Qty+Sz14*Pack14_Qty+Sz15*Pack15_Qty+"+;
5925 " Sz16*Pack16_Qty+Sz17*Pack17_Qty+Sz18*Pack18_Qty+Sz19*Pack19_Qty+"+;
5926 " Sz20*Pack20_Qty+Sz21*Pack21_Qty+Sz22*Pack22_Qty+Sz23*Pack23_Qty+"+;
5927 " Sz24*Pack24_Qty as PPK_Bk_Qty"+;
5928 " , pd.Color_Code as PDtl_Color"+;
5929 " , pd.Lbl_Code as PDtl_Lbl"+;
5930 " , i.Color_Code"+;
5931 " , i.Lbl_Code"+;
5932 " , i.Dimension"+;
5933 " , z.Size01 " + ;
5934 " , i.PKey"+;
5935 " , i.Qty"+;
5936 " , ph.Pack_Qty"+;
5937 " from zzxScolr c"+;
5938 " join zzxstylr st"+;
5939 " on st.pkey = c.fkey" + ;
5940 " join zzxPPakH ph"+;
5941 " on ph.Division = c.Division"+;
5942 " and ph.Size_Code = st.Size_Code"+;
5943 " and ph.ppK_Code = c.Dimension"+;
5944 " and c.color_code = case " + ;
5945 " when ph.MulClLb_Ok = 'Y' and ph.ppk_color <> '' " + ;
5946 " then ph.ppk_color else c.color_code end " + ;
5947 " join zzxPPakD pd"+;
5948 " on pd.FKey = ph.PKey"+;
5949 " join zzxSizer z"+;
5950 " on z.Division = c.Division"+;
5951 " and z.Size_Code = st.Size_Code"+;
5952 " cross join zzxBuckt b"+;
5953 " LEFT join #ImplodeSLN i"+;
5954 " on i.Color_Code = case "+;
5955 " when pd.Color_Code = 'ALL' or pd.Color_Code = '' "+;
5956 " then c.Color_Code else pd.Color_Code end "+;
5957 " and i.Lbl_Code = case "+;
5958 " when ph.MulClLb_Ok < 'Y' or pd.Lbl_Code = 'ALL' "+;
5959 " then c.Lbl_Code else i.Lbl_Code end"+;
5960 " and i.Dimension = pd.Dimension"+;
5961 " and i.SizeBucket = b.Size_Num"+;
5962 " where c.Style = '" + ALLTR(lcStyle) + "'" + ;
5963 " and c.Division = '" + ALLTR(lcDivision) + "'" + ;
5964 " and c.PPack_OK = 'Y'"+;
5965 " and c.Active_OK = 'Y'"+;
5966 " and ph.Active_OK = 'Y'" + ;
5967 " and Sz01*Pack01_Qty+Sz02*Pack02_Qty+Sz03*Pack03_Qty+"+;
5968 " Sz04*Pack04_Qty+Sz05*Pack05_Qty+Sz06*Pack06_Qty+Sz07*Pack07_Qty+"+;
5969 " Sz08*Pack08_Qty+Sz09*Pack09_Qty+Sz10*Pack10_Qty+Sz11*Pack11_Qty+"+;
5970 " Sz12*Pack12_Qty+Sz13*Pack13_Qty+Sz14*Pack14_Qty+Sz15*Pack15_Qty+"+;
5971 " Sz16*Pack16_Qty+Sz17*Pack17_Qty+Sz18*Pack18_Qty+Sz19*Pack19_Qty+"+;
5972 " Sz20*Pack20_Qty+Sz21*Pack21_Qty+Sz22*Pack22_Qty+Sz23*Pack23_Qty+"+;
5973 " Sz24*Pack24_Qty > 0 "+;
5974 " and not Exists("+;
5975 " Select *"+;
5976 " from zzxPPakD p"+;
5977 " cross join zzxBuckt bk"+;
5978 " left join #ImplodeSLN ii"+;
5979 " on ii.Color_Code = case when p.Color_Code = 'ALL' or p.Color_Code = '' then c.Color_Code else p.Color_Code end "+;
5980 " and ii.Lbl_Code = case when ph.MulClLb_Ok < 'Y' or p.Lbl_Code = 'ALL' then c.Lbl_Code else ii.Lbl_Code end"+;
5981 " and ii.Dimension = p.Dimension"+;
5982 " and ii.SizeBucket = bk.Size_Num"+;
5983 " where p.Fkey = ph.Pkey"+;
5984 " and Sz01*Pack01_Qty+Sz02*Pack02_Qty+Sz03*Pack03_Qty+"+;
5985 " Sz04*Pack04_Qty+Sz05*Pack05_Qty+Sz06*Pack06_Qty+Sz07*Pack07_Qty+"+;
5986 " Sz08*Pack08_Qty+Sz09*Pack09_Qty+Sz10*Pack10_Qty+Sz11*Pack11_Qty+"+;
5987 " Sz12*Pack12_Qty+Sz13*Pack13_Qty+Sz14*Pack14_Qty+Sz15*Pack15_Qty+"+;
5988 " Sz16*Pack16_Qty+Sz17*Pack17_Qty+Sz18*Pack18_Qty+Sz19*Pack19_Qty+"+;
5989 " Sz20*Pack20_Qty+Sz21*Pack21_Qty+Sz22*Pack22_Qty+Sz23*Pack23_Qty+"+;
5990 " Sz24*Pack24_Qty > Coalesce(ii.Qty,0))"+;
5991 "and not exists( "+;
5992 "select * "+;
5993 " from #ImplodeSLN ii "+;
5994 " left join zzxPPakD p "+;
5995 " on ii.Color_Code = case "+;
5996 " when p.Color_Code = 'ALL' or p.Color_Code = '' then ii.Color_Code "+;
5997 " else p.Color_Code "+;
5998 " end "+;
5999 " and ii.Lbl_Code = case "+;
6000 " when ph.MulClLb_Ok < 'Y' or p.Lbl_Code = 'ALL' then ii.Lbl_Code "+;
6001 " else p.Lbl_Code "+;
6002 " end "+;
6003 " and ii.Dimension = p.Dimension "+;
6004 " and p.Fkey = ph.Pkey"+;
6005 " join zzxBuckt bk "+;
6006 " on ii.SizeBucket = bk.Size_Num "+;
6007 " where IsNull(ii.Qty % NullIf(" + ;
6008 " Sz01*Pack01_Qty+Sz02*Pack02_Qty+Sz03*Pack03_Qty+ Sz04*Pack04_Qty" + ;
6009 " +Sz05*Pack05_Qty+Sz06*Pack06_Qty+Sz07*Pack07_Qty+ Sz08*Pack08_Qty" + ;
6010 " +Sz09*Pack09_Qty+Sz10*Pack10_Qty+Sz11*Pack11_Qty+ Sz12*Pack12_Qty" + ;
6011 " +Sz13*Pack13_Qty+Sz14*Pack14_Qty+Sz15*Pack15_Qty+ Sz16*Pack16_Qty" + ;
6012 " +Sz17*Pack17_Qty+Sz18*Pack18_Qty+Sz19*Pack19_Qty+ Sz20*Pack20_Qty" + ;
6013 " +Sz21*Pack21_Qty+Sz22*Pack22_Qty+Sz23*Pack23_Qty+ Sz24*Pack24_Qty, 0), 1) > 0 ) "+;
6014 " order by 1, 2, i.PKey", "vPPacks")
6015
6016 v_SQLExec("TRUNCATE TABLE #ImplodeSLN")
6017
6018 If Seek(tmpCurs.PKey, pceipcTS, "PKey")
6019 Select (pceipcTS)
6020 *- insert into #implodeSLN
6021 v_SQLExec("insert into #ImplodeSLN values ('"+;
6022 Color_Code + "', '" + Lbl_Code + "', '" + Dimension + "', " +;
6023 TRANSFORM(SizeBucket, '99') + ", '" + Size_Desc + ;
6024 "', " + STR(SLN_Qty) + ", " + STR(tmpCurs.PKey) + ")")
6025 Endif
6026
6027 SELECT lcDivision as division, ;
6028 lcStyle as style, ;
6029 ppk_color as color_code, ;
6030 ppk_lbl as lbl_code, ;
6031 ppk as dimension, ;
6032 ppk_bk_qty as sizebucket, ;
6033 size01 ;
6034 FROM VPPacks group by 5,3,4 ;
6035 into cursor qppk
6036 ENDIF && llImplodeOK
6037
6038 SELECT (pceipcTD)
6039 =Seek(lnFKey, pceipcTD, "PKey") && lnFKey contains the Previous Dtl PKey
6040 lcOldCust = Customer
6041 lcOldSKU = SKU
6042
6043 *-- Update all records with the same CustSKU
6044 *- =Seek(lcOldCust+lcOldSKU) && First matching record
6045 lcOldUPC = UPC
6046 =Seek(lcOldCust+lcOldSKU+lcOldUPC)
6047 If llImplodeOK and RecCount("qPPK") = 1
6048 replace Division with qPPK.Division, ;
6049 Style with qPPK.Style, ;
6050 Color_Code with qPPK.Color_Code, ;
6051 Lbl_Code with qPPK.Lbl_Code, ;
6052 Dimension with qPPK.Dimension,;
6053 SizeBucket with 1;
6054 Size_Desc with qPPk.Size01;
6055 Style_SLN_OK with 'Y' ;
6056 while Customer + SKU + UPC = lcOldCust+lcOldSKU+lcOldUPC
6057 Else
6058
6059 IF Seek(Division+Customer, pceipcCR, "DivCust") AND (SysGetFieldValue(pceipcCR, StyleFromSLN) <> "O")
6060 replace Style_SLN_OK with 'N' ;
6061 while Customer + SKU + UPC = lcOldCust+lcOldSKU+lcOldUPC
6062 ENDIF
6063
6064 ENDIF
6065 Else
6066 If Seek(tmpCurs.PKey, pceipcTS, "PKey")
6067 Select (pceipcTS)
6068 *- insert into #implodeSLN
6069 v_SQLExec("insert into #ImplodeSLN values ('"+;
6070 Color_Code + "', '" + Lbl_Code + "', '" + Dimension + "', " +;
6071 TRANSFORM(SizeBucket, '99') + ", '" + Size_Desc + ;
6072 "', " + STR(SLN_Qty) + ", " + STR(tmpCurs.PKey) + ")")
6073
6074 EndIf
6075 EndIf && Process Detail
6076
6077 Select tmpCurs
6078 if Eof()
6079 Exit
6080 EndIf
6081
6082 lnFKey = FKey
6083 Select (pceipcTD)
6084 =Seek(lnFKey, pceipcTD, "PKey")
6085
6086 llProcess = (Style_SLN_OK = ' ') && Detail Was Not Updated yet.
6087
6088 llImplodeOK = llProcess
6089
6090 If llImplodeOK
6091 store 0 to laBuckets
6092 lnPackTotal = 0
6093
6094 *-- Get BC SKU from SLN cursor (not from tmpCurs, because it does not have this data)
6095 Select (pceipcTS)
6096 =Seek(tmpCurs.PKey, pceipcTS, "PKey")
6097
6098 lcDivision = Division
6099 lcStyle = Style
6100 lcColor_Code = Color_Code
6101 lcLbl_Code = Lbl_Code
6102 lcDimension = Dimension
6103 EndIf
6104
6105 Else && The same FKey
6106 If llImplodeOK and Seek(tmpCurs.PKey, pceipcTS, "PKey")
6107 Select (pceipcTS)
6108 if Division # lcDivision;
6109 or Style # lcStyle
6110 llImplodeOK = .F.
6111 ELSE
6112 *- insert into #implodeSLN
6113 v_SQLExec("insert into #ImplodeSLN values ('"+;
6114 Color_Code + "', '" + Lbl_Code + "', '" + Dimension + "', " +;
6115 TRANSFORM(SizeBucket, '99') + ", '" + Size_Desc + ;
6116 "', " + STR(SLN_Qty) + ", " + STR(tmpCurs.PKey) + ")")
6117 EndIf
6118 EndIf
6119 EndIf && FKey Changed
6120
6121 if llImplodeOK
6122 *-- (pceipcTS) is selected!
6123 laBuckets[SizeBucket] = Sln_Qty
6124 lnPackTotal = lnPackTotal + Sln_Qty
6125 EndIf
6126
6127 Select tmpCurs
6128 Skip
6129
6130 If This.lUserInterface
6131 lnRecNo = lnRecNo + 1
6132 This.AdvanceThermo(lnRecNo)
6133 Endif
6134 EndDo && Endscan
6135
6136 Select (pceipcTD)
6137 Set Order to (lcOldOrder)
6138
6139 v_SQLExec("DROP table #ImplodeSLN ")
6140
6141 EndIf && Have data to Implode
6142
6143 If This.lUserInterface
6144 * Reset Thermometer
6145 This.ResetThermo()
6146 Endif
6147
6148 Select(lnOldSelect)
6149 Return llRetVal
6150
6151 ENDPROC
6152
6153 Procedure CreateSingleSLNCursor
6154 Lparameters pcTmpCursor
6155
6156 Local llRetVal, lnOldSelect, lcSQLString
6157
6158 llRetVal = true
6159 lnOldSelect = Select()
6160
6161 *--- TR 1048865 27-Dec-2010 Goutam. Changed the join of (pcTmpCursor) and zzeipccr from division and customer to pkey = cr_pkey
6162 select t.Customer ;
6163 , t.FKey ;
6164 , t.PKey ;
6165 from (pcTmpCursor) t ;
6166 join zzeipccr c ;
6167 on c.pkey = t.cr_pkey ;
6168 where c.slntodtl = 'N' ;
6169 and (c.stylefromsln = 'O' ;
6170 and t.pkey in (select pkey from (pcTmpCursor) group by fkey having (count(pkey)=1) and not SLN_Error and UnResolved AND IsPPK = 'N')) ;
6171 into Cursor __tmpipcts ;
6172 order by t.fkey, t.Customer, t.PKey
6173
6174 Select(lnOldSelect)
6175 Return llRetVal
6176 Endproc
6177
6178 Procedure ResolveSingleSLNDetail
6179 Lparameters pceipcTH, pceipcTD, pceipcTS, pceipcCR, pcTmpCursor
6180
6181 Local llRetVal, lnOldSelect, lnQtyChange, lcSQLString, lnFKey, lcDivision, lcStyle, lcColor_Code, lcDimension, lcSize_Desc
6182
6183 llRetVal = true
6184 lnOldSelect = Select()
6185
6186 *--- TR 1048865 27-Dec-2010 Goutam. Changed the join of (pcTmpCursor) and zzeipccr from division and customer to pkey = cr_pkey
6187 select t.Customer ;
6188 , t.FKey ;
6189 , t.PKey ;
6190 , t.ppk_code ;
6191 from (pcTmpCursor) t ;
6192 join zzeipccr c ;
6193 on c.pkey = t.cr_pkey ;
6194 where c.slntodtl = 'N' ;
6195 AND ((c.stylefromsln in ('Y','O') ;
6196 and t.pkey in (select pkey from (pcTmpCursor) group by fkey having (count(pkey)=1) and not SLN_Error and UnResolved AND IsPPK = 'Y'))) ;
6197 into Cursor __tmpipcts ;
6198 order by t.fkey, t.Customer, t.PKey
6199
6200 SELECT __tmpipcts
6201 SCAN
6202 lnFKey = Fkey
6203
6204 Select (pceipcTS)
6205 IF SEEK(__tmpipcts.PKey, pceipcTS, "PKey")
6206
6207 lcDivision = Division
6208 lcStyle = Style
6209 lcColor_Code = Color_Code
6210 lcLbl_Code = Lbl_Code
6211 lcDimension = __tmpipcts.PPK_Code
6212 lcSize_Desc = Size_Desc
6213
6214 select (pceipcTD)
6215 IF SEEK(lnFKey, pceipcTD, "PKey") AND !(Style_SLN_OK = 'Y')
6216
6217 replace Division with lcDivision, ;
6218 Style with lcStyle, ;
6219 Color_Code with lcColor_Code, ;
6220 Lbl_Code with lcLbl_Code, ;
6221 Dimension with lcDimension,;
6222 SizeBucket with 1;
6223 Size_Desc with lcSize_Desc;
6224 Style_SLN_OK with 'Y' ;
6225 IN (pceipcTD)
6226 ENDIF
6227 ENDIF
6228 ENDSCAN
6229
6230 IF USED("__tmpipcts")
6231 USE IN __tmpipcts
6232 ENDIF
6233
6234 Select(lnOldSelect)
6235 Return llRetVal
6236 Endproc
6237* === TR 1047609 7/7/10 CM
6238
6239* --- TR 1047609 7/7/10 CM
6240* Routine from 850 also implemented within 860
6241*---------------------------------------------------------------------------------
6242 FUNCTION GetTotSLNQty
6243 LPARAMETERS tnPSFkey, pceipcTS
6244
6245 LOCAL lnTotSlnQty, lnOldSelect
6246 LOCAL ARRAY laTotSlnQty[1]
6247
6248 lnOldSelect = SELECT()
6249 lnTotSlnQty = 0
6250
6251 SELECT SUM(sln_qty) FROM (pceipcTS) WHERE fkey = tnPSFkey INTO ARRAY laTotSlnQty
6252 lnTotSlnQty = laTotSlnQty[1]
6253
6254 Select(lnOldSelect)
6255 Return lnTotSlnQty
6256 ENDFUNC
6257*=================================================================================
6258* === TR 1047609 7/7/10 CM
6259
6260 *============================================================
6261 *--- TechRec 1050485 17-Dec-2010 vkrishnamurthy/Goutam ---
6262 FUNCTION MoveRZtoAI
6263 LOCAL llRetVal, lnSelect,lcFilter ,lcSql
6264 llRetVal = true
6265 lnSelect = SELECT()
6266
6267 WITH This
6268 lcFilter = IIF (EMPTY(.cFilterCriteria),"",.cFilterCriteria)
6269 lcFilter = STRTRAN(lcFilter,"H.","TH.")
6270 lcFilter = STRTRAN(lcFilter,"Where","")
6271
6272 *--- TR 1083913 02-Feb-2015 Partha ---
6273 * CHANGED: and c.template = " + SQLFormatChar('JCP 4030 860')
6274 * TO: and c.template IN ('JCP 4030 860','Biglots 5010 860')
6275 *
6276 * CHANGED: h.po_type = 'KC'
6277 * TO: h.po_type = 'KC' OR c.template = 'BIGLOTS 5010 860'
6278 *=== TR 1083913 02-Feb-2015 Partha ===
6279
6280 lcSql = "update td set td.qualifier = 'AI' " + ;
6281 " from zzeipctd td join zzeipcth th on th.pkey = td.fkey " + ;
6282 " Join zzeipccr c " + ;
6283 " on c.division = th.division "+ ;
6284 " and c.customer = th.customer "+ ;
6285 " and c.template IN ('JCP 4030 860','Biglots 5010 860')" + ; && 1083913
6286 " LEFT Join zzeipohh h "+ ; && 1083913 - Changed to LEFT Join
6287 " on h.po_num = th.po_num " +;
6288 " and h.po_type = 'KC' " + ;
6289 " where td.qualifier = 'RZ' " + IIF(EMPTY(lcFilter),lcFilter," AND " + lcFilter)+;
6290 " AND ( c.template = 'Biglots 5010 860' OR h.po_num is not null ) " + ; && 1083913
6291 " and NOT exists (select od.pkey from zzoordrd od (nolock) "+ ;
6292 " join zzoordrh oh (nolock) " + ;
6293 " on oh.pkey = od.fkey " + ;
6294 " join zzxstylr lr " + ;
6295 " on od.division = lr.division " + ;
6296 " and od.style = lr.style" + ;
6297 " join zzxsizer sr" + ;
6298 " on sr.division = od.division" + ;
6299 " and sr.size_code = lr.size_code " + ;
6300 " cross join zzxbuckt b " + ;
6301 " where od.size01_qty * b.sz01 + od.size02_qty * b.sz02 + od.size03_qty * b.sz03 + od.size04_qty * b.sz04 + od.size05_qty * b.sz05 + " + ;
6302 " od.size06_qty * b.sz06 + od.size07_qty * b.sz07 + od.size08_qty * b.sz08 + od.size09_qty * b.sz09 + od.size10_qty * b.sz10 + " + ;
6303 " od.size11_qty * b.sz11 + od.size12_qty * b.sz12 + od.size13_qty * b.sz13 + od.size14_qty * b.sz14 + od.size15_qty * b.sz15 + " + ;
6304 " od.size16_qty * b.sz16 + od.size17_qty * b.sz17 + od.size18_qty * b.sz18 + od.size19_qty * b.sz19 + od.size20_qty * b.sz20 + " + ;
6305 " od.size21_qty * b.sz21 + od.size22_qty * b.sz22 + od.size23_qty * b.sz23 + od.size24_qty * b.sz24 > 0 " + ;
6306 " and oh.po_num = th.po_num " + ;
6307 " and oh.customer = th.customer "+ ;
6308 " and oh.store = th.store "+ ;
6309 " and oh.ord_status = 'O' " + ;
6310 " and od.division = td.division " + ;
6311 " and od.style = td.style " + ;
6312 " and od.color_code = td.color_code " + ;
6313 " and od.lbl_code = td.lbl_code " + ;
6314 " and od.dimension = td.dimension " + ;
6315 " and case when b.SZ01 > 0 then sr.size01 " + ;
6316 " when b.SZ02 > 0 then sr.size02 " + ;
6317 " when b.SZ03 > 0 then sr.size03 " + ;
6318 " when b.SZ04 > 0 then sr.size04 " + ;
6319 " when b.SZ05 > 0 then sr.size05 " + ;
6320 " when b.SZ06 > 0 then sr.size06 " + ;
6321 " when b.SZ07 > 0 then sr.size07 " + ;
6322 " when b.SZ08 > 0 then sr.size08 " + ;
6323 " when b.SZ09 > 0 then sr.size09 " + ;
6324 " when b.SZ10 > 0 then sr.size10 " + ;
6325 " when b.SZ11 > 0 then sr.size11 " + ;
6326 " when b.SZ12 > 0 then sr.size12 " + ;
6327 " when b.SZ13 > 0 then sr.size13 " + ;
6328 " when b.SZ14 > 0 then sr.size14 " + ;
6329 " when b.SZ15 > 0 then sr.size15 " + ;
6330 " when b.SZ16 > 0 then sr.size16 " + ;
6331 " when b.SZ17 > 0 then sr.size17 " + ;
6332 " when b.SZ18 > 0 then sr.size18 " + ;
6333 " when b.SZ19 > 0 then sr.size19 " + ;
6334 " when b.SZ20 > 0 then sr.size20 " + ;
6335 " when b.SZ21 > 0 then sr.size21 " + ;
6336 " when b.SZ22 > 0 then sr.size22 " + ;
6337 " when b.SZ23 > 0 then sr.size23 " + ;
6338 " when b.SZ24 > 0 then sr.size24 end = td.size_desc) "
6339
6340 llRetVal = llRetVal and v_sqlexec(lcSQL)
6341
6342 IF llRetVal
6343 REQUERY('Vzzeipcth_ipcproc')
6344 SELECT ('Vzzeipcth_ipcproc')
6345 SCAN
6346 SCATTER NAME loEiPCth MEMO
6347 SELECT tceipcTH
6348 IF SEEK(loEiPCth.pkey,'tceipcTH','PKEY')
6349 GATHER NAME loEiPCth MEMO
6350 ELSE
6351 APPEND BLANK
6352 GATHER NAME loEiPCth MEMO
6353 ENDIF
6354 ENDSCAN
6355
6356 REQUERY('Vzzeipctd_ipcproc')
6357 SELECT Vzzeipctd_ipcproc
6358 SCAN
6359 SCATTER NAME loEiPCtd MEMO
6360 SELECT tceipcTD
6361 IF SEEK(loEiPCtd.pkey,'tceipcTD','PKEY')
6362 GATHER NAME loEiPCtd MEMO
6363 ELSE
6364 APPEND BLANK
6365 GATHER NAME loEiPCtd MEMO
6366 ENDIF
6367
6368 ENDSCAN
6369 ENDIF
6370
6371 ENDWITH
6372
6373 SELECT (lnSelect)
6374 RETURN llRetVal
6375 ENDFUNC
6376 *=== TechRec 1050485 17-Dec-2010 vkrishnamurthy/Goutam ===
6377 *============================================================
6378
6379 *--- TR 1048865 13-Apr-2011 Goutam
6380 FUNCTION InsertExtraRecordFromSO
6381 LPARAMETERS pcFilter, pcipcOrder_New, pcipcth_New, pcipctd_New
6382
6383 LOCAL lnOldSelect, llRetVal, lcSql, lcAddlSOHCurs, lcAddlSODCurs
6384 lnOldSelect = SELECT()
6385 llRetVal = true
6386
6387 lcAddlSOHCurs = "#AddlSOH" + SYS(2015)
6388 lcAddlSODCurs = "#AddlSOD" + SYS(2015)
6389
6390 WITH this
6391 lcSql = "select * into " + lcAddlSOHCurs + ;
6392 " from zzoordrh h " + ;
6393 " where h.ord_status = 'O' " + ;
6394 " and exists( " + ;
6395 " select 1 " + ;
6396 " from " + pcipcOrder_New + " oh " + ;
6397 " where oh.ORD_NUM = h.ord_num " + ;
6398 " and oh.store = h.store) "
6399
6400 llRetVal = llRetVal and v_sqlexec(lcSql)
6401
6402 lcSql = "select u.UPC_NUM+u.CHK_DIGIT as upc, h.po_num, h.store " + ;
6403 " , d.* into " + lcAddlSODCurs + ;
6404 " from zzoordrh h " + ;
6405 " join zvoordrdv d " + ;
6406 " on d.fkey = h.pkey " + ;
6407 " join zveupcnr u " + ;
6408 " on u.DIVISION = d.division " + ;
6409 " and u.STYLE = d.style " + ;
6410 " and u.COLOR_CODE = d.color_code " + ;
6411 " and u.LBL_CODE = d.lbl_code " + ;
6412 " and u.DIMENSION = d.dimension " + ;
6413 " and u.SIZEBUCKET = d.Size_Bk " + ;
6414 " where h.ord_status = 'O' " + ;
6415 " and exists( " + ;
6416 " select 1 " + ;
6417 " from " + pcipcOrder_New + " oh " + ;
6418 " where oh.ORD_NUM = h.ord_num " + ;
6419 " and oh.store = h.store) " + ;
6420 " and not exists( " + ;
6421 " select 1 " + ;
6422 " from zzeipcth th " + ;
6423 " join zzeipctd td " + ;
6424 " on th.pkey = td.fkey " + ;
6425 " and th.po_num = h.po_num " + ;
6426 " and th.ord_num = h.ord_num " + ;
6427 " and th.store = h.store " + ;
6428 " and th.customer = h.customer " + ;
6429 " and td.UPC = u.upc_num+u.chk_digit where " + IIF(EMPTY(pcFilter),"1=1", pcFilter) + ")" + ;
6430 " and exists( " + ;
6431 " select 1 " + ;
6432 " from zzeipcth th " + ;
6433 " join zzeipctd td " + ;
6434 " on th.pkey = td.fkey " + ;
6435 " and td.UPC = u.upc_num+u.chk_digit where " + IIF(EMPTY(pcFilter),"1=1", pcFilter) + ")"
6436
6437
6438 llRetVal = llRetVal and v_sqlexec(lcSql)
6439
6440 llRetVal = llRetVal and .GenSQLZZEIPCTH(lcAddlSOHCurs, pcipcth_New)
6441 llRetVal = llRetVal and .GenSQLZZEIPCTD(lcAddlSODCurs, pcipctd_New)
6442
6443 .dropTempTable(lcAddlSOHCurs, true)
6444 .dropTempTable(lcAddlSODCurs, true)
6445
6446 ENDWITH
6447
6448 SELECT(lnOldSelect)
6449 RETURN llRetVal
6450 ENDPROC
6451
6452 FUNCTION GenSQLZZEIPCTH
6453 LPARAMETERS pcAddlSOHCurs, pcSourceIPCth
6454
6455 LOCAL lnOldSelect, llRetVal
6456 lnOldSelect = SELECT()
6457 llRetVal = true
6458
6459 WITH this
6460
6461 *------ Use SQL String Builder -------------------------*
6462 .oGenStr.SB_Reset()
6463
6464 .oGenStr.cSB_Target = "ZZEIPCTH"
6465 .oGenStr.cSB_Source = pcSourceIPCth
6466 .oGenStr.cSB_SourceAlias = "th"
6467 .oGenStr.cSB_FROMExpandedString = " join " + pcAddlSOHCurs + " oh on 1 = 1 join zzxstorr s on s.store = oh.store and s.customer = oh.customer"
6468
6469 .oGenStr.cSB_WHEREString = "th.pkey = (Select top 1 pkey from " + pcSourceIPCth + " where division = oh.division and po_num = oh.po_num and customer = oh.customer)"
6470
6471 .oGenStr.SB_SetLiteralFieldValue("edi_store","s.edi_store")
6472 .oGenStr.SB_SetLiteralFieldValue("ord_num","oh.ord_num")
6473 .oGenStr.SB_SetLiteralFieldValue("store","oh.store")
6474
6475 .oGenStr.SB_KeySetAddKeySpec("pkey","INT","th.pkey","th.pkey")
6476 .oGenStr.SB_KeySetAddKeySpec("ord_num","INT","oh.ord_num","oh.ord_num")
6477 .oGenStr.SB_KeySetAddKeySpec("po_num","Char(20)","oh.po_num","oh.po_num")
6478 .oGenStr.SB_KeySetAddKeySpec("store","Char(9)","oh.store","oh.store")
6479
6480 llRetVal = .oGenStr.SB_GenerateSQLInsertString()
6481
6482 IF llRetVal
6483 .cHBCKeySet = .oGenStr.aSB_BCKeySet[ALEN(.oGenStr.aSB_BCKeySet)]
6484 .nH_FirstPkey = .oGenStr.nSB_FirstPkey
6485 llRetVal = v_sqlexec(.oGenStr.cSQLString)
6486 ELSE
6487 lcMessage = "Failed to generate SQL string for 860(i) header NZ Qualifier. Cannot continue."
6488 .oLog.LogEntry(lcMessage)
6489 ENDIF
6490
6491 ENDWITH
6492
6493 SELECT(lnOldSelect)
6494 RETURN llRetVal
6495 ENDPROC
6496
6497 FUNCTION GenSQLZZEIPCTD
6498 LPARAMETERS lcAddlSODCurs, pcSourceIPCtd
6499
6500 LOCAL lnOldSelect, llRetVal
6501 lnOldSelect = SELECT()
6502 llRetVal = true
6503
6504 WITH this
6505
6506 *------ Use SQL String Builder -------------------------*
6507 .oGenStr.SB_Reset()
6508
6509 .oGenStr.cSB_Target = "ZZEIPCTD"
6510 .oGenStr.cSB_Source = pcSourceIPCtd
6511 .oGenStr.cSB_SourceAlias = "td"
6512
6513 .oGenStr.cSB_FROMExpandedString = "JOIN " + .cHBCKeySet + " th ON th.pkey = td.fkey join " + lcAddlSODCurs + " od on od.ord_num = th.ord_num and od.po_num = th.po_num and od.store = th.store "
6514 .oGenStr.SB_SetLiteralFieldValue("fkey","th.bc_pkey + " + SQLFormatNum(.nH_FirstPkey))
6515
6516 .oGenStr.SB_SetLiteralFieldValue("division","od.division")
6517 .oGenStr.SB_SetLiteralFieldValue("style","od.style")
6518 .oGenStr.SB_SetLiteralFieldValue("color_code","od.color_code")
6519 .oGenStr.SB_SetLiteralFieldValue("lbl_code","od.lbl_code")
6520 .oGenStr.SB_SetLiteralFieldValue("dimension","od.dimension")
6521 .oGenStr.SB_SetLiteralFieldValue("size_desc","od.size_desc")
6522 .oGenStr.SB_SetLiteralFieldValue("sizebucket","od.size_bk")
6523 .oGenStr.SB_SetLiteralFieldValue("upc","od.upc")
6524 .oGenStr.SB_SetLiteralFieldValue("qty_change","od.bk_qty")
6525 .oGenStr.SB_SetLiteralFieldValue("qualifier","'DI'")
6526
6527 .oGenStr.SB_KeySetAddKeySpec("pkey","INT","td.fkey","td.fkey")
6528 .oGenStr.SB_KeySetAddKeySpec("ord_num","INT","od.ord_num","od.ord_num")
6529 .oGenStr.SB_KeySetAddKeySpec("upc","Char(12)","od.upc","od.upc")
6530 .oGenStr.SB_KeySetAddKeySpec("line_seq","INT","od.line_Seq","od.line_Seq")
6531
6532 llRetVal = .oGenStr.SB_GenerateSQLInsertString()
6533
6534 IF llRetVal
6535 llRetVal = v_sqlexec(.oGenStr.cSQLString)
6536 ELSE
6537 lcMessage = "Failed to generate SQL string for 860(i) detail NZ Qualifier. Cannot continue."
6538 .oLog.LogEntry(lcMessage)
6539 ENDIF
6540
6541 ENDWITH
6542
6543 SELECT(lnOldSelect)
6544 RETURN llRetVal
6545 ENDPROC
6546 *=== TR 1048865 13-Apr-2011 Goutam
6547
6548 *--- TechRec 1056904 24-Oct-2011 jisingh ---
6549 *============================================================
6550
6551 PROCEDURE Check850TM
6552 LPARAMETERS pceipcTH, pceipcCR
6553 LOCAL llRetVal, lnSelect, lcSQLString
6554
6555 llRetVal = true
6556 lnSelect = SELECT()
6557
6558 WITH This
6559
6560 *--- TR 1065396 22-Nov-2012 Goutam. Added template COSTCO 860
6561 *--- TR 1070268 27-Jun-2013 Goutam. Added template BURLINGTON 4010
6562 lcSQLString = " SELECT th.customer, th.division, th.po_num, th.Store FROM (pceipcTH) th " + ;
6563 " JOIN (pceipcCR) cr ON cr.customer = th.customer AND cr.division = th.division " + ;
6564 " WHERE th.po_purp = '05' AND (cr.template = 'CHARMING SHOPPES 4030' or cr.template = 'COSTCO 860' or cr.template = 'BURLINGTON 4010')"
6565
6566 llRetVal = llRetVal AND v_SQLExec(lcSQLString, "tc860TM",,true)
6567
6568 IF llRetVal AND RECCOUNT("tc860TM") > 0
6569 .cSQLTempTable = ""
6570 llRetVal = llRetVal AND .GenerateSQLTempTable("tc860TM")
6571 llRetVal = llRetVal AND .PopulateSQLTempTable("tc860TM")
6572
6573 lcSQLString = " SELECT DISTINCT th.division, th.customer, th.po_num, th.Store " + ;
6574 " FROM zzeipoth th " + ;
6575 " JOIN " + This.cSQLTempTable + " t " + ;
6576 " ON t.customer = th.customer " + ;
6577 " AND t.division = th.division " + ;
6578 " AND t.po_num = th.po_num "
6579
6580 llRetVal = llRetVal AND v_SQLExec(lcSQLString, "tc850")
6581
6582 SELECT tc850
6583 INDEX ON customer+division+po_num+store TAG cdp
6584
6585 SELECT tc860TM
6586 SCAN
6587 IF !SEEK(tc860TM.customer+tc860TM.division+tc860TM.po_num+tc860TM.store, "tc850", "cdp")
6588
6589 REPLACE errs_flg_h WITH 'Y', ;
6590 errs_msg_h WITH errs_msg_h + 'Replacement order for this PO is not found in the 850 Transaction Maintenance.' + CRLF ;
6591 FOR customer = tc860TM.customer AND division = tc860TM.division AND po_num = tc860TM.po_num AND store = tc860TM.store AND po_purp = '05' ;
6592 IN (pceipcTH)
6593
6594 ENDIF
6595 ENDSCAN
6596 .TableClose("tc860TM")
6597 ENDIF
6598 .TableClose("tc850")
6599 ENDWITH
6600
6601 SELECT (lnSelect)
6602 RETURN llRetVal
6603 ENDPROC
6604 *=== TechRec 1056904 24-Oct-2011 jisingh ===
6605
6606 *--- TR 1062197 7-Sep-2012 Goutam
6607 PROCEDURE ExplodeOrderForPOCStore
6608
6609 LOCAL llRetVal, lnSelect, lcSQLString, lcFilter
6610
6611 llRetVal = true
6612 lnSelect = SELECT()
6613
6614 WITH This
6615
6616 lcFilter = IIF (EMPTY(this.cFilterCriteria),"",THIS.cFilterCriteria)
6617 lcFilter = STRTRAN(lcFilter,"Where","")
6618
6619 lcSQLString = "Update h set edi_store = poc_store FROM zzeipcth h " + ;
6620 " WHERE poc_purp = '04' and poc_store > '' and store = ''" + ;
6621 IIF(EMPTY(lcFilter),""," and " + lcFilter)
6622
6623 llRetVal = llRetVal and v_sqlexec(lcSQLString)
6624
6625 ENDWITH
6626
6627 SELECT (lnSelect)
6628 RETURN llRetVal
6629 ENDPROC
6630
6631 PROCEDURE CheckDistribution
6632 LPARAMETERS tcTransHeader
6633
6634 LOCAL llRetVal, lnSelect, lcSQLStoreStr, llVerifyDC, lcShipTo, lcStore, lcCustomer, lcStoreRef, lcShip_dc_Type, lcUpdateStr, ;
6635 lcCenter_Field, lcErrs_Msg
6636
6637 llRetVal = true
6638 lnSelect = SELECT()
6639
6640 WITH This
6641 Select distinct customer, store, poc_shipto, po_num ;
6642 From (tcTransHeader) Where !Empty(customer) AND !EMPTY(poc_shipto) Into Cursor tcTemp
6643 Select tcTemp
6644 SCAN
6645 lcCustomer = tcTemp.customer
6646 lcStore = tcTemp.store
6647 lcPO_num = tcTemp.po_num
6648 lcShipTo = tcTemp.poc_shipto && could be either EDI_STORE or EDI_CENTER
6649
6650 lcSQLStoreStr = "SELECT customer, store, edi_store " + ;
6651 "FROM zzxstorr WHERE customer = " + Sqlformatchar(lcCustomer) + " AND edi_store = " + Sqlformatchar(lcShipTo)
6652
6653 llRetVal = llRetVal And v_SQLExec(lcSQLStoreStr, "tcStorr")
6654
6655 lcStoreRef = iif(llRetVal and Used("tcStorr"), tcStorr.store, "")
6656
6657 * Set Verify DC flag
6658 llVerifyDC = .T.
6659
6660 IF !Empty(lcStoreRef) And (Allt(lcStoreRef) == Allt(lcStore))
6661 * do nothing to EDI_CENTER from transaction
6662 llVerifyDC= .F.
6663 ENDIF
6664
6665 If llVerifyDC
6666 * SHIPTO should be poc_shipto
6667 * Check poc_shipto
6668 lcErrs_Msg= ""
6669
6670 lcCenter_Field = 'tcTemp.poc_shipto'
6671 DO CASE
6672 CASE .ValidEDIDist_Cons(@lcErrs_Msg, lcCustomer, lcShipTo, "D", "tcDistr")
6673 * replace center_code with shipthru.center_code when found edi_center
6674 Replace center_code with tcDistr.center_code, poc_shipto WITH "" ;
6675 For Customer= lcCustomer and poc_shipto = lcShipTo and po_num= lcPO_num ;
6676 In (tcTransHeader)
6677 CASE .ValidEDIDist_Cons(@lcErrs_Msg, lcCustomer, lcShipTo, "C", "tcDistr")
6678 * replace center_code with shipthru.center_code when found edi_center
6679 Replace consol_code with tcDistr.center_code ;
6680 For Customer= lcCustomer and ;
6681 poc_shipto = lcShipTo and po_num= lcPO_num ;
6682 In (tcTransHeader)
6683 lcErrs_Msg = ""
6684 *- The shipto also can be a store. Check it last in case we set up both
6685 *- edi center and stroe with the same code. We do it sometimes.
6686 CASE .ValidEDIStore(@lcErrs_Msg, lcCustomer, lcShipTo, "tcDistr")
6687 Replace store with tcDistr.store, ;
6688 edi_store WITH tcDistr.edi_store, ;
6689 poc_store WITH IIF(EMPTY(poc_store),tcDistr.edi_store, poc_store), ;
6690 center_code with "", ;
6691 consol_code with "", ;
6692 poc_shipto WITH "" ;
6693 For Customer= lcCustomer ;
6694 and poc_shipto = lcShipTo and po_num= lcPO_num ;
6695 In (tcTransHeader)
6696 *=
6697 OTHERWISE
6698 lcErrs_Msg= "Invalid POC Ship To Code" + CRLF
6699 Replace Errs_msg_h With Errs_msg_h + lcErrs_Msg, Errs_Flg_H With "Y" ;
6700 For customer= lcCustomer and poc_shipto = lcShipTo and po_num= lcPO_num ;
6701 In (tcTransHeader)
6702 EndCase && ValidEDIDistribute()
6703
6704 Endif && llVerifyDC
6705
6706
6707 ENDSCAN
6708 ENDWITH
6709
6710 SELECT (lnSelect)
6711 RETURN llRetVal
6712 ENDPROC
6713
6714 ************************************************************************************
6715 * Valid EDI Distrubtion Center or Consolidator
6716 ************************************************************************************
6717 PROCEDURE ValidEDIDist_Cons
6718 Lparameter tcErrorMsg, tcCustomer, tcCenter_code, tcShip_DC, tcTmpTable
6719 Local llRetVal
6720
6721 llRetVal= !(Empty(tcCenter_code) or ;
6722 !vl_diste(tcCustomer, "", tcTmpTable, tcCenter_code, tcShip_DC))
6723 Return llRetVal
6724 EndProc
6725
6726 PROCEDURE ValidEDIStore
6727 Lparameter tcErrorMsg, tcCustomer, tcStore, tcTmpTable
6728 Local llRetVal
6729 llRetVal= vl_store(tcCustomer, "", tcTmpTable, tcStore)
6730 Return llRetVal
6731 EndProc
6732
6733 PROCEDURE UpdatePOCShiptoWithConsolCode
6734 LPARAMETERS tcTransHeader
6735
6736 LOCAL llRetVal, lnSelect
6737
6738 llRetVal = true
6739 lnSelect = SELECT()
6740
6741 WITH This
6742 replace poc_shipto WITH consol_code FOR errs_flg_h <> 'Y' AND Auto_proc = 'Y' AND !EMPTY(consol_code) AND !EMPTY(poc_shipto) IN (tcTransHeader)
6743 ENDWITH
6744
6745 SELECT (lnSelect)
6746 RETURN llRetVal
6747 ENDPROC
6748 *=== TR 1062197 7-Sep-2012 Goutam
6749
6750 *--- TR 1066871 8-May-2013 Goutam. This is local instances of SplitFlatFile from clsedi.prg
6751 Procedure SplitFlatFile
6752 Lparameters tcSource, tcRenameOnly
6753 Local llRetVal, lnOldSelect, lcEDIPath, lcSource, lnHandle, lnMaxBytes, lcBuffer, lcTag, lnTagPos, ;
6754 lnTagDelimPos, lcNewFileName, lcUniqueSuff, llEmptyFile, ll850Created, lcDoc_Num, ln2ndTagDelimPos, llNewHDR
6755
6756 lcUniqueSuff = Sys(2015)
6757 llEmptyFile = .f.
6758
6759 Declare laTags[1, 1]
6760 laTags = ""
6761 llRetVal = .T.
6762 lnOldSelect = Select()
6763 lcEDIPath = This.GetEDIFlatFileDirectory("Inbound")
6764 lcEDIPath = Iif(Right(Alltrim(lcEDIPath ), 1) = "\", Alltrim(lcEDIPath ), Alltrim(lcEDIPath ) + "\")
6765 lcSourceDat = Upper( lcEDIPath + Alltrim(tcSource) )
6766
6767 If File(lcSourceDat)
6768
6769 * If we've gotten to this point there's a flat file to
6770 * process, store it and use it later during our file rename.
6771 This.lDATExists = true
6772
6773 *lcSource = FORCEEXT(lcSourceDat, ".PRI") && rename .dat to .pri right away, new .dat may be on its way
6774 lcSource = Forceext(Alltrim(tcSource), ".PRI") && copy server side .dat to local .pri right away, new .dat may be on its way
6775
6776 lcSource = Iif(!tcRenameOnly, Stuff(lcSource,At(".",lcSource),0,lcUniqueSuff), Forceext(lcSourceDat, ".PRI"))
6777
6778 IF tcRenameOnly
6779 Copy File (lcSourceDat) To (lcSource)
6780 ENDIF
6781
6782 If !tcRenameOnly && need to split
6783
6784 * Remove source
6785 IF FILE(lcSource)
6786 DELETE FILE (lcSource)
6787 ENDIF
6788
6789 RENAME (lcSourceDat) To (lcSource)
6790
6791 IF FILE(lcSourceDat)
6792 RETURN false
6793 ENDIF
6794
6795 lnHandle = Fopen(lcSource)
6796 llRetVal = (lnHandle > 0)
6797 lnMaxBytes = 8192 && max bytes FGETS can read. It reads until CRLF is encountered inside the lnMaxBytes.
6798 lnPos = At(".", tcSource)
6799 llRetVal = llRetVal And (lnPos > 0)
6800
6801 IF llRetVal AND Feof(lnHandle)
6802 llEmptyFile = .t.
6803 ENDIF
6804
6805 If llRetVal
6806 Do While !Feof(lnHandle)
6807 lcBuffer = Fgets(lnHandle, lnMaxBytes) + CRLF && Store one line to string
6808
6809 *- Tag may be 2 or 3 characters
6810 lcTag = Left(lcBuffer, 3)
6811 lnTagDelimPos = At("|", lcBuffer)
6812 lcTag = Left(lcBuffer, lnTagDelimPos - 1)
6813 *==
6814
6815 IF lcTag == "850HDR"
6816 llNewHDR = true
6817 ENDIF
6818
6819 lcBufferData = Strtran(lcBuffer, CRLF)
6820 lcBufferData = Strtran(lcBufferData, "|", "")
6821 If Empty(lcBufferData) Or lcBufferData == lcTag && nothing except the tag
6822 Loop && skip empty line
6823 Endif
6824
6825 lnALen = Alen(laTags,1)
6826 If !Empty(laTags[1]) && at least one tag has been processed
6827 lnTagPos = Ascan(laTags, lcTag, 1, lnALen, 1, 6)
6828 Else && the first record.
6829 lnTagPos = 0
6830 lnALen = 0
6831 Endif
6832 If lnTagPos = 0
6833 *- define the split file name
6834
6835 lcSplitFName = Stuff(tcSource, lnPos, 0, lcTag + lcUniqueSuff )
6836
6837 lcSplitFile = Alltrim(Stuff(tcSource, lnPos, 0, lcTag))
6838
6839 *--- make sure the local unique file is deleted.
6840 Delete File (lcSplitFName)
6841 IF (!ll850Created OR !LEFT(lcSplitFName, 6) = "860850")
6842 Declare laTags[lnALen + 1, 3]
6843 laTags[lnALen + 1, 1] = lcTag
6844 laTags[lnALen + 1, 2] = lcSplitFile
6845 laTags[lnALen + 1, 3] = lcSplitFName
6846 ENDIF
6847 Else
6848 lcSplitFName = laTags[lnTagPos + 2]
6849 ENDIF
6850
6851 IF LEFT(lcSplitFName, 6) = "860850"
6852 lcNewFileName = "850.dat"
6853 ll850Created = true
6854
6855 lcBuffer = SUBSTR(lcBuffer, 4)
6856 lcTag = "850"
6857
6858 IF ASCAN(laTags,lcNewFileName) = 0
6859 Delete File (lcNewFileName)
6860
6861 laTags[lnALen + 1, 1] = lcTag
6862 laTags[lnALen + 1, 2] = lcNewFileName
6863 laTags[lnALen + 1, 3] = lcNewFileName
6864 ENDIF
6865
6866 IF llNewHDR
6867 llNewHDR = false
6868 lnTagDelimPos = At("|", lcBuffer)
6869 ln2ndTagDelimPos = At("|", lcBuffer,2)
6870 lcDoc_Num = SUBSTR(lcBuffer, lnTagDelimPos + 1, (ln2ndTagDelimPos - lnTagDelimPos - 1))
6871
6872 this.oLog.LogEntry("EDI 850 flat file created from EDI 860. Doc # :" + lcDoc_Num)
6873
6874 INSERT INTO (this.c850RefCursor) (doc_num, proc_850) VALUES (VAL(lcDoc_Num), 'Y')
6875 ENDIF
6876
6877 Strtofile(lcBuffer, lcNewFileName, .T.)
6878 ELSE
6879 Strtofile(lcBuffer, lcSplitFName, .T.)
6880 ENDIF
6881 Enddo
6882 Else
6883 Endif
6884 Fclose(lnHandle)
6885
6886 IF NOT llEmptyFile
6887
6888 *- Copy LOCAL .pri and split files to server to be renamed later.
6889 lcServerFile = Forceext(lcSourceDat, ".PRI")
6890 Copy File (lcSource) To (lcServerFile)
6891 Delete File (lcSource)
6892 lnALen = Alen(laTags,1)
6893 For N = 1 To lnALen
6894 lcSplitFile = laTags[n, 2]
6895 lcServerSplitFile = lcEDIPath + lcSplitFile
6896 lcSplitFName = laTags[n, 3]
6897 This.CopyToFlatFileInBlock(lcSplitFName, lcServerSplitFile)
6898 Delete File (lcSplitFName)
6899
6900 Endfor
6901 ELSE
6902 Delete File (lcSource)
6903 ENDIF
6904 Endif
6905 Endif
6906 Select (lnOldSelect)
6907 Return llRetVal
6908 Endproc
6909 *=== TR 1066871 8-May-2013 Goutam
6910
6911*--- TechRec 1073591 15-Oct-2013 TShenbagavalli ---
6912*===========================================================================================
6913 PROCEDURE ResolveCustShipper
6914 Lparameters pceipcTH, pceipcCR
6915 LOCAL lnSelect, llRetVal, lcSQLString
6916
6917 lnSelect = SELECT()
6918 llRetVal = True
6919
6920 WITH This
6921
6922 lcSQLString = " SELECT distinct h.customer, h.division, " + ;
6923 " h.cust_shipper " + ;
6924 " FROM " + pceipcTH + " h, " + pceipcCR + " r " + ;
6925 " WHERE r.resv_cust_ship = 'Y' and " + ;
6926 " NOT EMPTY(h.cust_shipper) and " + ;
6927 " h.customer = r.customer and " + ;
6928 " h.division = r.division "
6929
6930 llRetVal = v_SqlExec(lcSQLString, "_tmpCustShipper",,.T.)
6931
6932 INDEX ON customer + division + cust_shipper TAG 'cust_ship'
6933
6934 llRetVal= RECCOUNT('_tmpCustShipper') > 0 AND .SetRelation("_tmpCustShipper", "cust_ship", pceipcTH, "customer + division + cust_shipper")
6935
6936 IF llRetVal
6937 REPLACE ALL shipper WITH '' ;
6938 FOR !EOF('_tmpCustShipper') ;
6939 AND NOT EMPTY(cust_shipper) In (pceipcTH)
6940
6941 SET RELATION TO
6942 ENDIF
6943
6944 SELECT '_tmpCustShipper'
6945
6946 .cSQLTempTable = ""
6947
6948 IF .GenerateSQLTempTable('_tmpCustShipper')
6949 IF .PopulateSQLTempTable('_tmpCustShipper')
6950 IF !EMPTY(.cSQLTempTable)
6951
6952 lcSQLString= "Select t.customer, t.division, t.cust_shipper, " + ;
6953 " Coalesce(s1.shipper, s2.shipper, '') as shipper " + ;
6954 "from " + .cSQLTempTable + " t " + ;
6955 " left join zzecshpd s1 " +;
6956 " on s1.customer = t.customer " + ;
6957 " AND s1.division = t.division " + ;
6958 " AND s1.cust_shipper = t.cust_shipper " + ;
6959 " left join zzecshpd s2 " +;
6960 " on s2.customer = t.customer " + ;
6961 " AND s2.division = '' " + ;
6962 " AND s2.cust_shipper = t.cust_shipper "
6963
6964 llRetVal = v_SqlExec(lcSQLString, "_custShipper")
6965
6966 IF llRetVal and RECCOUNT('_custShipper') > 0
6967 SELECT _custShipper
6968 INDEX ON customer + division + cust_shipper TAG 'cust_ship'
6969 llRetVal= .SetRelation("_custShipper", "cust_ship", pceipcTH, "customer + division + cust_shipper")
6970 IF llRetVal
6971 Replace All shipper with _custShipper.shipper ;
6972 FOR !EOF('_custShipper') AND NOT EMPTY(cust_shipper) In (pceipcTH)
6973 SET RELATION TO
6974 ENDIF
6975 ENDIF
6976 ENDIF
6977 ENDIF
6978 ENDIF
6979
6980 USE in '_tmpCustShipper'
6981
6982 lcSQLString = " SELECT distinct h.customer, h.division, " + ;
6983 " h.cust_shipper " + ;
6984 " FROM " + pceipcTH + " h, " + pceipcCR + " r " + ;
6985 " WHERE r.resv_cust_ship = 'Y' and " + ;
6986 " NOT EMPTY(h.cust_shipper) and " + ;
6987 " h.customer = r.customer and " + ;
6988 " h.division = r.division and " + ;
6989 " EMPTY(h.shipper) "
6990
6991 llRetVal = v_SqlExec(lcSQLString, "_tmpCustShipper",,.T.)
6992
6993 INDEX ON customer + division + cust_shipper TAG 'cust_ship'
6994
6995 IF RECCOUNT('_tmpCustShipper') > 0
6996 llRetVal= .SetRelation("_tmpCustShipper", "cust_ship", pceipcTH, "customer + division + cust_shipper")
6997
6998 IF llRetVal
6999 Replace ALL Errs_msg_H WITH Errs_msg_H + "Missing or Invalid Shipper." + CRLF, ;
7000 Errs_flg_h WITH "Y" ;
7001 FOR customer = _tmpCustShipper.customer and ;
7002 division = _tmpCustShipper.division and ;
7003 NOT EMPTY(cust_shipper) AND ;
7004 cust_shipper = _tmpCustShipper.cust_shipper and EMPTY(Shipper) In (pceipcTH)
7005
7006 SET RELATION TO
7007 ENDIF
7008
7009 ENDIF
7010
7011 ENDWITH
7012
7013 If Used("_tmpCustShipper")
7014 Use in '_tmpCustShipper'
7015 Endif
7016
7017 If Used("_custShipper")
7018 Use in '_custShipper'
7019 Endif
7020
7021 SELECT(lnSelect)
7022
7023 RETURN llRetVal
7024 ENDPROC
7025*============================================================
7026 PROCEDURE UpdateActualStoreDatawhseWithAllStoreDatawhse
7027 lPARAMETERS pceIPCth, pceIPCtd, pceIPCtwhse
7028
7029 *--- delete all ALL records from detail.
7030 *--- add "DI" notes from ALL records to actual store records.
7031 *--- create notes detail view
7032 *--- add detail notes from ALL store records to acutal store records.
7033
7034 LOCAL llRetVal, lnOldSelect, lcSQL
7035 llRetVal = .t.
7036 lnOldSelect = SELECT()
7037 *--- header view
7038 *--- find the notes of ALL headers
7039 LOCAL lcOldOrder
7040 SELECT (pceIPCth)
7041 lcOldOrder = ORDER()
7042 INDEX ON edi_store TAG edi_store
7043
7044 lcSQL = " SELECT h.customer, h.division, h.po_num, w.* from " + pceIPCtwhse + " w " + ;
7045 " inner join " + pceIPCth + " h on h.pkey = w.hfkey WHERE h.ForAllStore = 'Y' "
7046
7047 llRetVal = v_SqlExec(lcSQL, "tcIPCtwhse_add",,.T.)
7048
7049 IF RECCOUNT("tcIPCtwhse_add") > 0
7050 SELECT (pceIPCth)
7051 INDEX ON customer + division + po_num TAG custPoHdr
7052
7053 SELECT("tcIPCtwhse_add")
7054 SCAN
7055 SCATTER NAME loIPCtwhse_add memo
7056 SELECT(pceIPCth)
7057
7058 IF SEEK(loIPCtwhse_add.customer + loIPCtwhse_add.division + loIPCtwhse_add.PO_num, pceIPCth, "custPoHdr")
7059 SCAN WHILE customer + division + po_num = loIPCtwhse_add.customer + loIPCtwhse_add.division + loIPCtwhse_add.PO_num
7060 IF ForAllStore <> 'Y'
7061 loIPCtwhse_add.fkey = EVALUATE(pceIPCth + ".pkey")
7062 loIPCtwhse_add.pkey = v_nextPkey("ZZEIPCWHSE")
7063 SELECT(pceIPCtwhse)
7064 APPEND BLANK
7065 GATHER NAME loIPCtwhse_add memo
7066 ENDIF
7067 ENDSCAN
7068 ENDIF
7069 ENDSCAN
7070 ENDIF
7071
7072 lcSQL = " SELECT h.customer, h.po_num, d.upc, d.sku, d.ean, d.qualifier, n.* from " + pceIPCtwhse + " n " + ;
7073 " INNER JOIN " + pceIPCtd + " d ON d.pkey = n.dfkey " + ;
7074 " inner join " + pceIPCth + " h on h.pkey = d.fkey WHERE h.ForAllStore = 'Y' "
7075
7076 llRetVal = v_SqlExec(lcSQL, "tcWhseIPCD_add",,.T.)
7077
7078 IF RECCOUNT("tcWhseIPCD_add") > 0
7079 SELECT (pceIPCth)
7080 INDEX ON customer + po_num TAG custPo
7081 *--- IPC tran detail whse
7082 SELECT(pceIPCtd)
7083 SELECT("tcWhseIPCD_add")
7084 SCAN
7085 SCATTER NAME loWhseIPCD_add memo
7086 SELECT(pceIPCth)
7087 IF SEEK(loWhseIPCD_add.customer + loWhseIPCD_add.PO_num, pceIPCth, "custPo")
7088 SCAN WHILE customer + Po_num = loWhseIPCD_add.customer + loWhseIPCD_add.PO_num
7089
7090 IF ForAllStore <> 'Y'
7091 lnPkey_IPCH = pkey
7092 SELECT(pceIPCtd)
7093 IF SEEK(lnPkey_IPCH,pceIPCtd,"fkey")
7094 SCAN WHILE fkey = lnPkey_IPCH
7095 IF upc + sku + ean + qualifier = loWhseIPCD_add.upc + ;
7096 loWhseIPCD_add.sku + loWhseIPCD_add.ean + loWhseIPCD_add.qualifier
7097 loWhseIPCD_add.fkey = EVALUATE(pceIPCtd + ".pkey")
7098 loWhseIPCD_add.pkey = v_nextPkey("ZZEIPCWHSE")
7099 SELECT(pceIPCtwhse)
7100 APPEND BLANK
7101 GATHER NAME loWhseIPCD_add memo
7102 ENDIF
7103 ENDSCAN
7104 ENDIF
7105 ENDIF
7106 ENDSCAN
7107 ENDIF
7108 ENDSCAN
7109 ENDIF
7110 SELECT(lnOldSelect)
7111 RETURN llRetVal
7112 ENDPROC
7113
7114*===========================================================================================
7115*=== TechRec 1073591 15-Oct-2013 TShenbagavalli ===
7116
7117ENDDEFINE
7118*===========================================================================
7119
7120*- 1014475 12/20/05 YIK
7121*- Create new class, subclass of clscancl.
7122*- put this FUNCTION DeclareViewsAndCursors in there.
7123DEFINE CLASS BPOicProcess_860 AS BPOCancel
7124 FUNCTION DeclareViewsAndCursors
7125 WITH THIS
7126 DIMENSION .aRatioViews[RATIO_VIEWS]
7127 .aRatioViews[RATIO_ZZOORDRH] = "Vzzoordrh_Ratio_Confirm"
7128 .aRatioViews[RATIO_ZZOORDRD] = "Vzzoordrd_Ratio_Confirm"
7129 .aRatioViews[RATIO_ZZOORDSP] = "Vzzoordsp_Ratio_Confirm"
7130 .aRatioViews[RATIO_ZZOOPENH] = "VtcOpenH_Ratio_Confirm"
7131 .aRatioViews[RATIO_ZZOOPEND] = "VtcOpenD_Ratio_Confirm"
7132 .aRatioViews[RATIO_ZZOORDWH] = "Vzzoordwh_Ratio_Confirm"
7133 .aRatioViews[RATIO_ZZOORDWD] = "Vzzoordwd_Ratio_Confirm"
7134 .aRatioViews[RATIO_ZZXNIBLR] = "Vzzxniblr_Ratio_Confirm"
7135
7136 DIMENSION .aRatioCursors[RATIO_CURSORS]
7137 .aRatioCursors[RATIO_ZZOORDOH] = "Vzzoordoh_Ratio_Confirm"
7138 .aRatioCursors[RATIO_ZZOORDOD] = "Vzzoordod_Ratio_Confirm"
7139 .aRatioCursors[RATIO_ZZOUNITS] = "Vzzounits_Ratio_Confirm"
7140
7141 *--- TechRec 1022069 12-Apr-2007 kpattabiraman ---
7142 IF TYPE("this.lUseFRMCode") = "L" AND this.lUseFRMCode
7143 lnRatioViews = ALEN(.aRatioViews)
7144 This.nRatioFrmChrg = lnRatioViews + 1
7145 DIMENSION .aRatioViews[This.nRatioFrmChrg]
7146
7147 .aRatioViews[This.nRatioFrmChrg] = This.cFrmChrgView
7148 ENDIF
7149 *=== TechRec 1022069 12-Apr-2007 kpattabiraman ===
7150
7151 *--- TR 1031103 2-May-2008 Goutam
7152 lnRatioViews = ALEN(.aRatioViews)
7153 This.nRatioChrgDtl = lnRatioViews + 1
7154 DIMENSION .aRatioViews[This.nRatioChrgDtl]
7155 .aRatioViews[This.nRatioChrgDtl] = This.cDtlChrgView
7156 *=== TR 1031103 2-May-2008 Goutam
7157 ENDWITH
7158
7159ENDDEFINE