'WIP   - calculates & prints WIP & stock

external  dpath sch scw Background() vloadif() remove() PrintReport()
external  fentrybox() chkdate() messbox() progress() vunloadif()
external  messboxwait() makeidx() addidxrec() popuplist() X_path

public    ptstr sum_date ptval $wiptitle

global    WIP_Date() x ReturnToMenu() Stk_Bals() #total WIP_Bal() Stk_Ancls()
global    p1 p2 p3 p4 p5 p6 Bsp_Bals() BespokeSummaries() NrCopies() AgedStock()
global    CheckDocRef() CheckCtgRef() InvdUndeld1() InvdUndeld2()


' STOCK   "wip_1.vw" - "stk1.dfw" - file "wip_sum1" - "wip_1.dfr"
' ANCL    "wip_2.vw" - print "wip_2.dfr"
' BESPOKE   cross-tab "wip_3.dfw" - file "wip_sum3" - print "wip_3.dfr"
' WIP       cross-tab "wip_4.dfw" - file "wip_sum4" - print "wip_4.dfr"
' PT Gds    cross-tab "wip_4.dfw" - file "wip_sum5" - print "wip_5.dfr"
' PT Rqns   cross-tab "wip_5.dfw" - file "wip_sum6" - print "wip_6.dfr"


MAIN
'(str,str,str,int,int,int)
single-step off
' single-step oN
' message "Check Putney sections before using! - from 01/09/01"
  file unload all
  Background()
  remove(dpath|"WIP_SUM?.*")
  remove("WIPstk_A.*")

  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

  while true
    WIP_Date()
    if x = -1
      exit while
    end if

' Stock carpet balances
    messbox(" Print out Stock Balances? (y/n) ",1,0,1)
    if ptstr == "y"
      Stk_Bals()
    end if

' Stock ancillary balances
    messbox(" Print out Stock Ancillary Balances? (y/n) ",1,0,1)
    if ptstr == "y"
      Stk_Ancls()
    end if

' Bespoke carpet balances
    messbox(" Print out Bespoke Balances? (y/n) ",1,0,1)
    if ptstr == "y"
      Bsp_Bals()
    end if

' WIP balances
    messbox(" Print out Work-in-progress Balances? (y/n) ",1,0,1)
    if ptstr == "y"
      WIP_Bal()
    end if

' Inv'd but Undel'd - items in REQUSN
    messbox(" Inv'd but Undel'd - REQUSN items? (y/n) ",1,0,1)
    if ptstr == "y"
      InvdUndeld1()
    end if

' Inv'd but Undel'd - items in GOODSOUT
    messbox(" Inv'd but Undel'd - GOODSOUT items? (y/n) ",1,0,1)
    if ptstr == "y"
      InvdUndeld2()
    end if

    exit while
  end while

  ReturnToMenu()

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 WIP_Date()
  while true
    x = fentrybox(" Confirm Date for WIP Summary ",10,"##\/##\/####","")
    if x = 0
      sum_date = ptstr
      if chkdate(sum_date,1) = -1
        messbox(" Incorrect date - re-enter ",0,0,1)
        continue while
      end if
      exit while
    elseif x = -1
      return (-1)
    end if
  end while
END FUNCTION 'WIP_Date()


FUNCTION Stk_Ancls()
'ALL undeleted records in STK_ANCL.DB with positive [PhysicalBalance]
  progress(15,10," Please wait .... searching stock ancillaries ",0)
  vloadif(dpath|"WIP_2.vw")
  data query execute "WIP1.dfq" index "wip1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'  [PhysicalBalance]>0.1 and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Stock Ancillaries held ",0,0,1)
    return (1)
  end if
  data utilities recalc-all
  order sort now dictionary "wip_2.idx" fields "[Product_MRC]" ascending

  messbox(" Export for Crystal Reports? (y/n) ",1,0,1)
  if ptstr == "y"
