'DESPAT2X - same as DESPAT_2 but no ReturnToMenu

external   dpath PrintReport() sch scw vloadif() progress() progtag() fgi bgi
external   messbox() cpath Background() popuplist() messboxwait() fgp bgp
external   fentrybox() shopmask navrecs() chkstr() strcount() makeidx() base
external   addidxrec() vunloadif() chkdate() remove() getidxrecs() userid
external   findpopup() bpopdb() messline() wraptext() nr6 ipath
external   posncolpopup() colpoplines() colpopup() $menu
external   _shade() #margin_A #margin_B #margin_C #margin_D

public     invtot ptstr custcode dsa ptval jobnr $refnr psa a_jobnr
public     $dateftr $ftrcode ptary[1] $screen $shop_name
public     ftgdate ftrname ftrcode $branch

global     x i $dfa1 $ftrappts #ftrappts $fitter $day_1 $popstr df clb
global     ShowDeliveries() ReplaceHardSpace() ftrarray[1] ShowOrders() clf
global     Show1stCash() #1stbalance #1strecord Titles_1() $showdel $invoice
global     ShowStatus() ShowAllReqs() S_details #count WriteDetails() invdate
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 $invdate NavMess_A()
global     custname navmess() bot psmode RecsScroll() orddate fmt
global     SetupDetails() GetCustDetails() ShowDetails() all MaxFtgDate() maxdate
global     custaddr1  custaddr2  custcity custpostcode deladdr1 deladdr2 #inv
global     deladdr3 deladdr4 cust_title custcontact offtel hometel $partaddr
global     offax mobile custaddr deladdr k FittingDate() DespatRecs()
global     SearchAddress() ShowOrder() #prec CustScreenLine1() CustScreenLine2()
global     ReplaceCR() ShowFittings() varndes ShowReceipts() l #amount $invnr
global     $status SearchInvoice() ReplaceHardSpace2() S_all UndeldReqs()
global     ShowComments() BoxText() y2a y2b y2c y2d #margin #netinv #totcost
global     p1 p2 p3 p4 p5 p6 MarkDespatched() SelectDespatched()
global     $jobnrs #jobnrs PrintJobList() AddNewInvs() UpdateInvDates()
global     #slotsrem AlterApptSlots() #apptslots ChooseJobs() despatidx
global     UninvoicedOrders() ChooseShops2Select() Job_Locn() s1 s2 s3 s4 s5 s6 s7 $place lastjob


MAIN
single-step off
  file unload all
  Background()
  fmt = "L64"
  bot = 7
  clb = 13
  clf = 10
  $invoice = "N"

  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

  ChooseJobs()
'   if ChooseJobs() = 0
'     PrintJobList()
'   end if

'   UninvoicedOrders()

  ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
	Background()
	file unload all
'   transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION AlterApptSlots()
local  #newapptslots #newslotsrem
  #newapptslots = #apptslots - #slotsrem ' message "#newapptslots) is:"&str(#newapptslots)
' write to CUST_ORD
  #newslotsrem  = #slotsrem + (#newapptslots-#apptslots) 'message "#newslotsrem is:"&str(#newslotsrem)
  vloadif(dpath|"find_job.vw")
  order change key "[Job_Nr]"
  data find "[Job_Nr]" equal jobnr options "g"   '  find correct JOB
  if cerror
    messbox(" Job Nr NOT found ",0,0,1)
    vloadif(dpath|"despat_2.vw")
    return (-1)
  end if
  lock-record
    [Slots_Rem]  = #newslotsrem
    [Appt_Slots] = #newapptslots
  write-record
  vloadif(dpath|"despat_2.vw")
  return (0)
END FUNCTION ' AlterApptSlots()


FUNCTION PrintJobList()
  data query execute "despat_6.dfq" index "despat_3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [Completed]="Y"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    return (0)
  else
    messbox(" Print list of orders just marked for invoicing? (y/n) ",1,1,1)
    if ptstr == "y"
      repaint off
      p1 = "DESPAT_2.dfr"   ' p1 = report definition ("ord_stck.dfr")
      PrintReport(p1,p2,p3,p4,p5,p6)
      order change physical                ' release index
    end if
  end if
