'FRANINV1 - create report of franchise invoice details

external   dpath vloadif() userid sch scw cpath vunloadif() popuplist()
external   reqnpopup() messbox() fgp bgp messboxwait() nr6 nr8 chkdate()
external   progress() vatrate fentrybox() remove() makeidx() PrintReport()

public     ptstr $paymth $branch $shop #markup_S #markup_A #markup_B $lastmth
public     #tot_A #tot_B #total #vat #vattot $prevmth $current #prec #ancl
public     #netsales #mgt #mkt monthend fullmonth briefmonth enddate $shop_name
public     #markup #invcost  first_m_e last_m_e $mth_tbi $invmth #net_ancl
public     $currentmth $duemth $invdate

global     ReturnToMenu() x FindBranch() $shoplist Allocations() BespokeRcvd()
global     CalcMonths() Summary() $report $itemtype Put_ancl()
global     Sal_Rep() Date() Report() p1 p2 p3 p4 p5 p6 i


MAIN
  single-step off
'   quiet off
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  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 = 2                ' p6 = nr of copies

  $shoplist = "Clapham Fulham Putney Raynes Sheen"

  x = FindBranch()                   ' find branch & active month
'   if x = -1
'     exit while
'   elseif x = 1
'     continue while
'   end if

  x=Put_ancl()
  while true
    x = fentrybox(" Enter total of Ancillaries supplied (Mark Up inc.) ",8,nr8,"")
    if x = -1
      continue while
    end if
    #ancl = val(ptstr)
    messbox(" Confirm Ancillaries Supplied is"&currency(#ancl)|"? (y/n) ",1,1,1)
    if ptstr == "Y"
      exit while
    else
      continue while
    end if
  end while
  #net_ancl = #ancl/(1+#markup_A)     'message "#invcost) is:"&str(#invcost)
  messboxwait(" Net cost of Ancillaries is"&str(#net_ancl),0,0,1)


'   Sal_Rep()
'   while true
'     x = fentrybox(" Enter NET sales for month ",8,nr8,"")
'     if x = -1
'       continue while
'     end if
'     #netsales = val(ptstr)
'     messbox(" Confirm Net Sales are"&currency(#netsales)|"? (y/n) ",1,1,1)
'     if ptstr == "Y"
'       exit while
'     else
'       continue while
'     end if
'   end while
   #netsales=0

  while true
    progress(fgp,bgp," Preparing files for Franchise reports - Stock ",0)
    Allocations()

    progress(fgp,bgp," Preparing files for Franchise reports - Bespoke ",0)
    BespokeRcvd()
' message "#tot_B is:"&str(#tot_B)
' vloadif(dpath|"franinvB.vw")         'based on GDS_RCVD.DB
    Summary()
    exit while
  end while

  ReturnToMenu()

END MAIN


FUNCTION FindBranch()
local m1 m2 m3 m4 m5
  while true
    while true
      x = fentrybox(" Date to make franchise invoice upto ",10,"##\/##\/####",today)
      if x = 0
        $mth_tbi=ptstr
        if chkdate($mth_tbi,1) = -1
          messbox(" Incorrect date - re-enter ",0,0,1)
          continue while
        else
          exit while
        end if
      end if
    end while

'message "$mth_tbi is:"&str($mth_tbi)
    $paymth=addmonths(date1($mth_tbi),1)     'message "L117-$paymth is:"&str($paymth)
    $paymth=upper(mid($paymth,4,3))|"ÿ"|right($paymth,4) ' message "$paymth is:"&str($paymth)
    $invdate=addmonths(date1($mth_tbi),0)     'message "L117-$paymth is:"&str($paymth)
    $invmth=upper(mid($invdate,4,3))|"ÿ"|right($invdate,4) ' message "$invmth is:"&str($invmth)
    $invdate="I"|upper(mid($invdate,4,3))|right($invdate,2) ' message "$invdate is:"&str($invdate)
    $duemth=left($paymth,3)|"ÿ"|right($paymth,2) ' message "$duemth is:"&str($duemth)
    $shop = "Putney"
    $branch = "P"

    CalcMonths()
    screen clear box 1 1 sch scw 0 0 no-border
    x = messbox("ÿAllocations for"&$current&"- Invoices to be paid in"&$paymth|"?(y/n) ",1,1,1)
    if ptstr = "n"
      continue while
    end if

    while true
      while true
        x = fentrybox(" Enter % Mark-Up for STOCK ",4,"",5)
        if x = 0
          if ptstr = ""
            continue while
          end if
          #markup_S = value(ptstr)
          exit while
        elseif x = -1
          continue while
        end if
      end while

      while true
        x = fentrybox(" Enter % Mark-Up for ANCILLARIES ",4,"",10)
        if x = 0
          if ptstr = ""
            continue while
          end if
          #markup_A = value(ptstr)
          exit while
        elseif x = -1
          continue while
        end if
      end while

      while true
        x = fentrybox(" Enter % Mark-Up for BESPOKE ",4,"",0)
        if x = 0
          if ptstr = ""
            continue while
          end if
          #markup_B = value(ptstr)
          exit while
        elseif x = -1
          continue while
        end if
      end while
      messbox("ÿ"|str(#markup_S)|"% STOCK - "&str(#markup_A)|"% ANCL - "&str(#markup_B)|"% BESPOKE ? (y/n) ",1,1,1)
      if ptstr == "y"
        return (0)
      end if
    end while
  end while
END FUNCTION ' FindBranch()


FUNCTION CalcMonths()
local ld
  $current=upper(mid(date3($mth_tbi),4,3))|"ÿ"|right($mth_tbi,4)
  $currentmth=upper(mid(date3($mth_tbi),4,3))|"ÿ"|right($mth_tbi,2)
' message "$currentmth (s.b. MMM YY) is:"&str($currentmth)

  $lastmth = upper(mid(addmonths(date1("01/"|left($current,3)|"/"|right($current,2)),-1),4,3))|"ÿ"|upper(right(addmonths(date1("01/"|left($current,3)|"/"|right($current,2)),0),2))
' message "$lastmth is:"&str($lastmth)

  $prevmth = upper(mid(addmonths(date1("01/"|left($current,3)|"/"|right($current,2)),-2),4,3))|"ÿ"|upper(right(addmonths(date1("01/"|left($current,3)|"/"|right($current,2)),-1),2))
' message "$prevmth is:"&str($prevmth)
  first_m_e = "01 "|$paymth               '
  for ld = 31 to 28 step -1
    last_m_e  = str(ld)|" "|$paymth       '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
  last_m_e = $mth_tbi
' message "last_m_e (s.b. in dd/mm/yyyy) is:"&str(last_m_e)
' message "$invmth (s.b. MMM YY format) is:"&str($invmth)
END FUNCTION 'CalcMonths()


FUNCTION Allocations()       'query REQUSN file for Branch & Allocation Date
  vloadif(dpath|"products.vws")
  vloadif(dpath|"franinvA.vw")
  order change key "[Branch]"
  data query execute "franinv0.dfq" index "franinv0.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch] = $branch
'    and
'   not deleted
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No Stock Allocations for"&$shop&"in"&$invmth,0,0,1)
    #tot_A = 0
    return (1)
  end if
  data query execute "franinvA.dfq" index "franinvA.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Item_Type]="C" or [Item_Type]="S" or [Item_Type]="V"
'    and
'   left([DueDate],1) <> "I"
'    and
'   len([DueDate]) <> 0
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' old QUERY was:  [Branch] = $branch and [DueDate] = $paymth
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No Stock Allocations for"&$shop&"in"&$invmth,0,0,1)
    #tot_A = 0
    return (1)
  end if
' message "$currentmth (needs tb MMM YY) is:"&str($currentmth)
message "$lastmth (needs tb MMM YY) is:"&str($lastmth)
  data query execute "franinvC.dfq" index "franinvC.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [DueDate] = $lastmth
'    or
'   [DueDate] = $currentmth
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No Stock Allocations for"&$shop&"in"&$invmth,0,0,1)
    #tot_A = 0
    return (1)
  end if

'check that reqn's only for jobs BEFORE P20000
  data query execute "putancl9.dfq" index "pa1a"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' val(right([Job_Nr],5))<20000
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  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
    messbox(" No Stock Allocations for"&$shop&"in"&$invmth,0,0,1)
    repaint off
    file unload all
    exit main
  end if

' price up
  #tot_A = 0
  for i = 1 to records
    $itemtype = [Item_Type]            'message "$itemtype is:"&str($itemtype)
    #markup = case $itemtype ("C",#markup_S)("A",#markup_A)("B",#markup_B)("J",#markup_B)("S",#markup_S)("T",#markup_B)("V",#markup_S)("W",#markup_B)
    #markup = #markup/100              'message "#markup) is:"&str(#markup)
'     #invcost = round([Cost]*(1+#markup),2)      'message "#invcost) is:"&str(#invcost)
    #invcost = round([Cost],2)      'message "#invcost) is:"&str(#invcost)
    lock-record
      [DueDate]             = $invdate
      [Date_Status_Changed] = today
      [Created/Changed_By]  = userid
      [Retail]              = #invcost
    write-record
    #tot_A = #tot_A + #invcost
    data goto record next
  end for
'message "#tot_A is:"&str(#tot_A)
  messboxwait(" Net cost for Stock Allocations is"&str(#tot_A),0,0,1)
  #tot_A = #tot_A*(1+#markup)     'message "#invcost) is:"&str(#invcost)

  while true
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    p1 = "franinvA.dfr"    ' p1 = report definition ("ord_stck.dfr")
    x = PrintReport(p1,p2,p3,p4,p5,p6)
    vunloadif("franinvA.vw")
    messbox(" Did Stock Allocation reports print correctly? (y/n) ",1,1,1)
    if ptstr == "y"
      exit while
    end if
  end while
END FUNCTION 'Allocations()


FUNCTION BespokeRcvd()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  vloadif(dpath|"products.vws")
  vloadif(dpath|"franinvB.vw")         'based on GDS_RCVD.DB
  order change key "[Branch]"
  data query execute "franinv0.dfq" index "franinv0.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Branch] = $branch
'    and
'   not deleted
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No Bespoke receipts for"&$shop&"in"&$paymth,0,0,1)
    #tot_A = 0
    return (1)
  end if

  data query execute "franinvB.dfq" index "franinvB.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Item_Type]="B" or [Item_Type]="T" or [Item_Type]="J" or [Item_Type]="O" or [Item_Type]="W"
' and
' left([DueDate],1) <> "I"
' and
' len([DueDate]) <> 0
' and
' not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' old QUERY was:  [Branch] = $branch and left([DueDate],1) <> "I"         ³
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No Bespoke receipts for"&$shop&"in"&$paymth,0,0,1)
    return (1)
  end if
' message "$currentmth (sb MMM YY) is:"&str($currentmth)
' message "$duemth (sb MMM YY) is:"&str($duemth)
  data query execute "franinvD.dfq" index "franinvD.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [DueDate] = $currentmth
'    or
'   [DueDate] = $duemth
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    messbox(" No receipts of Bespoke items for"&$shop&"in"&$paymth,0,0,1)
    return (1)
  end if

'check that reqn's only for jobs BEFORE P20000
  data query execute "putancla.dfq" index "pa1a"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' val(mid([Order_Nr],2,5))<20000
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  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
    messbox(" No receipts of Bespoke items for"&$shop&"in"&$paymth,0,0,1)
    repaint off
    file unload all
    exit main
  end if

  while true
    screen clear box 1 1 sch scw 0 0 no-border
    repaint off
    p1 = "franinvB.dfr" ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)
    p6 = 2
    p1 = "franinvM.dfr" ' p1 = report definition ("ord_stck.dfr")
    PrintReport(p1,p2,p3,p4,p5,p6)
    p6 = 2
    messbox(" Did Bespoke reports print correctly? (y/n) ",1,1,1)
    if ptstr == "y"
      exit while
    end if
  end while

  #tot_B = filesum([Invoice_Cost])     'message "#tot_B is:"&str(#tot_B)
  for i = 1 to records
    lock-record
      [DueDate]     = $invdate
      [Last_Update] = today
      [Updated_By]  = userid
    write-record
    data goto record next
  end for
END FUNCTION 'BespokeRcvd()


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 Summary()
  #mgt   = #netsales*0.075
  #mkt   = #netsales*0.015
  #total = #tot_A + #tot_B + #ancl + #mgt + #mkt
  #vat = #total*vatrate/100              ' message "#vat is:"&str(#vat)
  #vattot = #total + #vat                ' message "#vattot is:"&str(#vattot)

  $report = "franrep"|$branch|".dfr"   ' message "$report is:"&str($report)
  x = remove("printme.idx")
  data query execute "onlyone.dfq" index "printme.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   record = 1
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  p1 = $report        ' p1 = report definition ("ord_stck.dfr")
  messboxwait(" Insert Headed paper in printer for invoice ",0,0,1)
  x = PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION 'Summary()


FUNCTION Sal_Rep()
  while true
    vloadif(dpath|"ord_rep1.vw")
    $shop_name = "Putney"
    $shop = "P"
    x = Date()
    if x = -1
      continue while
    end if
    x = Report()
    if x = 0
      exit while
    end if
  end while
  $shop = "Putney"
END FUNCTION ' Sal_Rep()


FUNCTION Date()
local y ld
  while true
    monthend = right(date2(today),7) 'message "monthend is:"&str(monthend)
    x = fentrybox(" Confirm month for"&$shop_name|"'s report ",7,"*2#\/*4#",monthend)
    if x = 0
      monthend = ptstr
      fullmonth = "01/"|ptstr
      x = chkdate(fullmonth,1)
      if x = 0
        y = len(date3(fullmonth))
        y = y - 8
        briefmonth = monthname(fullmonth)|" '"|right(fullmonth,2)
        exit while
      else
        messbox(" Incorrect date - re-enter ",0,0,1)
      end if
    else
      return (-1)
    end if
    briefmonth = left(date3(fullmonth),3)
  end while
  for ld = 31 to 28 step -1
    enddate = str(ld)|"/"|monthend         'message "last_m_e is:"&str(last_m_e)
    if chkdate(enddate,1) = -1
      continue for
    else
      exit for
    end if
  end for
' message "enddate is:"&date3(enddate)
END FUNCTION 'Date()


FUNCTION Report()
  order change key "[Var_Nr]"
  progress(fgp,bgp," Creating report for"&$shop_name|" ... please wait ",0)
  data query execute "shops.dfq" INDEX "first.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³  left[Var_Nr,1]=$shop                                          ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Sales this month at"&$shop_name|" ",0,0,1)
    return (1)
  end if
  data query execute "sal_rep.dfq" INDEX "second.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' º   right(date2([Date]),5) ! monthend                       º
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No Sales this month at"&$shop_name|" ",0,0,1)
    return (1)
  end if
  order sort execute "sal_rep.dfs" INDEX "sal_rep"
  screen clear box 1 1 sch scw 0 0 no-border
'   p1 = "sal_rep1.dfr"
  p1 = "ord_rep1.dfr"
  PrintReport(p1,p2,p3,p4,p5,p6)
END FUNCTION ' Report()


FUNCTION Put_ancl()
  progress(15,10," Searching for Putney requisitions ",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

  progress(15,10," Searching for Putney requisitions still uninvoiced ",0)
  vloadif(dpath|"put_delv.vw")
  order change index "pa0.idx"

  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

'check that reqn's only for jobs BEFORE P20000
  data query execute "putancl9.dfq" index "pa1a"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' val(right([Job_Nr],5))<20000
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  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)

message "#markup_A is:"&str(#markup_A)
  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] = $invmth
' ' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

    data query execute "putancl6.dfq"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   replace [ReqnDueDate] = $invdate
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  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 FUNCTION ' Put_ancl()

