'FRAN_OS - version of ORD_STAT for franchises

external   fentrybox() messbox() vloadif() vunloadif() dpath scr shopmask
external   sch scw progress() fgp bgp messline() wraptext() popuplist() nr6
external   userid menuchoice cpath entryline() navrecs() messboxwait()
external   remove() makeidx() Background() posncolpopup() colpoplines() base
external   chkstr() strcount() colpopup() bpopdb() $menu
external   _shade() #margin_A #margin_B #margin_C #margin_D

public     invtot ptstr custcode dsa abbrv_name ptval jobnr $refnr psa a_jobnr
public     $dateftr $ftrcode ptary[1] $screen

global     x i $dfa1 $ftrappts #ftrappts $fitter $day_1 ftrname $popstr df clb
global     ShowDeliveries() ReplaceHardSpace() ftrarray[1] ShowOrders() clf
global     #1stbalance #1strecord Titles_1() $showdel $invoice
global     CheckNr() ShowStatus() ShowAllReqs() S_details #count WriteDetails()
global     ReturnToMenu() jobdesc ftgcomm ftginstr ftgscrn y z slotrec y1 y2 y3 y4
global     ShowInstructions() $ctgplan ftginit #lenareas #startc #startr
global     $instruct EnterInstructions() #upper #rem m1 m5 NavReqns() S_status
global     $delonly ftgplan ShowText() mess5 $ordstat EnterCustName() $invdate
global     custname navmess() bot psmode RecsScroll() orddate fmt
global     SetupDetails() GetCustDetails() ShowDetails() all
global     custaddr1  custaddr2  custcity custpostcode deladdr1 deladdr2 #inv
global     deladdr3 deladdr4 cust_title custcontact offtel hometel $partaddr
global     offax mobile custaddr deladdr k NavMess_A()
'  CheckArcOrders() arc RecsScrollArc() NavMess_Arc()
global     SearchAddress() ShowOrder() #prec CustScreenLine()
global     ReplaceCR() ShowFittings() varndes ShowReceipts() l #amount $invnr
global     $status SearchInvoice() ReplaceHardSpace2() S_all
global     ShowComments() BoxText() y2a y2b y2c #margin #netinv #totcost


MAIN
single-step off
  file unload all
  Background()
  error off
  fmt = "L64"
  bot = 7
  clb = 13
  clf = 10
'   arc = 0
  $invoice = "N"

  while true
    window close
    if cerror
      exit while
    end if
  end while

  while true
    x = CheckNr()                          ' check Job Nr exists in CUST_ORD
    if x = -1
      exit while
    end if
  end while

  ReturnToMenu()

END MAIN


FUNCTION Titles_1()
local y1 y2 y3 y4 y5 y6 y7
  screen clear box 22 5 23 75 0 0 no-border
  y5 = format("Receipts - press any key to continue","M71")
  y6 = format("   Date     Amount  Method      Notes           Ent'd   Time  Posted","L71")
  screen print 9 5 fgp bgp y6
  screen print 22 5 fgp bgp y5
END FUNCTION ' Titles()


FUNCTION CheckNr()                     ' checks for JobNr - if not found
local m1 m2 m3 m4
  while true
    z = 0
'     arc = 0
'     x = popuplist(9,30,13,"ÿCustomerÿName ÿÿÿÿÿJobÿNr ÿÿInvoiceÿNr Partialÿaddress","{Esc} to exit",1,0)
    m1 = "ÿÿÿÿJobÿNr"
    m2 = "ÿCustomerÿName"
'     m3 = "ÿÿInvoiceÿNr"
    m4 = "Partialÿaddress"
    x = popuplist(9,30,13,m1&m2&m4,"{Esc} to exit",1,0)
    if x = 0
      if ptstr = m2                    '"ÿCustomerÿName"
        k=remove("all_req1.idx")
        x = EnterCustName(z)
        if x = -1
          continue while
        elseif x = 2                   ' using archives
          vloadif(dpath|"ordstat4.vw")
          order change key "[Job_Nr]"
          x = SetupDetails()
          if x = -1
            continue while
          end if

        elseif x = 0                   ' using current
          vloadif(dpath|"ordstat4.vw")
          order change key "[Job_Nr]"
          x = SetupDetails()
          if x = -1
            continue while
          end if
        end if

      elseif ptstr = m4                '"Partialÿaddress"
        k=remove("all_req1.idx")
        vloadif(dpath|"ordstat4.vw")
        order change key "[Job_Nr]"
        x = fentrybox(" Enter partial address details or {Esc} to exit ",35,"","")
        if x = -1
          return (-1)
        elseif x = 0
          $partaddr = ptstr             'message "$partaddr is:"&str($partaddr)
          repaint off
          progress(15,10," Searching for `"|$partaddr|"' ",0)
          x = SearchAddress()
          vloadif(dpath|"ordstat4.vw")
          order change key "[Job_Nr]"
          x = SetupDetails()
          if x = -1
            continue while
          end if
        end if

      elseif ptstr = m1                '"ÿÿ Job Nr"
        k=remove("all_req1.idx")
        vloadif(dpath|"ordstat4.vw")
        order change key "[Job_Nr]"
        x = fentrybox(" Enter Order Nr or {Esc} to exit ",6,shopmask,"")
        if x = -1
          return (-1)
        elseif x = 0
          jobnr = ptstr
          x = SetupDetails()
        end if
      end if

    elseif x = -1
      return (-1)
    end if
  end while
END FUNCTION ' CheckNr()


FUNCTION GetCustDetails()
  $showdel     = [PDA]
  cust_title   = [Title]
  custaddr1    = [Address_1]
  custaddr2    = [Address_2]
  custcity     = [City/Town]
  custpostcode = [Postcode]
  deladdr1     = [Delivery_Address_1]
  deladdr2     = [Delivery_Address_2]
  deladdr3     = [Del_City]
  deladdr4     = [Del_Postcode]
  custcode     = [Customer_Code]
  custname     = [Customer_Name]
  custcontact  = [Contact_Name]
  offtel       = [Office_Tel]
  hometel      = [Home_Tel]
  offax        = [Office_Fax]
  mobile       = [Mobile/Other_Nr]
  $status = case [Credit_Status] ("A","Account") ("C","Cash only") ("D","Delayed") ("N","No deliveries!!")