END FUNCTION ' PrintJobList()


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 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
'     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)
    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 ShowReceipts()
local rcptdes $rcpstr
  $rcpstr = ""
  repaint off
  ptval=0
  vloadif(dpath|"os_rcpts.vw")
  order change key "[Job_Nr]"
  data query execute "vu_cash" index  "#1stcash.idx"
' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
'   [Job_Nr] = jobnr
' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
  if cerror
    messbox(" No cash received for this order ",0,0,1)
    vunloadif("os_rcpts.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("os_rcpts.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()


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 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 ordstat mess1 col1 mess2
' message "[Completed] is:"&str([Completed])

  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
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 Show1stCash()
local $puar
  ptval=0
  repaint off
  vloadif(dpath|"os_rcpts.vw")
  order change key "[Job_Nr]"
  data query execute "vu_cash" index  "#1stcash.idx"
' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
'   [Job_Nr] = jobnr
' ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼
  if cerror
    messbox(" No cash received for this order ",0,0,1)
    return (-1)
  end if
  repaint on
  repaint
  screen shortrestore S_details
  Titles_1()
  inchar
  return (-1)
END FUNCTION ' Show1stCash()


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 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)
    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(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 #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
'  #m #c
  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 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 print (r1+5) c1+2 fg bg format fmt y2d
  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 for"&jobnr,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 NavMess()
local col1 pd pq pr psc psn psr psp pq1 pinv piv pss dld
  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)
      pss = filelookup([purchord.Order_Nr],[purchord.Del],$refnr)
      psn = filelookup([supplier.Supplier_Code],[supplier.Name],psc)
      psp = filelookup([supplier.Supplier_Code],[supplier.Telephone],psc)
      dld = case pss ("W","Warehouse")("F","Fulham")("R","Raynes")("P","Putney")("S","Sheen")("O","Collected")("I","On Site")
      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)
        y2d = format(left("Deliver to:"&dld,66),fmt)   'message "y2d is:"&str(len(y2a))
      else
        y2a = format(left("From:"&psn&"-"&psp,66),fmt)
        y2c = format(left("Ref:"|psr,66),fmt)   'message "len(y2a) is:"&str(len(y2a))
        y2d = format(left("Delivered to:"&dld,66),fmt)   'message "y2d 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,7,73,10,5,"L",1,0,0) = 0
      wait 7
      screen shortrestore psa
    end if
  else
    return (1)
  end if
END FUNCTION   'NavMess()



FUNCTION UndeldReqs()
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 undelivered requisitions ",0,0,1)
    fgp = fgpleasing
    bgp = bgpleasing
    return (1)
  end if
  data query execute "undelivd.dfq" index "ud2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Quant_OS]>.01
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    screen shortrestore psa
    messboxwait(" NO undelivered requisitions ",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 ' UndeldReqs()


FUNCTION SetupDetails()
local $chstr
'   #prec = precord
'   MaxFtgDate()
'   vloadif(dpath|"ordstat4.vw")
'   data goto record record-number #prec
'   if days(maxdate)>days([Fitting_Date]) 'message "Changing Ftg Date to"&date2(maxdate)
'     lock-record
'       [Fitting_Date]=maxdate
'     write-record
'   end if
  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]
  repaint on
  repaint
  screen save 1 1 6 scw S_all
  repaint off
  vunloadif("ordstat4.vw")
  $chstr = "Customer Fittings Instructions Orders Requisitions Undelivered 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()

    elseif ptstr = "Undelivered"
      x = UndeldReqs()

    end if
  end while

END FUNCTION ' SetupDetails()


FUNCTION FittingDate()
local  f3
' x=date2([Fitting_Date])
' message "x is:"&str(x)
  while true
    if dayname(date2([Fitting_Date])) == "Monday"
      f3 = days([Fitting_Date])+3
    elseif dayname(date2([Fitting_Date])) == "Tuesday"
      f3 = days([Fitting_Date])+3
    elseif dayname(date2([Fitting_Date])) == "Wednesday"
      f3 = days([Fitting_Date])+5
    elseif dayname(date2([Fitting_Date])) == "Thursday"
      f3 = days([Fitting_Date])+5
    elseif dayname(date2([Fitting_Date])) == "Friday"
      f3 = days([Fitting_Date])+5
    elseif dayname(date2([Fitting_Date])) == "Saturday"
      f3 = days([Fitting_Date])+4
    else
      f3 = days([Fitting_Date])+3
    end if
    invdate = date2(f3)
    if days(invdate)<days(today)
      invdate=today
    end if
    return (1)
  end while