'     remove(dpath|"X_stk_c.*")
'     order sort now dictionary "wip_2.idx" fields "[Product_MRC;Description_MRC;DateRecd]" ascending
'     data query execute "not_del.dfq" data-file dpath|"X_stk_c" fields "[Product_MRC|ChckMeas]"
    remove(X_path|"X_stk_a.*")
    data query execute "not_del.dfq" Smart4 X_path|"X_stk_a" fields\
   "[Product_Code;Product_MRC;PhysicalBalance;SM_List_Cuts;Balance_Value]"
  end if

'     file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;Location]" file "WIPstk_A"

  file export 3-dbase "[Product_Code;Product_MRC;PhysicalBalance;SM_List_Cuts;Balance_Value]" file "WIPstk_A"
  messboxwait(" 3-dbase file (WIPSTK_A) generated in E:\programs\ ",0,0,1)
  p6 = NrCopies()
  p1 = "WIP_2.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
  vunloadif("WIP_2.vw")
END FUNCTION ' Stk_Ancls()


FUNCTION WIP_Bal()
' ALL undeleted records in GOODSOUT.DB which have a [DOCREF] but for which
' the CUST_ORD record has NOT been invoiced EXCEPT [Item_Types]=C/S/V which
' have a [CTGTKT] reference. Does not include PUTNEY/TRADE either.
  vloadif(dpath|"WIP_4.vw")
  progress(15,10," Please wait  .... finding records ",0)
  data query execute "WIP_4a.dfq" index "WIP4a.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]=blank
'   and
'   left([JobNr],1)<>"T"
'   and not (deleted)
'   and
'   [Invoice_Total]>1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No WIP held ",0,0,1)
    return (1)
  end if
  remove("WIP_4b.idx")
  makeidx("goodsout","WIP_4b.idx","0",1)
  data goto record first
  while record <= records
    case [Itemtype]
      when "C"                         'Stock Carpet
        CheckCtgRef()
      when "A"                         'Stock Ancillaries
        CheckDocRef()
      when "S"                         'Stock Tiles
        CheckCtgRef()
      when "V"                         'Stock Vinyl
        CheckCtgRef()
      when "B"                         'Bespoke Carpet
        CheckDocRef()
      when "J"                         'Bespoke Ancillaries
        CheckDocRef()
      when "T"                         'Bespoke Tiles
        CheckDocRef()
      when "W"                         'Bespoke Vinyl
        CheckDocRef()
      when "F"                         'Labour
        CheckDocRef()
      when "O"                         'Other
        CheckDocRef()
    end case
    data goto record next
  end while
  order change index "WIP_4b.idx"

  messbox(" Print Full List of Work-In-Progress? (y/n) ",1,0,1)
  if ptstr == "y"
    order sort now dictionary "WIP.idx" fields "[Job_Nr]" ascending
    p1 = "WIP4FULL.dfr"        ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
    order change physical
  else
    data cross-tab execute "wip_4.dfw" Smart4 dpath|"wip_sum4"
    order sort now dictionary "WIP.idx" fields "[wip1]" ascending
    p6 = NrCopies()
    p1 = "WIP_4.dfr"        ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
    order change physical
    vloadif(dpath|"WIP_zero.vw")
    order change index "wip.idx"
    data query execute "wip_zero.dfq" index "wip_zero.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [Balance_Due]<.1                                                   ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
    else
      p1 = "WIP_ZERO.dfr"
      PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
    end if
    vunloadif("WIP_zero.vw")
  end if

  messbox(" Print unprocessed labour? (y/n) ",1,1,1)
  if ptstr=="y"
    vloadif(dpath|"WIP_4a.vw")
    order change index "WIP4a.idx"
    data query execute "WIP_5.dfq" index "WIP_5.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Itemtype]="F"