END FUNCTION ' GetCustDetails()


FUNCTION ShowCustomer()
local c1 c2 c3 c4 d1 d2 d3 d4 cc1 cr1 cc2 cr2 dc1 dr1 dc2 dr2 pc1 pr1 pc2 pr2 \
      ordets p1 p2 p3 p4 p5 p6 p7 p8 df
  cr1 = 8
  cc1 = 2
  cr2 = cr1+5
  cc2 = cc1+37
  dr1 = cr1
  dc1 = 42
  dr2 = cr2
  dc2 = dc1+37
  pr1 = cr2+1
  pc1 = cc1+14
  pr2 = pr1+8
  pc2 = pc1+50
  if $showdel = "Y"
    df  = clf
  else
    df  = 8
  end if

  screen clear box cr1 cc1 cr2 cc2 clf clb
  c1 = left(custaddr1|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c2 = left(custaddr2|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c3 = left(custcity|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c4 = left(custpostcode|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  screen print cr1 cc1+1 clf clb "ÿCustomer addressÿ(Acc Nr"&custcode|")ÿ"
  screen print cr1+1 cc1+2 clf clb c1
  screen print cr1+2 cc1+2 clf clb c2
  screen print cr1+3 cc1+2 clf clb c3
  screen print cr1+4 cc1+2 clf clb c4
  screen save cr1 cc1 cr2 cc2 custaddr
  screen clear box dr1 dc1 dr2 dc2 df clb
  d1 = left(deladdr1|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d2 = left(deladdr2|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d3 = left(deladdr3|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d4 = left(deladdr4|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  screen print dr1 dc1+1 df clb "ÿDelivery addressÿ"
  screen print dr1+1 dc1+2 df clb d1
  screen print dr1+2 dc1+2 df clb d2
  screen print dr1+3 dc1+2 df clb d3
  screen print dr1+4 dc1+2 df clb d4
  screen save dr1 dc1 dr2 dc2 deladdr
  if $showdel = "N"
    screen print dr2 dc1+1 df clb "ÿNot to be shown on invoiceÿ"
  end if
  screen save dr1 dc1 dr2 dc2 deladdr

  screen clear box pr1 pc1 pr2 pc2 clf clb
  p1 = format("Title:  ÿ   "|left(cust_title|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p2 = format("Name:     ÿ "|left(custname|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p3 = format("Contact:   ÿ"|left(custcontact|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p4 = format("Office tel:ÿ"|left(offtel|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p5 = format("Home tel:  ÿ"|left(hometel|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p6 = format("Fax nr:ÿÿ  ÿ"|left(offax|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p7 = format("Mobile nr: ÿ"|left(mobile|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p8 = " press any key to continue ... "
  screen print pr1 pc1+1 clf clb "ÿACCOUNT STATUS:"&$status|"ÿ"
  screen print pr1+1 pc1+2 clf clb p1
  screen print pr1+2 pc1+2 clf clb p2
  screen print pr1+3 pc1+2 clf clb p3
  screen print pr1+4 pc1+2 clf clb p4
  screen print pr1+5 pc1+2 clf clb p5
  screen print pr1+6 pc1+2 clf clb p6
  screen print pr1+7 pc1+2 clf clb p7
  screen print pr1+8 pc1+19 clf clb p8
  inchar
  screen clear box 7 1 sch 80 0 0 no-border
END FUNCTION ' ShowCustomer()


FUNCTION ShowFittings2()
local $ftgstr $fname d
  $ftgstr = ""
  repaint off
  vloadif(dpath|"ftr_list.vws")
  vloadif(dpath|"appntmnt.vws")
  order change physical
  data query execute "job_reqn.dfq" index "job_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr and not (deleted)                      ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No appointments for this job ",0,0,1)
    return (1)
  end if
  $dfa1 = ""
  $ftrappts = ""

'--------------------------------------search to remove duplicate days
  if records > 1
    data goto record first
    for i = 1 to records
      $dfa1 = left([DFA],11)
      x = chkstr($dfa1,$ftrappts)
      if x = -1
        $ftrappts = $ftrappts&$dfa1
      end if
      data goto record next
    end for
    x=strcount($ftrappts)                'message "x is:"&str(x)
    #ftrappts = ptval                    '
  else
    $ftrappts = left([DFA],11)
    #ftrappts = 1                   '
  end if
  redimension ftrarray[#ftrappts]
  for i = 1 to #ftrappts
    d = days(left(group($ftrappts,i),5))
    $day_1 = left(date2([Date]),6)|right(date2([Date]),2) 'message "$day_1 is:"&str($day_1)
    $fitter = right(group($ftrappts,i),6) 'message "$fitter) is:"&str($fitter)
    $fname = filelookup([FTR_LIST.Fitter_Code],[FTR_LIST.Nickname],$fitter)
    ftrname = ReplaceHardSpace2($fname,len($fname))
    $ftgstr = $ftgstr&$day_1|"ÿ"|left(ftrname|"ÿÿÿÿÿÿÿÿ",8)     ' HARD space
    ftrarray[i] = $fitter
  end for

  while true
    x = posncolpopup(4,5,20,$ftgstr,"",1,0,clf,clb,0,7,0)  'highlight date & press {Enter} to show deliveries
    $dateftr = ptstr
    if x = -1
      repaint off
      exit while
    end if
    screen shortrestore dsa
    $ftrcode = ftrarray[ptval]
    ShowDeliveries()
  end while

  vunloadif("appntmnt.vws")
  vunloadif("delivr_1.vw")
  vunloadif("ftr_list.vws")

END FUNCTION ' ShowFittings2()


FUNCTION ShowOrders()
local $ordstr
  $ordstr = ""
  repaint off
  vloadif(dpath|"variat_n.vws")
  order change physical
  data query execute "job_reqn.dfq" index "job_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr and not (deleted)                      ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" Job Nr not found ",0,0,1)
    return (1)
  end if
  for i = 1 to records
    #amount=right("ÿÿÿÿÿÿÿÿÿÿ"|currency([Amount_Gross]),10)
    varndes = ReplaceHardSpace2(date2([Date])&format([Reason],"L50")&#amount,70)
    $ordstr = $ordstr&varndes          'message "$popstr is:"&str($popstr)
    data goto record next
  end for
  vunloadif("variat_n.vws")
  while true
    x = colpoplines(10,5,23,$ordstr,"",1,0,clf,clb,14,3)  'highlight date & press {Enter} to show deliveries
    if x = -1
      exit while
    end if
    screen shortrestore dsa
  end while
END FUNCTION ' ShowOrders()


FUNCTION SetupDetails()
local $chstr
  if base<>left(jobnr,1)                               '   if none - then return
    messboxwait(" Not one of your Jobs! ",0,0,1)
    return (-1)
  end if

  data find "[Job_Nr]" equal jobnr options "gw"
  if cerror                               '   if none - then return
    messbox(" Job Nr not found ",0,0,1)
    return (-1)
  else
    jobdesc  = [Description]
    ftginstr = [Instructions]
    ftgcomm  = [Fitting_Comment]
    jobdesc  = @if(len(jobdesc)=0,"Not known",jobdesc)
    ftginstr = @if(len(ftginstr)=0,"Not known",ftginstr)
    ftgcomm  = @if(len(ftgcomm)=0,"Not known",ftgcomm)
    slotrec  = [Appt_Slots]
    $ordstat = [Order_Status]
    $invoice = [Completed]
    $invnr   = [Inv_Nr]
    $invdate = [Invoice_Date]
    #netinv  = [Net_Invoice]
  end if
  repaint on
  repaint
  screen save 1 1 6 scw S_all
  repaint off
  vunloadif("ordstat4.vw")
  $chstr = "Customer Fittings Instructions Orders Requisitions Receipts"
  while true
    screen shortrestore S_all
    x = colpopup(8,31,20,$chstr,"{Esc} to exit",1,0,clf,clb,0,7)  'highlight date & press {Enter} to show deliveries
    if x = -1
      Background()
      return (-1)
    end if

    if ptstr = "Instructions"
      ShowComments()                ' {I}nstructions
      screen shortrestore S_all

    elseif ptstr = "Receipts"
      #1stbalance = 0
      ShowReceipts()
      screen shortrestore S_all

    elseif ptstr = "Customer"
      repaint off
      vloadif(dpath|"ordstat4.vw")
      order change key "[Job_Nr]"
      data find "[Job_Nr]" equal jobnr options ""
      GetCustDetails()
      vunloadif("ordstat4.vw")
      ShowCustomer()
      screen shortrestore S_all

    elseif ptstr = "Fittings"
      x = ShowFittings2()
      screen shortrestore S_all

    elseif ptstr = "Orders"
      x = ShowOrders()
      inchar
      screen shortrestore S_all

    elseif ptstr = "Requisitions"
      x = ShowAllReqs()

    end if
  end while

END FUNCTION ' SetupDetails()


FUNCTION WriteDetails()         ' write customer & job details to CUSENT3B
  jobdesc  = ReplaceCR(jobdesc)        'message "jobdesc) is:"&str(jobdesc)
  ftginstr = ReplaceCR(ftginstr)       'message "ftginstr) is:"&str(ftginstr)
  ftgcomm  = ReplaceCR(ftgcomm)        'message "ftgcomm) is:"&str(ftgcomm)
  lock-record
    [Description]     = jobdesc
    [Instructions]    = ftginstr
    [Fitting_Comment] = ftgcomm
    [Last_Update]     = today
    [Updated_By]      = userid
  write-record
END FUNCTION ' WriteDetails()


FUNCTION ShowText()
  x=wraptext(9,14,13,66,15,1,jobdesc,"L",1,0,0)  '   message "x is:"&str(x)
  mess5 = "Job details"|@if(slotrec=0,""," - (timeslots"&str(slotrec)|")")
  screen print  9 16 15 1 mess5

  x = wraptext(14,14,17,66,15,1,ftginstr,"L",1,0,0)
  screen print 14 16 15 1 "Other comments (eg appointment times etc)"

  x = wraptext(18,14,21,66,15,1,ftgcomm,"L",1,0,0)
  screen print 18 16 15 1 "Comments re Fitting"
END FUNCTION ' ShowText()


FUNCTION ReturnToMenu()
  file unload all
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION ShowStatus()
local mess1 r1 r2 c1 c2 cl1 cl2 i
  r1 = 5
  r2 = r1+3
  c1 = 60
  c2 = c1+20
  if $invoice = "Y"
    cl1 = 15
    cl2 = 10
    screen clear box r1 c1 r2 c2 cl1 cl2
    screen print r1+1 c1+5 cl1 cl2 "ÿÿINVOICED"
    screen print r1+2 c1+2 cl1 cl2 $invnr|" - "|date2($invdate)

  else
    mess1 = case $ordstat ("A","Initial only")("U","All details held")\
  ("R","To be authorised")("H","Held for check")("V","Rejected")("P","Authorised")\
  ("L","Being prepared")("D","Despatched") else "Missing"
    if $ordstat = "A"
      cl1 = 14
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+5 cl1 cl2 mess1
    elseif $ordstat = "U"
      cl1 = 14
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+3 cl1 cl2 mess1
    elseif $ordstat = "R"
      cl1 = 10
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+3 cl1 cl2 mess1
    elseif $ordstat = "V"
      for i = 1 to 15
        cl1 = 4
        cl2 = 0
        screen clear box r1 c1 r2 c2 cl1 cl2
        screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
        screen print r1+2 c1+7 cl1 cl2 mess1
        wait .1
        cl1 = 0
        cl2 = 4
        screen clear box r1 c1 r2 c2 cl1 cl2
        screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
        screen print r1+2 c1+7 cl1 cl2 mess1
        wait .1
      end for
    elseif $ordstat = "H"
      for i = 1 to 15
        cl1 = 4
        cl2 = 0
        screen clear box r1 c1 r2 c2 cl1 cl2
        screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
        screen print r1+2 c1+4 cl1 cl2 mess1
        wait .1
        cl1 = 0
        cl2 = 4
        screen clear box r1 c1 r2 c2 cl1 cl2
        screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
        screen print r1+2 c1+4 cl1 cl2 mess1
        wait .1
      end for
    elseif $ordstat = "P"
      cl1 = 10
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+6 cl1 cl2 mess1
    elseif $ordstat = "L"
      cl1 = 4
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+4 cl1 cl2 mess1
    elseif $ordstat = "D"
      cl1 = 10
      cl2 = 0
      screen clear box r1 c1 r2 c2 cl1 cl2
      screen print r1+1 c1+5 cl1 cl2 "ORDER STATUS"
      screen print r1+2 c1+6 cl1 cl2 mess1
    end if
  end if
  screen save r1 c1 r2 c2 S_status
END FUNCTION ' ShowStatus()


FUNCTION ReplaceCR(str1)
local j r m bw l_last #addn l
  m = ""
  for j = 1 to len(str1)
    r = mid(str1,j,1)
    if r = "~"
      r = ""                          ' replace soft space
    end if
    m = m|r
  end for
  return (m)
END FUNCTION ' ReplaceCR()


FUNCTION RecsScroll()
local x bot psmode
  screen save scrheight 1 scrheight scrwidth bot
  smartpeek $_spndmes psmode
  if psmode = 1
    smartpoke $_spndmes 0
  end if
  while TRUE
    NavMess_A()
    x = inchar
    if x = {Down}
      data goto record next
      NavMess_A()

    elseif x = {Up}
      data goto record previous
      NavMess_A()

    elseif x = {PgDn}
      data goto page next
      NavMess_A()

    elseif x = {PgUp}
      data goto page previous
      NavMess_A()

    elseif x = {^End}
      data goto record last
      NavMess_A()

    elseif x = {^Home}
      data goto record first
      NavMess_A()

    elseif x = {Home}
      suspendone
      keys Home,F8
      screen shortrestore bot
      NavMess_A()

    elseif x = {End}
      suspendone
      keys End,F8
      screen shortrestore bot
      NavMess_A()

    else
      exit while
    end if
  end while
  if psmode = 1
    smartpoke $_spndmes 1
  end if
  return (x)
END FUNCTION ' RecsScroll()


FUNCTION NavMess_A()
local ftgdate ordstat mess1 col1 mess2
  col1 = 12
  ftgdate = [Fitting_Date]             'message "ftgdate) is:"&date2(ftgdate)
  ordstat = [Order_Status]             ' message "ordstat) is:"&str(ordstat)
  jobnr   = [Job_Nr]                   ' message "jobnr) is:"&str(jobnr)
  mess1   =  format("Job Nr"&[Job_Nr]&"- Ftg Date:"&format(@if([Fitting_Date]=blank,"NONE!",date2([Fitting_Date])),"L8")&"- Status:"&[$case],"M71")
  if [Invoice_Total] < 0
    mess2 =  format("Credit note for:"&currency(abs([Invoice_Total]))&"- balance o/s:"&currency([Balance_Due]),"M71")
  else
    mess2 =  format("Order value:"&currency([Invoice_Total])&"- balance o/s:"&format(currency([Balance_Due]),"R8"),"M71")
  end if
  screen print 19 6 15 col1 mess1
'   if arc = 0
'     screen print 20 6 15 col1 mess2
'   end if
END FUNCTION   'NavMess_A()


FUNCTION ShowDetails()
local c1 c2 c3 c4 d1 d2 d3 d4 cc1 cr1 cc2 cr2 dc1 dr1 dc2 dr2 pc1 pr1 pc2 pr2 \
      ordets p1 p2 p3 p4 p5 p6 p7 p8 clf clb df

  clb = 13
  clf = 10
  cr1 = 8
  cc1 = 2
  cr2 = cr1+5
  cc2 = cc1+37
  dr1 = cr1
  dc1 = 42
  dr2 = cr2
  dc2 = dc1+37
  pr1 = cr2+1
  pc1 = cc1+14
  pr2 = pr1+8
  pc2 = pc1+50
  if $showdel = "Y"
    df  = clf
  else
    df  = 8
  end if
  screen clear box cr1 cc1 cr2 cc2 clf clb
  c1 = left(custaddr1|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c2 = left(custaddr2|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c3 = left(custcity|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  c4 = left(custpostcode|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  screen print cr1 cc1+1 clf clb "ÿCustomer's addressÿ"
  screen print cr1+1 cc1+2 clf clb c1
  screen print cr1+2 cc1+2 clf clb c2
  screen print cr1+3 cc1+2 clf clb c3
  screen print cr1+4 cc1+2 clf clb c4
  screen save cr1 cc1 cr2 cc2 custaddr
  screen clear box dr1 dc1 dr2 dc2 df clb
  d1 = left(deladdr1|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d2 = left(deladdr2|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d3 = left(deladdr3|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  d4 = left(deladdr4|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35)
  screen print dr1 dc1+1 df clb "ÿDelivery addressÿ"
  screen print dr1+1 dc1+2 df clb d1
  screen print dr1+2 dc1+2 df clb d2
  screen print dr1+3 dc1+2 df clb d3
  screen print dr1+4 dc1+2 df clb d4
  screen save dr1 dc1 dr2 dc2 deladdr
  if $showdel = "N"
    screen print dr2 dc1+1 df clb "ÿNot to be shown on invoiceÿ"
  end if
  screen save dr1 dc1 dr2 dc2 deladdr

  screen clear box pr1 pc1 pr2 pc2 clf clb
  p1 = format("Title:  ÿ   "|left(cust_title|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p2 = format("Name:     ÿ "|left(custname|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p3 = format("Contact:   ÿ"|left(custcontact|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p4 = format("Office tel:ÿ"|left(offtel|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p5 = format("Home tel:  ÿ"|left(hometel|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p6 = format("Fax nr:ÿÿ  ÿ"|left(offax|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p7 = format("Mobile nr: ÿ"|left(mobile|"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ",35),"L47")
  p8 = " press any key to continue ... "
  screen print pr1 pc1+1 clf clb "ÿACCOUNT STATUS:"&$status|"ÿ"
  screen print pr1+1 pc1+2 clf clb p1
  screen print pr1+2 pc1+2 clf clb p2
  screen print pr1+3 pc1+2 clf clb p3
  screen print pr1+4 pc1+2 clf clb p4
  screen print pr1+5 pc1+2 clf clb p5
  screen print pr1+6 pc1+2 clf clb p6
  screen print pr1+7 pc1+2 clf clb p7
  screen print pr1+8 pc1+19 clf clb p8
  inchar
  repaint off
END FUNCTION ' ShowDetails()


' FUNCTION CheckArcOrders()
'   while true
'     screen clear box 1 1 sch scw 0 0 no-border
'     repaint off
'     vloadif(dpath|"a_ordst2.vw")
'
'     order change key "[Abbrv_Name]"
'     data find "[Abbrv_Name]" equal abbrv_name options ""
'     if cerror
'       messboxwait(" Name"&chr(34)|abbrv_name|chr(34)|" not held on file ",0,0,1)
'       return (-1)
'     end if
'     repaint on
'     repaint
'     ptval=0
'     y4 = format(" ****************************************************","M71")
'     y3 = format(" *****************  ARCHIVED  ORDERS  ***************","M71")
'     y1 = format(" Name                                Delivery Address","L71")
'     y2 = format(" {Enter} selects - {Esc} exits ","M71")
'     screen print 1 6 fgp 13 y4
'     screen print 2 6 fgp 13 y3
'     screen print 3 6 fgp 13 y4
'     screen print 4 6 fgp bgp y1
'     screen print 18 6 fgp bgp y2
'     screen print 20 6 fgp 13 y4
'     screen print 21 6 fgp 13 y3
'     screen print 22 6 fgp 13 y4
'
'     while true
'       ptval = RecsScrollArc()
'
'       if ptval = {Enter}
'         repaint off
'         jobnr = [Job_Nr]
'         arc   = 1
'         return (0)
'
'       elseif ptval = {Esc}
'         screen clear box 1 1 sch scw 0 0 no-border
'         repaint off
'         return (-1)
'       end if
'     end while
'   end while
' END FUNCTION ' CheckArcOrders()


FUNCTION EnterCustName(z)
  while true
    if z = 0
      while true
        x = fentrybox(" Enter first 5 letters of Name (inc. capitals) - {Esc} ",5,"","")
        if x = 0
          if len(ptstr)=0
            continue while
          end if
          exit while
        elseif x = -1
          return (-1)
        end if
      end while
      abbrv_name = ptstr

      screen clear box 1 1 sch scw 0 0 no-border
      repaint off
      vloadif(dpath|"ordstat2.vw")
      order change key "[Abbrv_Name]"
      data find "[Abbrv_Name]" equal abbrv_name options ""
      if cerror
'         messbox(" Name"&chr(34)|abbrv_name|chr(34)|" not on file - search archives? (y/n) ",1,1,1)
'         if ptstr == "y"
'           arc = 1
'           x = CheckArcOrders()
'           if x = -1
'             return (-1)
'           else
'             screen clear box 1 1 sch scw 0 0 no-border
'             repaint off
'             jobnr = [Job_Nr]
'             return (2) ' using archived files
'           end if
'         else
        continue while
'         end if
      end if
    else
      vloadif(dpath|"ordstat2.vw")
    end if

    CustScreenLine()
    while true
      ptval = RecsScroll()
      if ptval = {Enter}
        repaint off
        jobnr = [Job_Nr]

        vloadif(dpath|"ordstat4.vw")
        order change key "[Job_Nr]"
        x = SetupDetails()
        vloadif(dpath|"ordstat2.vw")
        CustScreenLine()
        continue while

'       elseif ptval = {a}
'         x = CheckArcOrders()
'         if x = -1
'           exit while
'         else
'           screen clear box 1 1 sch scw 0 0 no-border
'           repaint off
'           jobnr = [Job_Nr]
'           return (2) ' using archived files
'         end if

      elseif ptval = {Esc}             'message "Escaping from EnterCustNAme - L705"
        screen clear box 1 1 sch scw 0 0 no-border
        repaint off
        return (-1)
      end if
    end while
  end while
END FUNCTION 'EnterCustName()


' FUNCTION RecsScrollArc()
' local x bot psmode
'   screen save scrheight 1 scrheight scrwidth bot
'   smartpeek $_spndmes psmode
'   if psmode = 1
'     smartpoke $_spndmes 0
'   end if
'   while TRUE
'     NavMess_Arc()
'     x = inchar
'     if x = {Down}
'       data goto record next
'       NavMess_Arc()
'
'     elseif x = {Up}
'       data goto record previous
'       NavMess_Arc()
'
'     elseif x = {PgDn}
'       data goto page next
'       NavMess_Arc()
'
'     elseif x = {PgUp}
'       data goto page previous
'       NavMess_Arc()
'
'     elseif x = {^End}
'       data goto record last
'       NavMess_Arc()
'
'     elseif x = {^Home}
'       data goto record first
'       NavMess_Arc()
'
'     elseif x = {Home}
'       suspendone
'       keys Home,F8
'       screen shortrestore bot
'       NavMess_Arc()
'
'     elseif x = {End}
'       suspendone
'       keys End,F8
'       screen shortrestore bot
'       NavMess_Arc()
'
'     else
'       exit while
'     end if
'   end while
'   if psmode = 1
'     smartpoke $_spndmes 1
'   end if
'   return (x)
' END FUNCTION ' RecsScrollArc()


' FUNCTION NavMess_Arc()
' local ftgdate ordstat mess1 col1 mess2
'   col1 = 12
'   orddate = [Date_Of_Order]
'   ftgdate = [Fitting_Date]             'message "ftgdate) is:"&date2(ftgdate)
'   ordstat = [Order_Status]             ' message "ordstat) is:"&str(ordstat)
'   jobnr   = [Job_Nr]                   ' message "jobnr) is:"&str(jobnr)
'   mess1   =  format("Job Nr"&[Job_Nr]&"- Ftg Date:"&format(@if([Fitting_Date]=blank,"NONE!",date2([Fitting_Date])),"L8")&"- Status:"&[$case],"M71")
'   if [Invoice_Total] < 0
'     mess2 =  format("Order date:"&date2(orddate)&"Credit note for:"&currency(abs([Invoice_Total])),"M71")
'   else
'     mess2 =  format("Order date:"&date2(orddate)&"-"&"Order value:"&format(currency([Invoice_Total]),"R8"),"M71")
'   end if
'   screen print 19 6 15 col1 mess1
'   if arc = 0
'     screen print 20 6 15 col1 mess2
'   end if
' END FUNCTION   'NavMess_A()


FUNCTION SearchAddress()
  vloadif(dpath|"ordstat5.vw")
  data goto record first
  while true
    data find "[Delivery_Address_1]" partial $partaddr options "fi"
    if cerror
      data goto record first
      while true
        data find "[Delivery_Address_2]" partial $partaddr options "fi"
        if cerror
          messboxwait(" `"|$partaddr|"' not found in Customer Order's file ",0,0,1)
          Background()
          return (1)
        else
          #prec = precord
          x = ShowOrder()
          if x = 0
            return (0)     ' correct found & SEEN!
          elseif x = -1
            return (-1)     '
          end if
        end if
      end while

    else
      #prec = precord
      x = ShowOrder()
      if x = 0
        return (0)     ' correct found & SEEN!
      elseif x = -1
        return (-1)     '
      end if
    end if
  end while
END FUNCTION ' SearchAddress()


FUNCTION ShowOrder()
  vloadif(dpath|"ordstat4.vw")
  data goto record record-number #prec
  repaint on
  repaint
  x = messbox(" Is this the order? (y/n) ",1,1,0)
  if x = -1
    return (-1)
  else
    if ptstr == "y"
      jobnr = [Job_Nr]
      return (0)     ' correct found & SEEN!
    else
      repaint off
      progress(15,10," Searching for `"|$partaddr|"' ",0)
      vloadif(dpath|"ordstat5.vw")
      data goto record next
      return (1)
    end if
  end if
END FUNCTION ' ShowOrder()


FUNCTION CustScreenLine()
  repaint on
  repaint
  ptval=0
  y1 = format(" Name                                Delivery Address","L71")
  y2 = format(" {A}rchived orders - {Enter} selects - {Esc} exits ","M71")
  screen print 4 6 fgp bgp y1
  screen print 18 6 fgp bgp y2
END FUNCTION ' CustScreenLine()


FUNCTION ShowFittings()
local d
  $popstr = ""
  repaint off
  vloadif(dpath|"ftr_list.vws")
  vloadif(dpath|"appntmnt.vws")
  order change physical
  data query execute "job_reqn.dfq" index "job_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr and not (deleted)                      ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messbox(" No appointments for this job ",0,0,1)
    return (1)
  end if
  $dfa1 = ""
  $ftrappts = ""

'--------------------------------------search to remove duplicate days
  if records > 1
    data goto record first
    for i = 1 to records
      $dfa1 = left([DFA],11)
      x = chkstr($dfa1,$ftrappts)
      if x = -1
        $ftrappts = $ftrappts&$dfa1
      end if
      data goto record next
    end for
    x=strcount($ftrappts)                'message "x is:"&str(x)
    #ftrappts = ptval                    '
  else
    $ftrappts = left([DFA],11)
    #ftrappts = 1                   '
  end if
  redimension ftrarray[#ftrappts]
  for i = 1 to #ftrappts
'     x = fm_busdate(left(group($ftrappts,i),5))   'message "x) is:"&str(x)
'     $day_1 = ptstr                     'message "$day_1 is:"&str($day_1)
'     x = fm_busdate(left(group($ftrappts,i),5))   'message "x) is:"&str(x)
'     $day_1 = ptstr                     '
    d = days(left(group($ftrappts,i),5))
    $day_1 = left(date2([Date]),6)|right(date2([Date]),2) 'message "$day_1 is:"&str($day_1)
'     $fitter = right(group($ftrappts,i),6) 'message "$fitter) is:"&str($fitter)
'     $fname = filelookup([FTR_LIST.Fitter_Code],[FTR_LIST.Nickname],$fitter)
    $fitter = right(group($ftrappts,i),6) 'message "$fitter) is:"&str($fitter)
    ftrname = ReplaceHardSpace(filelookup([FTR_LIST.Fitter_Code],[FTR_LIST.Nickname],$fitter))
    $popstr = $popstr&$day_1|"ÿ"|left(ftrname|"ÿÿÿÿÿÿÿÿ",8)     ' HARD space
    ftrarray[i] = $fitter
  end for

  while true
    x = posncolpopup(5,10,20,$popstr,"",1,0,12,13,0,7,0)  'highlight date & press {Enter} to show deliveries
    $dateftr = ptstr
    if x = -1
      repaint off
      exit while
    end if
    screen shortrestore dsa
    $ftrcode = ftrarray[ptval]
    ShowDeliveries()
  end while
  vloadif(dpath|"appntmnt.vws")
  order change physical
END FUNCTION ' ShowFittings()


FUNCTION ReplaceHardSpace(str1)
local j r m bw l_last #addn
  m = ""
  for j = 1 to len(str1)
    r = mid(str1,j,1)
    if r = " "
      r = "ÿ"                          ' replace hard space
    end if
    m = m|r
  end for
  m = m|repeat("ÿ",#addn)
  return (m)
END FUNCTION ' ReplaceHardSpace()


FUNCTION ReplaceHardSpace2(str1,bw)
local j r m l_last #addn
  m = ""
  for j = 1 to len(str1)
    r = mid(str1,j,1)
    if r = " "
      r = "ÿ"                          ' replace hard space
    end if
    m = m|r
  end for

  if len(m) < bw
    #addn = bw-len(m)
  else
    #addn = mod(len(m),bw)
  end if
  m = m|repeat("ÿ",#addn)
  return (m)
END FUNCTION ' ReplaceHardSpace2()


FUNCTION ShowComments()
'   x=wraptext(9,14,13,66,clf,clb,jobdesc,"L",1,0,0)  '   message "x is:"&str(x)
  x=wraptext(8,14,12,66,clf,clb,jobdesc,"L",1,0,0)  '   message "x is:"&str(x)
  mess5 = "Job details"|@if(slotrec=0,""," - (timeslots"&str(slotrec)|")")
  screen print  8 16 clf clb mess5
  x = wraptext(13,14,16,66,clf,clb,ftginstr,"L",1,0,0)
  screen print 13 16 clf clb "Other comments (eg appointment times etc)"
  x = wraptext(17,14,20,66,clf,clb,ftgcomm,"L",1,0,0)
  screen print 17 16 clf clb "Comments re Fitting"
  ShowInstructions()
  screen clear box 7 1 sch scw 0 0 no-border
END FUNCTION ' ShowComments()


FUNCTION ShowAllReqs()
local y2 y1 y3 y4
  progress(15,10," Please wait ... finding requisitions ",0)
  repaint off
  vloadif(dpath|"gds_rcvd.vws")
  vloadif(dpath|"supplier.vws")
  vloadif(dpath|"purchord.vws")
  vloadif(dpath|"all_reqn.vw")
  order change key "[JobNr]"
  data query execute "all_reqn.dfq" index "all_req1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen shortrestore psa
    x = remove("all_reqn.idx")                ' create temp index for allocation
    x = makeidx("requsn","all_reqn.idx","0",1)
    if x = -1
      message "makeidx() failed"
    end if
    messboxwait(" NO requisitions entered yet ",0,0,1)
    return (1)
  else                               ' order by ListOrder & prodMRC
    order sort now dictionary "all_reqn.idx" fields "[Lst_Stck;Product_MRC]" ascending
    #count = records
    repaint on
    repaint
    screen shortrestore S_all
  end if
  ptval=0
  while true
    ptval = NavReqns()
    if ptval = {Esc}
      repaint off
      vunloadif("gds_rcvd.vws")
      vunloadif("supplier.vws")
      vunloadif("purchord.vws")
      vunloadif("all_reqn.vw")
      screen clear box 7 1 sch scw 0 0 no-border
      return (-1)
    end if
  end while
  repaint off
END FUNCTION ' ShowAllReqs()


FUNCTION ShowInstructions()
local mess2
  if $ordstat <> "L" and $ordstat <> "D"
    fgp = clf
    bgp = clb
    x = messline(" Update Instructions? (y/n) ",1,1,1,21,14,53)
    fgp = fgpleasing
    bgp = bgpleasing
    if x = 0
      if ptstr == "y"
        x = EnterInstructions()          ' return 0 - success
        return (1)
      else                             ' repaint & restore top of screen
        repaint off
        return (1)
      end if
    end if
  else
    messboxwait(" Instructions cannot be altered - already passed/delivered ",0,0,1)
    return (1)
  end if
END FUNCTION ' ShowInstructions()


FUNCTION EnterInstructions()
local l #lenareas #startc #startr
  error off
  while true
    y = format("Press F10 to finish","M53")
    screen print 21 14 15 1 y
    x=wraptext(8,14,12,66,7,1,jobdesc,"L",1,0,0)  '   message "x is:"&str(x)
    mess5 = "Job details"|@if(slotrec=0,""," - (timeslots"&str(slotrec)|")")
    screen print  8 16 7 1 mess5

    x = wraptext(17,14,20,66,7,1,ftgcomm,"L",1,0,0)
    screen print 17 16 7 1 "Comments re Fitting"

    while true
      #lenareas = len(ftginstr)        'message "#lenareas) is:"&str(#lenareas)
      #startc = mod(#lenareas,50)
      #startr = int(#lenareas/50)+1
      screen editor 13 14 16 66 15 1 "Other comments (eg appointment times etc)" VARIABLE ftginstr ftginstr\
      MAX 2 50 START #startr #startc OPTIONS "" 0 0 1 RW_MODE
      smartpeek $_lastkey z
      if z <> {F10}
        messbox(" Must use {F10} to save record!! ",0,0,1)
        continue while
      else
        exit while
      end if
    end while

    x = wraptext(13,14,16,66,7,1,ftginstr,"L",1,0,0)
    screen print 13 16 7 1 "Other comments (eg appointment times etc)"
    while true
      #lenareas = len(ftgcomm)         ' message "#lenareas) is:"&str(#lenareas)
      #startc = mod(#lenareas,50)
      #startr = int(#lenareas/50)+1
      screen editor 17 14 20 66 15 1 "Comments re Fitting" VARIABLE ftgcomm ftgcomm\
      MAX 2 50 START #startr #startc OPTIONS "" 0 0 1 RW_MODE
      smartpeek $_lastkey z
      if z <> {F10}
        messbox(" Must use {F10} to save record!! ",0,0,1)
        continue while
      else
        exit while
      end if
    end while

    messline(" Confirm correct and continue? (y/n) ",1,1,1,22,14,53)
    if ptstr == "y"
      if len(ftginstr) = 0
        messbox(" Must enter instructions ",0,0,1)
        continue while
      else
        vloadif(dpath|"ordstat4.vw")
        order change key "[Job_Nr]"
        data find "[Job_Nr]" equal jobnr options ""
        WriteDetails()
        vunloadif("ordstat4.vw")
        return (0)
      end if
    else
      continue while
    end if
  end while
END FUNCTION ' EnterInstructions()


FUNCTION SearchInvoice()
  vloadif(dpath|"ordstat4.vw")
  order change key "[Inv_Nr]"
  while true
    data find "[Inv_Nr]" equal $invnr options ""
    if cerror
      messboxwait(" Invoice Nr"&$invnr&"not found ",0,0,1)
      return (1)
    else
      jobnr = [Job_Nr]
      return (0)     ' correct found & SEEN!
    end if
  end while
END FUNCTION ' SearchInvoice()


FUNCTION NavReqns()
local x psmode pd pq #percentmargin
  if $menu == "boss"
    #totcost = filesum([Cost])
    #margin  = (#netinv-#totcost)/#netinv
    #percentmargin = round(#margin*100,2) 'message "#percentmargin is:"&str(#percentmargin)
    y3 = format("ÿ"|chr(24)&chr(25)&"req'ns ("|str(#count)|")    {P}urchase details   {Esc} to exit    (Margin"&fixed(#percentmargin,1)|"%"|")","M78")
    if #margin < #margin_A
      screen print 9 2 12 1 y3
    elseif #margin < #margin_B
      screen print 9 2 14 1 y3
    elseif #margin < #margin_C
      screen print 9 2 10 1 y3
    elseif #margin < #margin_D
      screen print 9 2 14 1 y3
    else
      screen print 9 2 12 1 y3
    end if
  else
    y3 = format("ÿ"|chr(24)&chr(25)&"req'ns ("|str(#count)|")    {P}urchase details   {Esc} to exit ","M78")
    screen print 9 2 15 1 y3
  end if
  screen save scrheight 1 scrheight scrwidth bot
  smartpeek $_spndmes psmode
  if psmode = 1
    smartpoke $_spndmes 0
  end if
  while TRUE
    x = inchar
    if x = {Down}
      data goto record next

    elseif x = {Up}
      data goto record previous

    elseif x = {PgDn}
      data goto page next

    elseif x = {PgUp}
      data goto page previous

    elseif x = {^End}
      data goto record last

    elseif x = {^Home}
      data goto record first

    elseif x = {P} or x = {p}
      NavMess()

    else
      exit while
    end if
  end while
  if psmode = 1
    smartpoke $_spndmes 1
  end if
  return (x)
END FUNCTION   'NavReqns()


FUNCTION NavMess()
local col1 pd pq pr psc psn psr psp pq1 pinv piv
  if [Item_Type] = "B" or [Item_Type]="W" or [Item_Type]="J" or [Item_Type]="T" or [Item_Type]="O"
    pr = [Date_Allocated]              'message "pr is:"&date2(pr)
    $refnr = [Reference_Nr]            'message "$refnr is:"&str($refnr)
    error off
    pd = filelookup([purchord.Order_Nr],[purchord.Date_Ordered],$refnr) 'message "pd is:"&str(pd)
    if cerror
      messboxwait(" Reference NOT found in PURCHORD.DB ",0,0,1)
      return (1)
    else
      pq  = filelookup([purchord.Order_Nr],[purchord.Delivery_Quoted],$refnr)
      pq1 = @if(pq=null,"N/Q",pq)    'message "pq1 is:"&str(pq1)
      psc = filelookup([purchord.Order_Nr],[purchord.Supplier_Code],$refnr)
      psr = filelookup([purchord.Order_Nr],[purchord.Order_Reference],$refnr)
      psn = filelookup([supplier.Supplier_Code],[supplier.Name],psc)
      psp = filelookup([supplier.Supplier_Code],[supplier.Telephone],psc)
      if value(pr)=0 ' NOT received
        y2 = format("Ordered on"&date2(pd)&"- for delivery:"&pq1,fmt)
        y2a = format(left("From:"&psn&"-"&psp,66),fmt)   '
        y2c = format(left("Ref:"|psr,66),fmt)   'message "len(y2a) is:"&str(len(y2a))
        y2b = format("",fmt)   'message "y2 is:"&str(y2)
      else
        y2a = format(left("From:"&psn&"-"&psp,66),fmt)   '
        y2c = format(left("Ref:"|psr,66),fmt)   'message "len(y2a) is:"&str(len(y2a))
        pinv= filelookup([gds_rcvd.Order_Nr],[gds_rcvd.Invoice_Nr],$refnr)
        if $menu == "offc" or $menu == "boss"
          piv = filelookup([gds_rcvd.Order_Nr],[gds_rcvd.Invoice_Cost],$refnr)
          y2b = format(left(@if(pinv=blank,"","Invoice amount"&currency(piv)),65),fmt)
        else
          y2b = format("",fmt)   'message "y2 is:"&str(y2)
        end if
        y2  = format(left(@if(pinv=blank,"Order received on"&date2(pr)&"(Invoice not rec'd)","Order received on"&date2(pr)|"ÿ(Inv Nr"&pinv|")"),65),fmt)
      end if
      col1 = 1
    end if
    if BoxText(1,7,6,73,10,5,"L",1,0,0) = 0
      wait 7
      screen shortrestore psa
    end if
  else
    return (1)
  end if
END FUNCTION   'NavMess()


FUNCTION BoxText(r1,c1,r2,c2,fg,bg,jst,sprn,sml,pg)
local dr a b $line fmt
  b = dr
  clear psa
  screen save r1 c1 r2 c2 psa
  screen clear box r1 c1 r2 c2 fg bg
  screen print (r1+1) c1+2 fg bg format fmt y2
  screen print (r1+2) c1+2 fg bg format fmt y2a
  screen print (r1+3) c1+2 fg bg format fmt y2c
  screen print (r1+4) c1+2 fg bg format fmt y2b
  screen save r1 c1 r2 c2 dsa
  redimension ptary[1]
  ptval = a
  return (0)
END FUNCTION   'BoxText(r1,c1,r2,c2,fg,bg,ts,jst,sprn,sml,pg)


FUNCTION ShowDeliveries()
local y6
  progress(15,10," Please wait ... finding deliveries ",0)
  fgp = clf
  bgp = clb
  repaint off
  vloadif(dpath|"delivr_1.vw")
  order change key "[Job_Nr]"
  data query execute "job_reqn.dfq" index "sd1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Job_Nr] = jobnr
'   and
'   not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen shortrestore psa
    messboxwait(" NO deliveries booked ",0,0,1)
    fgp = fgpleasing
    bgp = bgpleasing
    return (1)
  end if
  data query execute "showdel1.dfq" index "sd2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Date_Out] = date2(left($dateftr,8))
'   and
'   [Fitter_Code]=$ftrcode
'   and
'   not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen shortrestore psa
    messboxwait(" NO deliveries booked for"&date2($dateftr),0,0,1)
    fgp = fgpleasing
    bgp = bgpleasing
    return (1)
  end if
  screen shortrestore psa
  y6 = format(" Deliveries not yet booked are shown in brackets ","M55")
  screen print 6+records 26 fgp bgp y6
  x = bpopdb("delivr_1",6,"","[ScrollView]","L53","[Quant_OS]","R6","[Job_Nr]",4,26,20,80,"",0)
  screen clear box 6+records 26 6+records 80 0 0 no-border
  fgp = fgpleasing
  bgp = bgpleasing
END FUNCTION ' ShowDeliveries()


FUNCTION ShowReceipts()
local rcptdes $rcpstr
  $rcpstr = ""
  repaint off
  ptval=0
  vloadif(dpath|"fran_os.vw")
  order change key "[Job_Nr]"
  error off
  data query execute "vu_cash" index  "#1stcash.idx"
' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
'   [Job_Nr] = jobnr
' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
  if cerror
    messbox(" No cash received for this order ",0,0,1)
    vunloadif("fran_os.vw")
    return (0)
  end if
  for i = 1 to records
    #amount=right("ÿÿÿÿÿÿÿÿÿÿÿÿ"|currency([Amount_Received]),12)
    rcptdes = ReplaceHardSpace(date2([Date_Of_Receipt])&format([Method_Of_Payment],"L6")&[Entered_By]&format([Authorisation],"L20")&#amount)
    $rcpstr = $rcpstr&rcptdes          'message "$popstr is:"&str($popstr)
    data goto record next
  end for
  vunloadif("fran_os.vw")
  x = colpoplines(10,5,20,$rcpstr,"",1,0,clf,clb,14,3)  'highlight date & press {Enter} to show deliveries
  screen shortrestore dsa
  inchar
END FUNCTION ' ShowReceipts()

