I'm writing a calculation that finds all of today's records of SOLines, and gives me a summary of how many of each item was sold today. I've gotten the list of records sorted by ItemNum, but am stumped on how to loop through each ItemNum to find its 'like' ItemNums and sum its quantities, then move on to the next ItemNum, and so on through the last ItemNum. I will then Calculate the AvgSales/Week for each ItemNum, subtract the SumQty ordered today for that ItemNum, and the result will be the QtyToPurch so that my inventory on that item is brought back up to proper stocking level.
My critical need (I can do the rest) is how to loop through and sum up the quantities for 'like' ItemNums and then discard that ItemNum, repeat the procedure for the next set of 'like' ItemNums, etc.
Any advice would be much appreciated. Here is the code and some notes so far ...
var vRSp as int var vToday as date var vTime as time
var vYesterday as date var vSOTime as time var vSODate as date var vCutoffTime as string
var vItemNum as string var vItemQty as string
var vTot as int var vLoop as int var vSONum as string var vBO as string
OpenSlate() CLS() CloseSlate()
vToday = @ServerDate() vTime = @ServerTime() writeln(vTime + " vTime")
vYesterday = @date - 1
vCutoffTime = "16:00" vCutoffTime = @TT(vCutoffTime) writeln(vCutoffTime + " vCutoffTime")
vRSp = @XResultSetSearch(@FN, "Orders!SOLines", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "!SODate=" + vToday; "!SODate=" + vYesterday) If vRSp > -1 { // this section will discard Backorders and Orders placed before 4pm yesterday
vTot = @XResultSetTotal(vRSp) For vLoop = 1 to vTot XResultSetCurrentPosition(vRSp, vLoop) vSONum = @XResultSetValue(vRSp, "SONum") vSODate = @XResultSetValue(vRSp, "SODate") vSOTime = @XResultSetValue(vRSp, "SOTime") vBO = @ContainsStringArray(vSONum, "A;B;C;D;E", 0) If (vBO <> "") or ((vSODate = vYesterday) and (vSOTime < vCutofftime)) { XResultSetRemoveRecord(vRSp) vLoop = vLoop - 1 vTot = vTot - 1 } Next
// this section will sort the SOLines records by ItemNum and give me a Writeln of the resulting list XResultSetSort(vRSp, "ItemNum:-1")
vTot = @XResultSetTotal(vRSp)
For vLoop = 1 to vTot XResultSetCurrentPosition(vRSp, vLoop) vItemNum = @XResultSetValue(vRSp, "ItemNum") vItemQty = @XResultSetValue(vRSp, "ItemQtyShadow") vSODate = @XResultSetValue(vRSp, "SODate") vSOTime = @XResultSetValue(vRSp, "SOTime") vItemQty = @TN(vItemQty) WriteLn(vSODate + " - " + vSOTime + " - " + vItemNum + " - " + vItemQty)
Next
// this section is where I need to calc the Sum of the ItemQty's for each ItemNum in the vRSp list
/* below is figuring out the following: 1) what is the sumQty of each ItemNum in vRSp ? a) start with first ItemNum ... vItemQty = @TN(vRSp,"ItemQty") 2) what is QSPW for this ItemNum? 3) what is the QtyAvailToSell for this ItemNum? 4) QSPW - QATS = QTP AvgQty/Week - QtyAvailToSell = QtyToPurchase of this ItemNum
5) write this QTP to writeln 6) then NEXT to loop to the next ItemNum
*/
|