END FUNCTION ' FittingDate()


FUNCTION CustScreenLine1()
local y1 y2
  repaint on
  repaint
  ptval=0
  y1 = format(" Fitting         Name & Delivery Address","L78")
  y2 = format(" Toggle {C}ompleted/Not {C}ompleted - {O}rder Status - {Esc} ","M78")
  screen print 4 2 fgp bgp y1
  screen print 18 2 fgp bgp y2
END FUNCTION ' CustScreenLine1()


FUNCTION CustScreenLine2()
  repaint on
  repaint
  ptval=0
  y1 = format(" Name                                Delivery Address","L71")
  y2 = format(" {Enter} selects - {Esc} exits ","M71")
  screen print 4 6 fgp bgp y1
  screen print 18 6 fgp bgp y2
END FUNCTION ' CustScreenLine2()


FUNCTION SelectDespatched()
  CustScreenLine1()
  while true
    ptval = DespatRecs()
    if ptval = {C} or ptval = {c}
      jobnr = [Job_Nr]
      if [Completed] = "Y"
        continue while
      end if
      repaint off
      #prec = precord
'       MaxFtgDate()
      jobnr = [Job_Nr]
      #slotsrem = [Slots_Rem]
      x = MarkDespatched("C")
      vloadif(dpath|"despat_2.vw")
      if record<records
        data goto record next
      end if
      CustScreenLine1()
      continue while

    elseif ptval = {D} or ptval = {d}
      jobnr = [Job_Nr]
      if [Completed] = "N"
        continue while
      end if
      repaint off
      #prec = precord
      MaxFtgDate()
      jobnr = [Job_Nr]
      #slotsrem = [Slots_Rem]
      x = MarkDespatched("D")
      vloadif(dpath|"despat_2.vw")
      if record<records
        data goto record next
      end if
      CustScreenLine1()
      continue while

    elseif ptval = {I} or ptval = {i}
      jobnr = [Job_Nr]
      if [Completed] = "N"
        continue while
      end if
      repaint off
      #prec = precord
      MaxFtgDate()
      jobnr = [Job_Nr]
      #slotsrem = [Slots_Rem]
      x = MarkDespatched("I")
      vloadif(dpath|"despat_2.vw")
      if record<records
        data goto record next
      end if
      CustScreenLine1()
      continue while

    elseif ptval = {O} or ptval = {o}
      jobnr = [Job_Nr]
      #prec = precord
      MaxFtgDate()
      x = SetupDetails()
      vloadif(dpath|"despat_2.vw")
      CustScreenLine1()
      continue while

    elseif ptval = {Esc}
      Background()
      return (-1)
    end if
  end while
END FUNCTION ' SelectDespatched()


FUNCTION DespatRecs()
local x psmode pd pq #percentmargin
  while TRUE
    if [Completed] = "N"
      y2 = format(" Mark as {C}ompleted - {O}rder Status - {Esc} ","M78")
    else
      y2 = format(" {I}ncomplete - change Invoice {D}ate - {O}rder Status - {Esc} ","M78")
    end if
    screen print 18 2 fgp bgp y2
    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 = {Esc}
'       exit while
    else
      return (x)
    end if
  end while
END FUNCTION ' DespatRecs()


