FUNCTION NewJobNr()
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()

  elseif base="F"
    while true
      x = popuplist(8,57,15,s3&S7&s2,"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"
        leftjob=left($place,1)
        exit while
      else
        continue while
      end if
    end while

'     messbox(" Confirm FULHAM job? (y/n) ",1,1,1)
'     if ptstr == "y"
'       leftjob = base
'     else
'       leftjob=Job_Locn()
'     end if

  elseif base="S"
    while true
      x = popuplist(8,57,15,s5&s4,"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"
        leftjob=left($place,1)
        exit while
      else
        continue while
      end if
    end while

'     messbox(" Confirm SHEEN job? (y/n) ",1,1,1)
'     if ptstr == "y"
'       leftjob = base
'     else
'       leftjob=Job_Locn()
'     end if

  else
    leftjob=Job_Locn()
  end if

  vloadif(dpath|"cust_ord.vws")
  data goto record last
  while true
    if left([Job_Nr],1)=leftjob
      lastjob=right([Job_Nr],5)
      jobnr=leftjob|right("00000"|str(value(lastjob)+1),5)
      currec=precord
      data find "[Job_Nr]" equal jobnr options "g"
      if cerror                               '   if none - then return
        exit while
      else
        data goto record record-number currec
        data goto record previous
      end if
    else
      data goto record previous
    end if
  end while
END FUNCTION 'NewJobNr()


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()


FUNCTION PrintReceipt()
  vloadif(dpath|"cshrcvd1.vw")
  order change physical
  remove("cashrcpt.idx")
  makeidx("cashrcvd","cashrcpt.idx",rcvdnr,5)
  order change index "cashrcpt.idx"
  screen clear box 1 1 sch scw 0 0 no-border
  messbox(" Print Receipt? (y/n) ",1,1,1)
  if ptstr == "y"
    Background()
    messboxwait(" Insert paper for Cash Receipt ",0,1,1)
    while true
'       p1 = "cshrcv_b.dfr"
'       PrintReport(p1,p2,p3,p4,p5,p6)
  vunloadif("Xaddvarn.vws")
  remove(X_path|"Xaddvarn.*")
  data query execute "not_del.dfq" data-file X_path|"Xaddvarn" fields "[Customer_Code|Br_Fax]"
' [Var_Nr;Date;CustOrd_Name;Amount_Gross;shop;Date_To;Nr_Orders;Avg_Order;Tot_Order_Net;Tot_Order_Gross]"
  _SWIP_Crystal(Xreppath|"cshrcpt2","P",0,1,"")
'   _SWIP_Crystal(Xreppath|"cshrcpt2","S",0,1,"Cash Receipt")
'   _SWIP_Crystal(Xreppath|"$inv_1","EP",0,1
  vloadif(dpath|"cshrcvd1.vw")
      messbox(" Has Cash Receipt printed correctly? (y/n) ",1,1,1)
      if ptstr == "y"                      '  store file & exit
        return (0)
      else
        messbox(" Abandon? (y/n) ",1,1,1)
        if ptstr == "y"                      '  store file & exit
          return (0)
        else
        continue while
        end if
      end if
    end while
  end if
END FUNCTION ' PrintReceipt()