' and [Document]=blank and
' days([Date_Out])<=days(sum_date)
' and
' [Inv_Nr]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No unprocessed labour for Work-in-progress ",0,0,1)
      return (1)
    end if
    order sort now dictionary "WIP_5a.idx" fields "[Job_Nr]" ascending
    p6 = NrCopies()
    p1 = "WIP_5.dfr"        ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)
  end if
END FUNCTION ' WIP_Bal()


FUNCTION CheckDocRef()
  if [Document]<>blank
    x = addidxrec("WIP_4b.idx",precord,7)  'message "x is:"&str(x)
  end if
END FUNCTION ' CheckDocRef()


FUNCTION CheckCtgRef()
  if [CPL_Ref]<>blank
    x = addidxrec("WIP_4b.idx",precord,7)  'message "x is:"&str(x)
  end if
END FUNCTION ' CheckCtgRef()
' file export smart row-format "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value]" file "WIP_SUM1"


FUNCTION InvdUndeld1() 'invoiced out but NOT delivered out (i.e. in STOCK/WIP)
                       'REQUSN file records with [Quant_OS]
  file unload all
  vloadif(dpath|"invdund1.vw")
  progress(15,10," Please wait  .... finding records ",0)
  data query execute "invdund1.dfq" index "invdund1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Invoice_Date])<=days(sum_date)
'   and not (deleted)
'   and [Quant_OS]>.1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Inv'd but Undeliv'd records in REQUSN ",0,0,1)
    return (1)
  end if
  data query execute "chk_wip8.dfq" index "WIP8.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Document]=blank
'   and
'   [Inv_Nr]<>blank
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
'     messboxwait(" No P & T Goodsout records to process ",0,0,1)
    data query execute "onlyone.dfq" index "WIP8N.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   record = 1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    p6 = NrCopies()
    p1 = "WIP_5N.dfr"
    PrintReport(p1,p2,p3,p4,p5,p6)
    return (1)
  end if

  messbox(" Select only Goodsout items with unpaid balances? (y/n) ",1,0,1)
  if ptstr == "y"
    data query execute "posbal.dfq" index "WIP8a.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Balance_Due]>.01
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  end if

  data cross-tab execute "wip_4.dfr" Smart4 dpath|"wip_sum5"
  order sort now dictionary "WIP.idx" fields "[wip1]" ascending
  p6 = NrCopies()
'   p1 = "WIP_5.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       '
END FUNCTION ' InvdUndeld1()


FUNCTION InvdUndeld2()   'invoiced out but NOT delivered out (i.e. in STOCK/WIP)
                         'GOODSOUT file
  file unload all
  vloadif(dpath|"chk_wip3.vw")
  progress(15,10," Please wait  .... finding records ",0)
  data query execute "chk_wip9.dfq" index "WIP9.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]<>blank
'   and
'   asc(left([Inv_Nr],1)) <= 57 and asc(left([Inv_Nr],1)) >= 48
'   and
'   not (deleted)
'   and
'   days([Date_Requisitioned])>days("25/01/98")
'   and
'   [Cost_OS]>.01
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
'     messboxwait(" No P & T Requsn records to process ",0,0,1)
    data query execute "onlyone.dfq" index "WIP9N.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   record = 1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    p6 = NrCopies()
    p1 = "WIP_6N.dfr"
    PrintReport(p1,p2,p3,p4,p5,p6)
    return (1)
  end if
  data cross-tab execute "wip_5.dfw" Smart4 dpath|"wip_sum6"
  order sort now dictionary "wip6.idx" fields "[wip1]" ascending
  p6 = NrCopies()
  p1 = "WIP_6.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       '
END FUNCTION ' InvdUndeld2()


FUNCTION NrCopies()
  while true
    x = fentrybox(" Enter Nr of copies (max=3) ",1,"#","1")
    if x = -1
      continue while
    end if
    ptval = value(ptstr)
    if ptval > 3
      continue while
    else
      return (ptval)
    end if
  end while
END FUNCTION ' NrCopies()


