'PRODANAL - analysis of Req'ns by ItemType, Branch and selected dates

external   dpath PrintReport() sch scw vloadif() progress() progtag() fgi bgi
external   vatrate remove() makeidx() fentrybox() chkdate() messbox() cpath
external   nr8 messboxwait() dly_pstgpath vunloadif() popuplist()

public     ptstr rel_date from_date chk_cb end_date strt_date $itemtype $title
public     $itemtitle $file

global     x SelectDates() p1 p2 p3 p4 p5 p6 #chk #chk1 SelectItemTypes()
global     ReturnToMenu() Prodmix()
'  PrepareTotalReport()

' external   briefmonth

' public F_tot R_tot S_tot T_tot W_tot P_tot
' public F_SC F_ST F_SA F_BC F_BA F_BT F_BV F_F F_O
' public R_SC R_ST R_SA R_BC R_BA R_BT R_BV R_F R_O
' public S_SC S_ST S_SA S_BC S_BA S_BT S_BV S_F S_O
' public T_SC T_ST T_SA T_BC T_BA T_BT T_BV T_F T_O
' public W_SC W_ST W_SA W_BC W_BA W_BT W_BV W_F W_O
' public P_SC P_ST P_SA P_BC P_BA P_BT P_BV P_F P_O

' global p1 p2 p3 p4 p5 p6


MAIN
single-step off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  end_date = today
  strt_date = today

  messbox(" Suggest running from Backup file for speed. Exit(y/n)? ",1,1,1)
  if ptstr = "y"
    ReturnToMenu()
  end if

  p1 = "prodanal.dfr"   ' p1 = report definition ("ord_stck.dfr")
  p2 = ""               ' p2 = title at top of choice popup ("LABEL")
  p3 = 1                ' p3 = printer to be used (1=HPIII_QC; 2=GEN_EPSN etc)
  p4 = 2                ' 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

  while true
    x=SelectDates()
    if x = -1
      ReturnToMenu()
    end if

    SelectItemTypes()

    Prodmix()

    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    file unload all
  end while
END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION SelectDates()
local mth ld
  while true
    x = fentrybox(" Start Date for Product Analysis - {Esc} to exit ",10,"##\/##\/####",strt_date)
    if x = 0
      strt_date = ptstr
      if chkdate(strt_date,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      end if
    elseif x = -1
      return (-1)
    end if
    exit while
  end while

  while true
    x = fentrybox(" End Date for Product Analysis ",10,"##\/##\/####",end_date)
    if x = 0
      end_date = ptstr
      if chkdate(end_date,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      end if
    end if
    exit while
  end while
END FUNCTION ' SelectDate()


FUNCTION SelectItemTypes()
local s1 s2 s3 s4 s5 s6 s7 s8
  while true
    vloadif(dpath|"carplist.vw")
    s1 = "˙˙Stock˙Carpet"
    s2 = "˙Stock˙Ancillary"
    s3 = "˙˙Stock˙Tiles"
    s4 = "˙Bespoke˙Carpet"
    s5 = "Bespoke˙Ancillary"
    s6 = "˙˙Bespoke˙Tiles"
    s7 = "˙˙Bespoke˙Vinyl"
    s8 = "˙˙˙˙Fitting"
    x = popuplist(8,33,16,s1&s2&s3&s4&s5&s6&s7&s8,"",1,0)
    if x = -1
      return (-1)
    end if
    if ptstr=s1
      $itemtype = "C"
      remove("stk_carp.dbf")
      $file      = "stk_carp.dbf"
      $itemtitle = ptstr

    elseif ptstr=s2
      $itemtype = "A"
      remove("stk_ancl.dbf")
      $file      = "stk_ancl.dbf"
      $itemtitle = ptstr

    elseif ptstr=s3
      $itemtype = "S"
      remove("stk_tile.dbf")
      $file      = "stk_tile.dbf"
      $itemtitle = ptstr

    elseif ptstr=s4
      $itemtype = "B"
      remove("bsp_carp.dbf")
      $file      = "bsp_carp.dbf"
      $itemtitle = ptstr

    elseif ptstr=s5
      $itemtype = "J"
      remove("bsp_ancl.dbf")
      $file      = "bsp_ancl.dbf"
      $itemtitle = ptstr

    elseif ptstr=s6
      $itemtype = "T"
      remove("bsp_tile.dbf")
      $file      = "bsp_tile.dbf"
      $itemtitle = ptstr

    elseif ptstr=s7
      $itemtype = "W"
      remove("bsp_vnyl.dbf")
      $file      = "bsp_vnyl.dbf"
      $itemtitle = ptstr

    elseif ptstr=s8
      $itemtype = "F"
      remove("fittings.dbf")
      $file      = "fittings.dbf"
      $itemtitle = ptstr

    end if
    progress(15,10," Please wait .... finding requisitions ",0)
' message "$itemtype is:"&str($itemtype)
' repaint on
' repaint
' single-step on
    order change key [Item_Type]
    data query execute "prodanl1.dfq" index "prodanl1.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
' [Item_Type] = $itemtype
' and
' NOT(deleted)
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
    if cerror
      messbox(" L180/ No requisitions for this itemtype ",0,0,1)
      return (1)
    end if

    data query execute "prodanl2.dfq" index "prodanl2.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
'   days([Date_Requisitioned]) <= days(end_date) and
'   days([Date_Requisitioned]) >= days(strt_date)
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
    if cerror
      messbox(" L190/ No requisitions for this itemtype and period ",0,0,1)
      return (1)
    end if
'     vunloadif("requsn.vws")
'     order change index "prodanl2.idx"

    data query execute "carplst3.dfq" index "prodanl3.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
'   [SalesAnalysis] = "P"
'   or
'   [SalesAnalysis] = "F"
'   or
'   [SalesAnalysis] = "R"
'   or
'   [SalesAnalysis] = "S"
'   or
'   [SalesAnalysis] = "W"
'   or
'   [SalesAnalysis] = "T"
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
    if cerror
      messbox(" L211/ No requisitions for this period ",0,0,1)
      return (1)
    end if
' x=mid([Product_Code],3,1)
' message "x is:"&str(x)

' remove all "ad-hoc" req'ns
    data query execute "carplst5.dfq" index "prodanl4.idx"
' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
' mid([Product_Code],3,1)<>"7"
' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
    if cerror
      messbox(" L211/ No requisitions for this period ",0,0,1)
      return (1)
    end if

    return (0)
  end while
END FUNCTION ' SelectItemTypes()


FUNCTION Prodmix()
  p1 = "prod_mix.dfr"   ' p1 = report definition ("ord_stck.dfr")
  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

  remove("ma")
  remove("prodanal.db")
  remove("prodanal.vws")
  remove("prodanal.dbf")
  data cross-tab execute "prodanal.dfw" Smart4 "prodanal"
  order sort now dictionary "prodanl5" fields "[prodanal]" ascending ' CURRENT month
  file export 3-dbase "[prodanal;Fulham;Trade;Putney;Raynes;Sheen;Whouse;Total]" file $file
  messboxwait(" DBF file stored as E:\programs\"|$file|" ",0,0,1)
END FUNCTION ' Prodmix()

