'GDS2PROC - list all items in GDS_RCVD received in given month but not cleared
'           down from supplier's invoice via SUPP_INV.RF3

external  dpath Background() chkdate() fentrybox() messbox() vloadif()
external  messboxwait() PrintReport() vunloadif()

public    ptstr from_date to_date repdate

global    x SelectDate()


MAIN
local p1 p2 p3 p4 p5 p6
single-step off

  p2 = ""               ' p2 = title at top of choice popup ("LABEL")
  p3 = 1                ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p4 = 1                ' p4 = printer port to use (1,2 etc - network set to use 2=LASER; 3=LABEL)
  p5 = 1                ' p5 = choose VIEW/PRINT 1=PRINT; 2=VIEW; 3=CHOOSE
  p6 = 1                ' p6 = nr of copies

  file unload all
  Background()

  SelectDate()

'find unposted records
  vloadif(dpath|"gds_rcvd.vws")
  data query execute "gds2proc.dfq" index "proc1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([Date_Received])<=days(to_date) and
' ³ days([Date_Received])>=days(from_date) and not deleted
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No unprocessed Goods Received for month to"&date2(to_date)|" ",0,0,1)
  else                              'print schedule
    order sort now dictionary "proc2.idx" fields "[Supplier_Code]" ascending
    p1 = "gds2proc.dfr"   ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)
    vunloadif("gds_rcvd.vws")
    vloadif(dpath|"gds2prca.vw")
    order change index "proc1.idx"
    order sort now dictionary "proc2.idx" fields "[Item_Type;Product_Supplier]" ascending
    p1 = "gds2prca.dfr"   ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)
  end if
  file unload all
END MAIN


FUNCTION SelectDate()
local mth ld
  while true
    x = fentrybox(" Unprocessed Goods upto (s.b. end of prev mth) ",10,"##\/##\/####",today)
    if x = 0
      to_date = ptstr
      if chkdate(to_date,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      else
'         return (0)
        exit while
      end if
    end if
  end while

' x=mid(addmonths(to_date,0),4,2)
' message "x) is:"&str(x)
' x=right(addmonths(to_date,0),2) '
' message "x) is:"&str(x)
  from_date = "01/"|mid(addmonths(to_date,0),4,2)|"/"|right(addmonths(to_date,0),4) 'message "from_date is:"&str(from_date)
  mth = right(date2(from_date),7)     'message "mth is:"&str(mth)
  for ld = 31 to 28 step -1
    to_date = str(ld)|"/"|mth         'message "last_m_e is:"&str(last_m_e)
    if chkdate(to_date,1) = -1
      continue for
    else
      exit for
    end if
  end for
END FUNCTION ' SelectDate()