FUNCTION MarkDespatched(md)
local aa
  if md = "I"
    messbox("Mark"&jobnr&"-"&[CustOrd_Name]&"as incomplete? (y/n) ",1,1,1)
    if ptstr == "y"
      lock-record
        [Completed] = "N"
        [Last_Update]=today
        [DateTB_Inv] = blank
      write-record
      return (0)
    else
      return (1)
    end if

  elseif md = "D"
    invdate = [DateTB_Inv]
    while true
      x = fentrybox(" To be inv'd on"&date2(invdate)|"; change date to: ",10,"##\/##\/####",today)
      if x = 0
        invdate = ptstr
        if chkdate(invdate,1) = -1
          messbox(" Incorrect date - re-enter ",0,0,1)
          continue while
        elseif days(invdate)<days(today)
          messbox(" Must be today or future date ",0,0,1)
          continue while
        end if
        exit while
      elseif x = -1
        return (-1)
      end if
    end while
    lock-record
      [DateTB_Inv] = invdate
      [Completed]  = "Y"
      [Last_Update]= today
      [Comp_Date]  = today
      [Comp_Time]  = time
      [Comp_User]  = userid
      [Updated_By] = userid
    write-record

  elseif md = "C"
    vloadif(dpath|"despat_6.vw")
    order change physical
    data query execute "job_reqn.dfq" index "undeliv.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Job_Nr] = jobnr
'   and
'   not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    if cerror
      messboxwait(" No uninvoiced orders ",0,0,1)
      return (-1)
    end if
    if filesum([Quant_OS])>.01
      messboxwait(" Items still to be delivered ... cannot invoice ",0,0,1)
      return (-1)
    else
' message "Check if any goods not yet delivered TO US"
    end if
    vloadif(dpath|"despat_2.vw")
    #apptslots = [Appt_Slots]        'message "#apptslots is:"&str(#apptslots)
    #slotsrem  = [Slots_Rem]         'message "#slotsrem is:"&str(#slotsrem)
    if #slotsrem <> 0
      messbox(" App't slots still to book - remove o/s slots? (y/n) ",1,0,1)
      if ptstr == "y"
        aa = AlterApptSlots()
        if aa = 1
          return (1)
        end if
      else
        return (1)
      end if
    end if

    custcode = [Customer_Code]           'message "custcode) is:"&str(custcode)
    vloadif(dpath|"customer.vws")
    custcity = filelookup([Customer_Code],[City/Town],custcode) 'message "custcity) is:"&str(custcity)
    vloadif(dpath|"despat_2.vw")

    if len(custcity)=0
      messboxwait(" Cannot process - customer's CITY/TOWN not entered ",0,0,1)
      return (1)
    end if

    if [Order_Status]<>"P"
      messboxwait(" Cannot mark as completed - order not passed by Shop ",0,0,1)
      return (1)
    end if

    FittingDate()                      'message "invdate is:"&str(invdate)

    messbox(jobnr&"will be invoiced on"&date2(invdate)|"? (y/n) ",1,1,1)
    if ptstr == "y"
'         lock-record
'           [DateTB_Inv] = invdate
'         [Completed]  = "Y"
'         [Last_Update]= today
'         [Updated_By] = userid
'       write-record
    lock-record
      [DateTB_Inv] = invdate
      [Completed]  = "Y"
      [Last_Update]= today
      [Comp_Date]  = today
      [Comp_Time]  = time
      [Comp_User]  = userid
      [Updated_By] = userid
    write-record


      return (0)
    else
      return (1)
    end if
  end if
END FUNCTION ' MarkDespatched()


FUNCTION AddNewInvs()
local ld
  order change index ipath|$branch|"_uninv.idx"
  ld = filemax([Date_Of_Order])        'message "ld is:"&str(ld)
  order change physical
  data goto record last
  while days([Date_Of_Order])>days(ld)
    if [SalesAnalysis]=$branch
      x = addidxrec(ipath|$branch|"_uninv.idx",precord,7)  'message "x is:"&str(x)
    end if
    data goto record previous
  end while
  order change index ipath|$branch|"_uninv.idx"
END FUNCTION ' AddNewInvs()


FUNCTION ChooseJobs()
local $locn

  ChooseShops2Select()

' message "$branch) is:"&str($branch)

  progress(15,10," Searching for uninvoiced orders ",0)
  vloadif(dpath|"despat_2.vw")
  AddNewInvs()
  data query execute "despat_2.dfq" index "uninv.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Inv_Nr]=blank
'   and
'   not (deleted)
'   and
'   [SalesAnalysis]<>"X"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No uninvoiced orders ",0,0,1)
    return (-1)
  end if
  UpdateInvDates()
  vloadif(dpath|"despat_2.vw")
  order sort now dictionary "lstjobs.idx" fields "[Fitting_Date;Job_Nr]" descending
  repaint on
  repaint
  SelectDespatched()
