'PUT_ANCL - finds all Putney ancillaries and prints out lists for DG & shop

' new program to use GOODSOUT file

external  vloadif() dpath sch scw PrintReport() messbox() messboxwait()
external  progress() reqnpopup() chkdate()

public    ptstr $mth $invmth last_m_e first_m_e

global    x p1 p2 p3 p4 p5 p6 ChooseMonth()


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off

'(str,str,str,int,int,int)
  p2 = "PUTNEY"         ' 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 = 2                ' p6 = nr of copies

'enter month
  ChooseMonth()
  if x = -1
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    file unload all
    exit main
  end if
repaint on
repaint
single-step on

  progress(15,10," Searching for Putney Goods collected ",0)
  vloadif(dpath|"putancl1.vw")
  data query execute "putancl8.dfq" index "pa0"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch]="P"
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Ancillary req'ns still to invoice to Putney this month ",0,0,1)
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    file unload all
    exit main
  end if

  vloadif(dpath|"put_delv.vw")
  order change index "pa0.idx"
last_m_e
message "last_m_e) is:"&str(last_m_e)

  data query execute "putancl7.dfq" index "pa1"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch]="P"
'   and
'   [Item_Type]="A"
'   and
'   days([Date_Out])<=days(date2(last_m_e))
'   and
'   days([Date_Out])>0
'   and
'   [DueDate]=blank
'   and
'   [ReqnDueDate]=blank
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Ancillary req'ns still to invoice to Putney this month ",0,0,1)
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    file unload all
    exit main
  end if

  order sort now dictionary "pa2" fields "[Date_Out;Job_Nr]" ascending
  p1 = "putancl3.dfr"
  PrintReport(p1,p2,p3,p4,p5,p6)

  order sort now dictionary "pa3" fields "[Product_Code;Date_Out]" ascending
  p1 = "putancl4.dfr"
  PrintReport(p1,p2,p3,p4,p5,p6)

  messbox(" Continue and update REQUSN file with Payment Dates? (y/n) ",1,0,1)
  if ptstr == "y"
    data query execute "putancl2.dfq"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   replace [DueDate] = $mth
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    data query execute "putancl6.dfq"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   replace [ReqnDueDate] = $mth
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  else
    messboxwait(" GOODSOUT file MUST be updated before running program for next month ",0,0,1)
  end if

  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all

END MAIN


FUNCTION ChooseMonth()
local m1 m2 m3 m4 m5 ld
  m1 = upper(mid(addmonths(date1(today),-3),3,4))|"ÿ"|right(addmonths(date1(today),-3),4)
  m2 = upper(mid(addmonths(date1(today),-2),3,4))|"ÿ"|right(addmonths(date1(today),-2),4)
  m3 = upper(mid(addmonths(date1(today),-1),3,4))|"ÿ"|right(addmonths(date1(today),-1),4)
  m4 = upper(mid(addmonths(date1(today),0),3,4))|"ÿ"|right(addmonths(date1(today),0),4)
  m5 = format("Month to summarize","M20")
  screen print 15 31 15 1 m5
  x = reqnpopup(9,36,15,m1&m2&m3&m4,"",1,0,3,15,1)  'message "x is:"&str(x)
  if x = 0
    $mth = ptstr                       'message "$mth is:"&str($mth)
  end if
  first_m_e = "01 "|$mth               '
  for ld = 31 to 28 step -1
    last_m_e  = str(ld)|" "|$mth       'message "last_m_e is:"&str(last_m_e)
    if chkdate(last_m_e,1) = -1
      continue for
    else
      exit for
    end if
  end for
' message "last_m_e is:"&str(last_m_e)
' message "first_m_e is:"&str(first_m_e)
' message "days(last_m_e)) is:"&str(days(last_m_e))
' message "$invmth is:"&str($invmth)
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
END FUNCTION ' ChooseMonth()