FUNCTION Bsp_Bals()
' ALL undeleted records in STK_BESP.DB with positive [PhysicalBalance] for which
' the CUST_ORD record has NOT been invoiced. Does not include PUTNEY/TRADE either.

  progress(15,10," Please wait .... searching bespoke list ",0)
  remove(dpath|"bespstk?.db")
  remove(dpath|"bespstk?.vws")
  vloadif(dpath|"WIP_3.vw")
  data query execute "chk_wip7.dfq" Smart4 dpath|"bespstk1" fields\
 "[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;Product_Code;Product_MRC;Description_MRC;Location;RollNr]"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Balance_Value]>.01
'   and
'   not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Bespoke items in stock ",0,0,1)
    return (1)
  end if
  data utilities recalc-all

  vloadif(dpath|"bespstk3.vw") ' show
  messbox(" List Bespoke Carpets in Stock but NOT invoiced? (y/n) ",1,0,1)
  if ptstr == "y"
'     PrintInStockButInvd()
    data query execute "chk_wip3.dfq" index "WIP_invd.idx" ' find NOT inv'd to customer
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Inv_Nr]<>blank
' and
' [PhysicalBalance]>1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No invoiced Bespoke items in stock ",0,0,1)
      return (1)
    end if
    BespokeSummaries()
  end if

  vloadif(dpath|"bespstk3.vw") ' show
  order change physical
  data query execute "chk_wip2.dfq" index "WIP2.idx" ' find NOT inv'd to customer
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]=blank
'   and
'   [Invoice_Total]>1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Bespoke items in stock ",0,0,1)
    return (1)
  end if
  messbox(" Print Full List of Bespoke Carpets? (y/n) ",1,0,1)
  if ptstr == "y"
    BespokeSummaries()
  end if

  messbox(" Export for Crystal Reports? (y/n) ",1,0,1)
  if ptstr == "y"
    remove(X_path|"X_bsp_c.*")
    data query execute "not_del.dfq" Smart4 X_path|"X_bsp_c" fields\
   "[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;Product_Code;Product_MRC;Description_MRC;Location;RollNr]"
  end if

  vloadif(dpath|"bespstk3.vw") ' show
  order change index "WIP2.idx"
  data cross-tab execute "wip_3.dfw" Smart4 dpath|"wip_sum3"
  p6 = NrCopies()
  p1 = "WIP_3.dfr"        ' p1 = report definition ("ord_stck.dfr")

  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
  vunloadif("stk_sum3.vw")
  vunloadif("WIP_3.vw")
END FUNCTION ' Bsp_Bals()


FUNCTION BespokeSummaries()
'in "bespstk3.vw" index "WIP2.idx"
  order sort now dictionary "WIP_3f.idx" fields "[JobNr]" ascending
  p6 = NrCopies()
  p1 = "WIP_3F.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
  return (0)
END FUNCTION ' BespokeSummaries()


FUNCTION Stk_Bals()
'ALL undeleted records in STK_CARP.DB with positive [PhysicalBalance]
  progress(15,10," Please wait .... searching stock list ",0)
  vloadif(dpath|"WIP_1.vw")
  data query execute "WIP1.dfq" index "wip0.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'  [PhysicalBalance]>0.1 and not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Stock Carpets held ",0,0,1)
    return (1)
  end if
  data utilities recalc-all

  data query execute "liststck.dfq" index "wip1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Item_Type]="C" or [Item_Type]="S" or [Item_Type]="V"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No Stock Carpets held ",0,0,1)
    return (1)
  end if

  messbox(" Print Full List of Stock Carpets? (y/n) ",1,0,1)
  if ptstr == "y"
    x = popuplist(5,53,13,"ByÿItemtype/ProductCode ByÿAge","",1,0)
    if ptstr = "ByÿAge"
      AgedStock()
    else
      order sort now dictionary "wip_1a.idx" fields "[Item_Type;Product_MRC;Description_MRC;DateRecd]" ascending
      p6 = NrCopies()
      p1 = "WIP_1F.dfr"        ' p1 = report definition ("ord_stck.dfr")
      remove("WIPstk_c.*")
      file export 3-dbase "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;Location]" file "WIPstk_c"