END FUNCTION ' ChooseJobs()


FUNCTION ChooseShops2Select()
local leftjob currec
  s1 = "Warehouse"
  s2 = "Trade"
  s3 = "Fulham"
  s4 = "Raynes"
  s5 = "Sheen"
  s7 = "Putney"

  if base="O"                         ' choice of Warehouse etc
    leftjob=Job_Locn()
' message "base is:"&str(base)
' message "$place is:"&str($place)

  elseif base="F"
    while true
      x = popuplist(8,57,15,s3&S7&s2,"",1,0)
      if x = -1
        continue while
      end if
      $place = ptstr
'       messbox(" Confirm"&upper($place)&"? (y/n) ",1,1,1)
'       if ptstr == "y"
      leftjob=left($place,1)
      exit while
'       else
'         continue while
'       end if
    end while

  elseif base="S"
    while true
      x = popuplist(8,57,15,s5&s4,"",1,0)
      if x = -1
        continue while
      end if
      $place = ptstr
'       messbox(" Confirm"&upper($place)&"? (y/n) ",1,1,1)
'       if ptstr == "y"
      leftjob=left($place,1)
      exit while
'       else
'         continue while
'       end if
    end while

  else
    leftjob=Job_Locn()
  end if

  $branch=leftjob

END FUNCTION 'ChooseShops2Select()


FUNCTION MaxFtgDate()
  repaint off
  vloadif(dpath|"appntmnt.vws")
  order change physical
  data query execute "job_reqn.dfq" index "job_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   [Job_Nr] = jobnr
'   and
'   not(deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    vloadif(dpath|"ordstat4.vw")
    order change key "[Job_Nr]"
    data find "[Job_Nr]" equal jobnr options ""
'     data goto record record-number #prec
    lock-record
      [Fitting_Date]=blank
    write-record
    return (1)
  else
    maxdate=filemax([Date])            'message "1593/ Max Date:"&date2(maxdate)
    vloadif(dpath|"ordstat4.vw")
    order change key "[Job_Nr]"
    data find "[Job_Nr]" equal jobnr options ""
'     data goto record record-number #prec
    lock-record
      [Fitting_Date]=maxdate
    write-record
  end if
'   vunloadif("appntmnt.vws")
END FUNCTION ' MaxFtgDate()


FUNCTION UpdateInvDates()
'updates [Fitting_Date]
  for i = 1 to records
    jobnr = [Job_Nr]
    MaxFtgDate()
    vloadif(dpath|"despat_2.vw")
    data goto record next
  end for
  data goto record first
  vunloadif("appntmnt.vws")
END FUNCTION ' UpdateInvDates()


FUNCTION UninvoicedOrders()
  progress(15,10," Please wait ... looking for uninvoiced orders ",0)
  vloadif(dpath|"aged_drs.vw")
  order change index "first.idx"
  data query execute "uninvd_1.dfq" INDEX "uninvd_1.idx"   ' choose o/s balances
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   days([Date_Of_Order])<=(days(today)-30)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  if cerror
    messboxwait(" No uninvoiced orders for"&$shop_name|" ",0,0,1)
    return (1)
  end if
  order sort now "uninvd_2.idx" fields "[Date_Of_Order]" ascending
  screen clear box 1 1 sch scw 0 0 no-border
  PrintReport("uninvord.dfr","Uninvoiced",p3,p4,p5,p6)
END FUNCTION ' UninvoicedOrders()


FUNCTION Job_Locn()
  s1 = "Warehouse"
  s2 = "Trade"
  s3 = "Fulham"
  s4 = "Raynes"
  s5 = "Sheen"
  s7 = "Putney"
  while true
    x = popuplist(8,37,15,s3&s7&s4&s5&s2&s1,"Order",1,0)
    if x = -1
      continue while
    end if
    $place = ptstr
    messbox(" Confirm"&upper($place)&"job? (y/n) ",1,1,1)
    if ptstr == "y"
      return (left($place,1))
    else
      continue while
    end if
  end while
END FUNCTION 'Job_Locn()