'       messboxwait(" 3-dbase file (WIPSTK_C) generated in E:\programs\ ",0,0,1)
    end if
  end if
  messbox(" Export for Crystal Reports? (y/n) ",1,0,1)
  if ptstr == "y"
    remove(X_path|"X_stk_c.*")
    order sort now dictionary "wip_2.idx" fields "[Product_MRC;Description_MRC;DateRecd]" ascending
    data query execute "not_del.dfq" Smart4 X_path|"X_stk_c" fields "[Product_MRC|ChckMeas]"
'    "[Product_Code;Description_MRC;Product_MRC;RollNr;Width;Unit_Cost;PhysicalBalance;Balance_Value;Location]"
'    "[JobNr;StockOrder;PhysicalBalance;Balance_Value;Width;Unit_Cost;DateRecd;Item_Type;Product_Code;Product_MRC;Description_MRC;Location;RollNr]"
  end if

  vloadif(dpath|"WIP_1.vw")
  order change index "wip1.idx"
  data cross-tab execute "wip_8.dfw" Smart4 dpath|"wip_sum1"
  p6 = NrCopies()
  p1 = "WIP_1.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report
  vunloadif("WIP_1.vw")
  vunloadif("wip_sum1.vws")
END FUNCTION ' Stk_Bals()


FUNCTION AgedStock()
  order change index "wip1.idx"
' message "records is:"&str(records)
  data query execute "agedstk1.dfq" index "agedstk1.idx" ' over 36 mths
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-1095)                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
message "Special for DG"
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock over 36 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk2.dfq" index "agedstk2.idx" ' 30/36 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-913) and days([DateRecd])>=(days(sum_date)-1095)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock between 30 and 36 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk3.dfq" index "agedstk3.idx" ' 24/30 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-730) and days([DateRecd])>=(days(sum_date)-913)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock between 24 and 30 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk4.dfq" index "agedstk4.idx" ' 18/24 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-548) and days([DateRecd])>=(days(sum_date)-730)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock between 18 and 24 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk5.dfq" index "agedstk5.idx" ' 12/18 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-365) and days([DateRecd])>=(days(sum_date)-548)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock between 12 and 18 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk6.dfq" index "agedstk6.idx" '  6/12 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])<(days(sum_date)-183) and days([DateRecd])>=(days(sum_date)-365)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock between 6 and 12 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

  order change index "wip1.idx"
  data query execute "agedstk7.dfq" index "agedstk7.idx" ' under 6 mths old
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ days([DateRecd])>=(days(sum_date)-183)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' message "records is:"&str(records)
  order sort now dictionary "wip_age.idx" fields "[DateRecd]" ascending
  $wiptitle = "Stock upto 6 months old"
  p6 = 1
  p1 = "WIP_1AGE.dfr"        ' p1 = report definition ("ord_stck.dfr")
  PrintReport(p1,p2,p3,p4,p5,p6)       ' basic WIP report

END FUNCTION ' AgedStock()

' external   X_path _SWIP_Crystal() Xreppath
'   remove(X_path|"X_mth_o.*")
'
'   vunloadif("X_inv_a.vws")
'   ClearHardSpaces()
'   data query execute "not_del.dfq" data-file X_path|"X_mth_o" fields\
'   "[Var_Nr;Date;CustOrd_Name;Amount_Gross;shop;Date_To;Nr_Orders;Avg_Order;Tot_Order_Net;Tot_Order_Gross]"
'   _SWIP_Crystal(Xreppath|"$inv_1","P",0,1,"")
'   _SWIP_Crystal(Xreppath|"$inv_1","EP",0,1,invpath|$nextinvnr|".pdf")
' ' '
