' MEASOPTS - diary view for options to print/update/move etc.

' {U}pdate measure details added
' 15/12/14 - email routine amended to remove check for @ etc. L1373
' 15/05/15 - ADDED [VAT] field at L1818

external   vloadif() dpath scr sch scw vunloadif() messboxwait() ipath bge Background() chkstr()
external   progress() fgp bgp messbox() cpath wraptext() fentrybox() shopmask messline() city
external   userid fgi bgi base navrecs() bpopdb() entryline() chkdate() colpopup() mobfone
external   addidxrec() remove() makeidx() delstr() popuplist() findpopup()
external   strcount() colmessbox() $menu resref increment() $GEMS_RADFuncTitle
external   X_path _SWIP_Crystal() Xreppath _GEMS_Web() posncolpopup() _GEMS_Display_Message()
external   _GEMS_Input() areas _GEMS_ListBox()

public    ptstr ptval ptary[1] $stock psa $ccwcode dsa $screen ftgdate leftjob $url $neword $newcust
public    #start #end #days plist[1,1] $cust $deldate reqnnr $thisday jobnr recnr $origin $post
public    $daynr $ftrcode $dateftr $user $ftrdate $dateout $reqnnr $apptday $apptest #recs $apptdate
public	#GEMS_Cancel $options #col #col1 $locn $showrm uid $sameaddr

global     $desc custname MarkAbsent() Navigate() x i y1 m4 $msg Show_MA() $title $text rightjob z
global     DaysLeft() ReserveAppt() Absent() $dfa $key Job_Locn() #measdate $job
global     #asc ftrcode WriteApptDate() $comment EnterEmailAddress() BookReservn() $ftgdate BookMove()
global     prodtype #nritems strtcol #asc251 CheckEstimator() ClearAppt() ChkAreas() $type $sales
global     $popcol $itemtype $ccwidx $refnr $ftr_ch CheckFree() $meastime ud UpdateDetails()
global     $chckmeas #ordlen #lowerlen #upperlen #midlen $ccw ftrlist[1,2] DeliveryAddr() EnterPhones()
global     #rem #balance #minrsvn y strtrow $popstr #delcost Update1() $email y2 y3 y4
global     startdate enddate col $list #oscost $loc CheckBooked() #slotsempty UpdateReservn() ReservnUpdate()
global     $date $dow $name $a1 $a2 $a3 $a4 $a5 $a6 $a7 w $jobstr sd ChooseFitter() EnterCustName()
global     $ftrname #appt $appth delpostcode recallnr ShowDetails() lastjob NotReady() $pdf
global     deladdr1 $b1 $b2 $b3 $b4 $b5 $b6 $b7 delcity $custordstat CO_recnr $measstat ShowTimes()
global     abbrv_name title1 Show() n #prec #rec #count namelist[1,1] $idx CheckBkdDelAppt()						' L2595
global     drows pl t rec recs lc sc sym mr blen l c r2 dc pc k pg tr $apptstat $nophone MoveAppt()
global     #del_cost #rem_len #refnr $ordstat #bline $instr resvdat UpdateFile() $ma Clear2MoveAppt()
global     refcode #rem_cost $ftgnr spc $pl BookApptsMenu() $inst $mustread EnterMinInfo1() EnterMinInfo2()
global	 initbalance res ApptReservn() cr ba ReservnBooking() $mobnr $homenr $offnr c1 c2 c3
global     g fgc bgc $jobnrs #jobnrs $permit BookAppt() MoveRight() DeleteAppt() $PLACE LookRight()
global	 $ftr wr ftrassist CheckNr() ViewMeasInfo() CreateIndex()
global     nr colSf colSb Reserve() UnReserve() NewDate() FindShop() CustLocn() LookUpMeasTime()
global     rescol #reslin S_instr DrawLine() $measinst $measdesc $measpcode $measaddr1
global     $slotsrem #slotsrem #apptslots ShowMin() S_top S_RHS S_LHS WC() $stat $dely $mess ReturnToMenu()
global     $col1 $status PrntAppts() cf ts cb Setup() colIf colIb recval #needed linenr
global     #listcount poplist[1] $str_list #tline #lcol #split $selected $location lr $movedely nrslots
global     clf clb S_all #timeout ShowRm() MarkShowRm() #startcol MoveLeft() RemoveAbsent()
global     $dfa1 $ftrappts #ftrappts ftrarray[1] $day_1 $fitter bot jobdesc slotrec S_status #amount varndes
global     custaddr1  custaddr2  custcity custpostcode deladdr2 #1stbalance RemoveShowRm()
global     deladdr3 deladdr4 cust_title custcontact offtel hometel $partaddr rebkdate
global     offax mobile custaddr deladdr S_details mess5 RemoveBooking() #emptyslots vucol
global 	 cnp vo $docref chkdep job_code custcode $hometel $offtel $mobile clearvar()
global	 cr_status balancedue $ftrs #ftrs prevpcode $dayftr PrntInsts() Duplicates() StreetMap()
global     $estimator newrec invtot telnr NewJobNr() #slotsreqd RemoveUSERID() ShowStreetmap()
global  	 RebookMeasure() ReserveRebook() BookRebook() RebookBooking() CheckJobNr() CustomerAddr()


' SHWAPTE6 Status colours
'	"T" - Provisional - 13,0 Purple on Black; just holds the appt while MinInfo entered otherwise cleared
'	"N" - MiNimal - Red on White; just sufficient to hold appt; MinInfo entered cannot be printed
'	"M" - Full - Green on White; all details entered and can be printed

'Not used - MEAS_UPD only
'	"E" - Full - Green on Lt Grey; estimate sent to customer
'	"D" - Dormant - Dk Grey on Lt Grey; customer no longer interested and NOT shown on list
'	"F" - DeFerred - Dk Grey on Lt Grey; customer not interested at present but SHOW on list


MAIN
single-step off
	file unload all
	Background()
  	bot = 7
  	clb = 13
   	#timeout=60
  	clf = 10
	chkdep=0						'1=check for 40% deposit - 0=don't check

  	WC()									' close any windows

  	Setup()

  	x = Navigate()							' L125

     ReturnToMenu()

END MAIN


FUNCTION  Setup()
local cl1 cl2 r1 c1 r2 c2
  	vloadif(dpath|"aptedate.vws")
  	order change key "[Date]"
  	data find "[Date]" equal date2(days(today)+1) options ""
  	if cerror
    		data find "[Date]" equal date2(days(today)+2) options ""
    		#recs = precord
  	else
    		#recs = precord
  	end if
  	vunloadif("aptedate.vws")

  	error off
  	colSf = 14
  	colSb = 12
  	colIf = 0
  	colIb = 15
  	repaint off
  	vloadif(dpath|"shwappt3.vw")
  	vloadif(dpath|"shwapte6.vw")

   	DaysLeft()                           ' find nr of days left in APPTS file

END FUNCTION 'Setup()


FUNCTION DaysLeft()
local mess1
  	order change physical
  	data goto record last
'   	$lastdate = days([Date])   						'message "$lastdate is:"&str($lastdate)
'   	#daysleft = days($lastdate)-days(today) 			'message "#daysleft is:"&str(#daysleft)
  	data goto record record-number #recs
  	Show()
END FUNCTION  ' DaysLeft()


FUNCTION Navigate()
local x j k l nextcell sortblock c ll dm start_t $est_yn bm
  	col = 4
	$ma="N"
'    	start_t = seconds(now)
  	quiet on
  	while TRUE                           				' message "col is:"&str(col)
    		k = nextkey								' message "L132 k) is:"&str(k)
    		if k<>0
      		inchar                             		' message "k is:"&str(k)
      		quiet on

      		if k = {Up}
        			if record = 1
          			beep
          			continue while
        			end if
        			data goto record previous
         			if indirect("[A"|str(col-3)|"]") = "ÛÛÛÛÛÛÛÛÛÛ"
          			data goto record previous
        			end if
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {Down}
        			if record = records
          			beep
          			continue while
        			end if
        			data goto record next
 				if indirect("[A"|str(col-3)|"]") = "ÛÛÛÛÛÛÛÛÛÛ"
          			data goto record next
        			end if
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {Right}
        			if col = 10     ' check that cursor does not go to col 11
          			beep
          			continue while
        			end if
        			col = col + 1
        			suspendone
        			keys Right,F8
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {Left}
        			if col = 4     ' check that cursor does not go to col 3
          			beep
          			continue while
        			end if
        			suspendone
        			keys Left,F8
        			col = col - 1
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {PgDn}
		        	j = record                     ' find present pos'n
		        	j = j + 17                  '
		        	if j > records
		          	data goto record last
		        	else
          			data goto record record-number j
	     	   	end if
 				if indirect("[A"|str(col-3)|"]") = "ÛÛÛÛÛÛÛÛÛÛ"
          			data goto record next
        			end if
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {PgUp}
	     	   	j = record                     ' find present pos'n
     	   		j = j - 17                  ' go up 17 rows
	        		if j < 1                    ' ensure it does not goes above row 1
     	     		data goto record first
	        		else
     	     		data goto record record-number j
	        		end if
        			if indirect("[A"|str(col-3)|"]") = "ÛÛÛÛÛÛÛÛÛÛ"
          			data goto record previous
	        		end if	
     	   		ShowMin()
		     	start_t = seconds(now)

      		elseif k = {^End}
		        	data goto record last
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {^Home}
		          data goto record first
        			ShowMin()
        			start_t = seconds(now)

      		elseif k = {f} or k = {F}          ' go to Ftg Diary
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
  				Background()
  				repaint off
  				file unload all
  				execute "alt_appt.rf3" in-memory

      		elseif k = {p} or k = {P}          		' prints a day's Measures
				if $ma<>"N"						' message "L226 $ma<>N"
					continue while
				end if
				repaint off
				$dayftr=[DayFitter]						' message "L234 $dayftr is:"&str($dayftr)
 				$ftrcode=right($dayftr,6)				'message " L223 ftrcode is:"&str($ftrcode)
	     		$ftrname=[Nickname]
				$apptday=date2(left($dayftr,5))			'message "apptday is:"&str($apptday)
				$apptdate=left($dayftr,5)				'message "apptdate is:"&str($apptdate)
				repaint off
				CreateIndex()						' L3455
				x=PrntAppts()						' L2041
         			Show()
    				continue while

       		elseif k = {m} or k = {M}          ' Manage Measures
				if $ma<>"N"						' message "L226 $ma<>N"
					continue while
				end if
  				Background()
  				repaint off
  				file unload all
  				execute "meas_upd.rf3" in-memory

      		elseif k = {a} or k = {A}          ' book etc. appts
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
        			linenr = 0
        			ftgdate=[Date]						'message "L265 ftgdate) is:"&str(ftgdate)
        			$ftgdate=date2([Date])				'message "$ftgdate) is:"&str($ftgdate)
        			if days(ftgdate)<days(today)
					messboxwait(" You can only book for today onwards ",0,0,1)
					repaint on
					repaint
	         			Show()
 					continue while
  				end if
        			if days(ftgdate)=days(today)
					messbox(" Sure you want to book/amend a Measure for today? (y/n) ",1,1,1)
					if ptstr == "n"
						repaint on
						repaint
		         			Show()
    	 					continue while
	  				end if
  				end if
				repaint off
				$dayftr=[DayFitter]					'message "L256 $dayftr is:"&str($dayftr)
 				$ftrcode=right($dayftr,6)				'message " L223 ftrcode is:"&str($ftrcode)
				$apptday=date2(left($dayftr,5))			'message " L295 apptday is:"&str($apptday)
				$apptdate=left($dayftr,5)				'message " L296 apptdate is:"&str($apptdate)
				repaint off
         			x=BookApptsMenu()					' at L394
 				if x=-2
					repaint on
					repaint
	         			Show()
      				continue while
 				elseif x=2						' appts to move
					$ma="Y"
	         			Show_MA()
    				end if
         			clearvar()
         			Show()
				continue while

      		elseif k = {d} or k = {D}          		'
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
        			sd=ShowDetails()					'at L1670' message "print Xaptnot4"
         			Show()
				continue while

      		elseif k = {s} or k = {S}          		'
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
        			sd=ShowStreetmap()
         			Show()
				continue while


       		elseif k = {v} or k = {V}          		' MOVE appts - only used on 2nd iteration
messboxwait(" 'Move Measure Appt' module not yet in use ",0,0,1)
         			Show()
				continue while

      		elseif k = {t} or k = {T}          		'
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
				repaint off
				$dayftr=[DayFitter]					'message "$dayftr is:"&str($dayftr)
 				$ftrcode=right($dayftr,6)				'message " L223 ftrcode is:"&str($ftrcode)
	     		$ftrname=[Nickname]					'message "$ftrname) is:"&str($ftrname)
				x=CheckEstimator()					' L2817
			     if x = -1					' NOT an Estimator
					messboxwait(" Not an Estimator - re-select ",0,0,1)
					repaint on
					repaint
	         			Show()
      				continue while
    				end if
				$apptday=date2(left($dayftr,5))			'message "apptday is:"&str($apptday)
				$apptdate=left($dayftr,5)				'message "apptdate is:"&str($apptdate)
				repaint off
        			sd=ShowTimes()						'at L1670' message "print Xaptnot4"
         			Show()
    				continue while

      		elseif k = {u} or k = {U}          		'
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
        			ftgdate=[Date]						'message "L265 ftgdate) is:"&str(ftgdate)
        			$ftgdate=date2([Date])				'message "L305 $ftgdate) is:"&str($ftgdate)
        			if days(ftgdate)<days(today)
					messboxwait(" You can only update Measures for today onwards ",0,0,1)
	         			Show()
 					continue while
  				end if
        			ud=Update1()						'at L3354 ' message "L301 - option to print_SWIP_Crystal(Xreppath|Xaptnot4"
				if ud=-2
	         			Show()
 					continue while
				else
	         			Show()
 					continue while
  				end if

      		elseif k = {Esc}
				if $ma<>"N"						'message "L226 $ma<>N"
					continue while
				end if
        			return (0)
      		end if
    		end if
  	end while
END FUNCTION 'Navigate


FUNCTION Show_MA()
local y1 y2 y3 y4 y5
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
   	y1 = format(" Select Appointment slot (or first if several) and press {V} ","M94")
  	screen print 2 9 fgp bgp y1
   	y2 = format("ÿAll details entered ","M31") '19 long
   	screen print 28 9 2 7 y2					' 2,7 Green on Lt Grey
   	y4 = format(" Provisional ","M33")	'13 long
   	screen print 28 40 13 0 y4				' 13,0 Purple on BlackRed
   	y3 = format(" Incomplete information ","M30") '24 long
   	screen print 28 73 4 7 y3				' 4,7 Red on Lt Grey
   	y5 = format("ÿABSENT - working at NAMED shop - pre-MEASURES job ","M94")
  	screen print 29 9 8 7 y5
END FUNCTION 'Show_MA()


FUNCTION BookApptsMenu()						' from L284
local  m1 m2 m3 m4 m5 m6 m7 m8 m9 $ch ma m0 as cfp t3 t4 t5 t7 ru
' in "shwapte6.vw"
   	m1="ÿBookÿAppointments"
   	m3="ÿClearÿAppointments"
   	m4="ÿÿMarkÿasÿABSENT"
   	m5="ÿÿWorkingÿinÿShop"
   	m6="ÿÿÿUnlistedÿday"
	m0="ÿMoveÿAppointments"
	m7="ÿÿRe-bookÿMeasure"
	m8="ÿÿÿClearÿUSERID"

   	while true
    		x=posncolpopup(12,47,23,m1&m3&m4&m8&m5&m6&m7,"",1,0,colSf,colSb,colIf,colIb,linenr)
	  	if x = -1
    			return (-1)
	  	end if
 		linenr = ptval-1

	 	if ptstr = m1                  				'Book Appt 'message "L1619/ BookAppt"'	m1="ÿBookÿAppointments"
     		ftgdate = [Date]						''message "L359 ftgdate) is:"&str(ftgdate)
		     cf=CheckFree()                 			' L868  0=clear; -1 taken message "checkfree is:"&str(cf)
     		if cf=-1
				messboxwait(" Slot reserved - choose another ",0,0,1)
		      	return (-1)
		     end if
     		ts=ReserveAppt()						' at L630
	     	if ts = 1
			  	vloadif(dpath|"shwapte6.vw")			'vloadif(dpath|"shwapte6.vw")
	        		ftgdate = [Date]
		        	$ftrcode = right([DayFitter],6)       	'message "$ftrcode is:"&str($ftrcode)
			elseif ts = 2
			  	vloadif(dpath|"shwapte6.vw")
			     ftgdate = [Date]               		'message "jobnr is:"&str(jobnr)
     	   		$ftrcode = right([DayFitter],6)       	'message "$ftrcode is:"&str($ftrcode)
			elseif ts=-1
		      	return (-2)
      		end if
	      	return (-1)

	 	elseif ptstr = m7                  				'Book Appt 'message "L1619/ BookAppt"'	m1="ÿBookÿAppointments"
     		rebkdate = [Date]						'message "MO L476 rebkdate) is:"&str(rebkdate)
		     cf=CheckFree()                 			' L868  0=clear; -1 taken message "checkfree is:"&str(cf)
     		if cf=-1
				messboxwait(" Slot reserved - choose another ",0,0,1)
		      	return (-1)
		     end if
     		ts=RebookMeasure()						'at 871 - message " L473 ts is:"&str(ts)
	     	if ts = 1
			  	vloadif(dpath|"shwapte6.vw")			'vloadif(dpath|"shwapte6.vw")
	        		ftgdate = [Date]
		        	$ftrcode = right([DayFitter],6)       	'message "$ftrcode is:"&str($ftrcode)
			elseif ts = 2
			  	vloadif(dpath|"shwapte6.vw")
			     ftgdate = [Date]               		'message "jobnr is:"&str(jobnr)
     	   		$ftrcode = right([DayFitter],6)       	'message "$ftrcode is:"&str($ftrcode)
			elseif ts=-1
		      	return (-2)
      		end if
	      	return (-1)

	 	elseif ptstr = m8                  			'clear USERID from "broken booking"
		  	uid=indirect("[A"|str(col-3)|"]")			'' message "MO L 491 uid) is:"&str(uid)
 			if $menu="boss"
			 	ru=RemoveUSERID()						' L1750
 			else
				if uid==userid						'check that person logged in is same as USERID
				 	ru=RemoveUSERID()					' L1750
			      	return (-1)
				else
					messboxwait("You can only clear res'vns that you put on - contact Head Office to remove ",0,0,1)
		     	 	return (-1)
				end
 			end

	    	elseif ptstr = m3                     			'm3="ÿClearÿAppointments"
     		ftgdate = [Date]						'message "L415 ftgdate) is:"&str(ftgdate)
			cf=CheckBkdDelAppt()					' L2414' message "L386 cf) is:"&str(cf)
			if $job="Y"
      		 	ts=ClearAppt()                 		' at L2382		' message "ts) is:"&str(ts)
     	  		clear jobnr
	 	      	return (-1)
			elseif $job="N"
				if cf="ABSENT"					'message "ABSENT, remove whole day"
			    		messbox(" Remove ABSENT appts for this day? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveAbsent()
				      	return (-1)
					else
				      	return (-1)
					end if
				elseif cf="SHOWRM"				' message "SHOWRM, remove one slot"
			    		messbox(" Remove SHOWRM? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveShowRm()
				      	return (-1)
					else
				      	return (-1)
					end if
				elseif cf="SHEENÿ"				' message "SHOWRM, remove one slot"
			    		messbox(" Remove SHEEN? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveShowRm()
				      	return (-1)
					else
				      	return (-1)
					end if
				elseif cf="FULHAM"				' message "SHOWRM, remove one slot"
			    		messbox(" Remove FULHAM? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveShowRm()
				      	return (-1)
					else
				      	return (-1)
					end if
				elseif cf="RAYNES"				' message "SHOWRM, remove one slot"
			    		messbox(" Remove RAYNES? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveShowRm()
				      	return (-1)
					else
				      	return (-1)
					end if
				elseif cf="PUTNEY"				' message "SHOWRM, remove one slot"
			    		messbox(" Remove PUTNEY? (y/n) ",1,1,1)
					if ptstr == "Y"
		        			RemoveShowRm()
				      	return (-1)
					else
				      	return (-1)
					end if
				end if
			end if
     	 	lr=0
												' message "L405 ftgdate) is:"&str(ftgdate)
    		elseif ptstr = m4                  ' mark as ABSENT
		     $ch = ptstr
		     ftgdate = [Date]
      		if days(ftgdate) = days(today)
        			continue while
      		end if
      		cf = CheckFree()
      		if cf = -1
        			continue while
      		end if
      		if base <> "O"
        			if base <> "S"
          			if base <> "F"
            				if base <> "P"
              					if base <> "R"
                					continue while
              					end if
              				end if
          			end if
              		end if
              	end if
		     #appt   = col-3
     		$ftrname = [Nickname]
	     	$dow    = [DOW]
	      	ftgdate = [Date]
     	 	if indirect("[A"|str(col-3)|"]") = "None"
        			Absent("ABSENT","A")
		      	return (-1)
	      	else
     	   		continue while
      		end if

    		elseif ptstr = m5                  ' mark as SHOWRM
		     $ch = ptstr
		     ftgdate = [Date]
      		if days(ftgdate) = days(today)
        			continue while
      		end if
      		cf = CheckFree()
      		if cf = -1
        			continue while
      		end if
      		if base <> "O"
        			if base <> "S"
          			if base <> "F"
            				if base <> "P"
              					if base <> "R"
                					continue while
              					end if
              				end if
          			end if
              		end if
              	end if
		     #appt   = col - 3
     		$ftrname = [Nickname]
	     	$dow    = [DOW]
	      	ftgdate = [Date]
     	 	if indirect("[A"|str(col-3)|"]") = "None"
  				$locn = case base ("R","RAYNES")("S","SHEENÿ")("P","PUTNEY")("F","FULHAM")("O","FULHAM")
  				t3 = "FULHAM"
			  	t4 = "RAYNES"
  				t5 = "SHEENÿ"
	  			t7 = "PUTNEY"
	   			while true
			  		x = findpopup(11,75,19,t3&t7&t4&t5,$locn,"Choose Shop",1,0)
			   		if x = -1
						continue while
					else
	    					$SHOWRM=ptstr
						exit while
  		  			end if
				end while
        			ShowRm($showrm,"A")				' L2473
		      	return (-1)
	      	else
     	   		continue while
      		end if

    		elseif ptstr = m6                  			'm6="ÿÿÿUnlistedÿday" L2751
 			$ftrcode=right($dayftr,6)					'message " L492 ftrcode is:"&str($ftrcode)
 			$ftgdate=[Date]						' message "L493 date is:"&date2($ftgdate)
	     	$ftrname=[Nickname]						'message "$ftrname) is:"&str($ftrname)
      		x=NewDate()							' L2753

    		elseif ptstr = m0                  ' Move Appt
     		ftgdate = [Date]						'message "L415 ftgdate) is:"&str(ftgdate)
 			cf=CheckBkdDelAppt()					' L2414' message "L386 cf) is:"&str(cf)
			if len(jobnr)=0
				messboxwait(" No appoinment to move - choose another ",0,0,1)
		      	return (-2)
			else
   		  		ftgdate = [Date]						'message "L415 ftgdate) is:"&str(ftgdate)
				cf=CheckBkdDelAppt()					' L2414' message "L386 cf) is:"&str(cf)
				if $job="Y"
      		 		ts=Clear2MoveAppt()                 		' at L2453		' message "ts) is:"&str(ts)
			      	return (2)
				end if
			end if
' 			MoveAppt()							' L2408
    		end if
	end while
END FUNCTION 'BookApptsMenu()					' back to L262


FUNCTION ReserveAppt()						' from L417
  	$dfa=[DayFitter]|str(col-3)    'message "$dfa is:"&str($dfa)
  	#appt=col-3
  	$ftrname = [Nickname]
  	$ftrcode= right([DayFitter],6)   'message "$ftrcode) is:"&str($ftrcode)
  	$dow    = [DOW]
  	if indirect("[A"|str(col-3)|"]") = "None"
    		z = Reserve()                  ' at L647
		if z=-1
	    		return (-1)
		end if
	else                             ' jobnr <> "None"
    		return (-1)
  	end if
END FUNCTION 'ReserveAppt()


FUNCTION Reserve() '1=ALL ; 2=SOME ; 0=NONE resv'd; -1=Esc/NULL return
local ba
'find nr of slots to right
	#emptyslots=0
	#startcol=0
	#startcol=col
 	while true									'
	  	if indirect("[A"|str(col-3)|"]") = "None"		'if current slot is empty
 			#emptyslots=#emptyslots+1				'add 1 to #emptyslots
    			vucol=col+#emptyslots					'look right one column' message "Column nr is vucol) is:"&str(vucol)
												' x=indirect("[A"|str(vucol-3)|"]")' message "x) is:"&str(x)
			if vucol=11					' message "Column nr is vucol) is:"&str(vucol)
				#slotsempty=#emptyslots
 				exit while
			end if
		  	if indirect("[A"|str(vucol-3)|"]")<>"None"
 				#slotsempty=#emptyslots
 				exit while
 			else
 				continue while
 			end if
 		else
 			exit while
 		end if	
	end while
										' message "Max nr of slots is:"&str(#slotsempty)
  	while true
		#slotsreqd=0
    		x = fentrybox(" Enter Nr of Measure slots to book - max is"&str(#slotsempty),1,"*1#","")
    		if x = -1
	    		return (-1)
    		end if
    		#slotsreqd=val(ptstr)						'message "#slotsreqd is:"&str(#slotsreqd)
												'message "slots empty is:"&str(#slotsempty)
    		if #slotsreqd=0
 			messboxwait(" Cannot enter zero for slots req'd ",0,0,1)
       		continue while
		end if			
    		if #slotsreqd>#slotsempty
			messboxwait(" Only"&str(#slotsempty)&"slot(s) available - retry ",0,0,1)
       		continue while
		end if			
    		messbox(" Confirm"&str(#slotsreqd)|" slot(s)? (y/n) ",1,1,1)
    		if ptstr == "Y"
      		exit while
    		else
      		continue while
    		end if
  	end while										' message "Slots reqd:"&str(#slotsreqd)

	BookReservn()									' L830
	while true									' move cursor back to start
		if col>#startcol
			MoveLeft()
		else
			exit while
		end if
	end while
  	repaint off									'
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' message "L584	Job Nr has been created - no more cancellations!!! - true???"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

    	x=EnterMinInfo1()								'message " L1036 1=New; 2=Exist x) is:"&str(x)
												'1=NEW customer
												'2=Exist customer
												'-1= abandon Appts only allowed if Esc from CheckNr() at beginning
 	if x = -1										' sure you want to abandon these appts - they will be released
 	     return (-1)                          			' return to L420
 	end if										' message "L693 Slots reqd:"&str(#slotsreqd)

    	x = EnterMinInfo2()								' at L929
' 	if x = -1										' sure you want to abandon these appts - they will be released
' 	     return (-1)                          			' return to L420
' 	end if
												' message "L600 mark slotsreqd with JobNr and alter Status to N"
	repaint off
	UpdateReservn()								' L710
	while true									' move cursor back to start
		if col>#startcol
			MoveLeft()
		else
			exit while
		end if
	end while

END FUNCTION ' Reserve()


FUNCTION BookReservn() '1=ALL ; 2=SOME ; 0=NONE resv'd; -1=Esc/NULL return - ' from L578
local ba k $resref $m4 z
	#count=0
	z=0
	while true
		if indirect("[A"|str(col-3)|"]") = "None"
	    		$dfa   = [DayFitter]|str(col-3) 			'message " L784 $dfa is:"&str($dfa)
    			$appth = case #appt (1,"1st")(2,"2nd")(3,"3rd") else str(#appt)|"th"
    			ba = ReservnBooking()          			' L822 message "1=Booked; 0=Not booked:"&str(ba)' message "L607 ba) is:"&str(ba)
        		if ba = 0                      			' Appt NOT booked
    	     		repaint on
         			repaint
    			elseif ba = 1                   			' Appt BOOKED
												' message "L608 Slots reqd:"&str(#slotsreqd)
				if #slotsreqd=1					'done to refresh screen
          			mr = MoveRight()
         				return (1)                      	'Null return
          		end if
				z=#slotsreqd						'message "#slotsreqd) is:"&str(#slotsreqd)
				#count=#count+1					'message "z - slotsreqd - 1  is:"&str(z)
												'message "#count) is:"&str(#count)
				if #count=z
         	  			return (1)                      	'Null return
				end if
         			mr = MoveRight()
     			if mr=1
    	  				return (1)                      	'Null return
         			end if
      			repaint on
    				repaint
    				continue while
	    		end if
    		else
      		messbox(" Appointment already booked - 799 ",0,0,1)
      		return (-1)                      'Null return
    		end if
  	end while
END FUNCTION ' BookReservn()


FUNCTION ReservnBooking()
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			' if none - then return
    		x = messbox("MO L812 Job Nr not found ",0,0,1)
    		return (0)                         ' NOT booked
  	end if
	x="Res'v'd by"&userid&"at"&str(left(time,5))			' message "L730 is:"&str(x)
  	lock-record
    		[Job_Nr]       = "X99999"
'     		[DelAddr&Code] = left(time,5)
    		[DelAddr&Code] = x
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = "T"						' shows as RED on BLACK
  	write-record
  	repaint off
  	vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)
  	lock-record
    		dbput("[A"|str(col-3)|"]",userid)
    		dbput("[B"|str(col-3)|"]","T")
  	write-record
  	return (1)
END FUNCTION 'ReservnBooking()


FUNCTION RebookMeasure()						' from L455
  	$dfa=[DayFitter]|str(col-3)    'message "MO L873 $dfa is:"&str($dfa)
  	#appt=col-3
  	$ftrname = [Nickname]
  	$ftrcode= right([DayFitter],6)   'message "$ftrcode) is:"&str($ftrcode)
  	$dow    = [DOW]
  	if indirect("[A"|str(col-3)|"]") = "None"
    		z = ReserveRebook()                  			' at L888
		if z=-1
	    		return (-1)
		end if
	else                             ' jobnr <> "None"
    		return (-1)
  	end if
END FUNCTION 'RebookMeasure()					


FUNCTION ReserveRebook() '1=ALL ; 2=SOME ; 0=NONE resv'd; -1=Esc/NULL return
local ba
	#emptyslots=0
	#startcol=0
	#startcol=col
										' message "Max nr of slots is:"&str(#slotsempty)
   	while true
        	x = fentrybox(" Enter Job/Measure Nr ",6,shopmask,"")
        	if x = -1
          	return (-1)
        	end if
        	jobnr = ptstr
    		#slotsreqd=1
' in SHWAPTE6.vw
		x=CheckJobNr()
		if x=1
			exit while
		else	
          	return (-1)
        	end if
   	end while										' message "Slots reqd:"&str(#slotsreqd)

  	vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)

	BookRebook()									' L950 ' message "L674 Slots reqd:"&str(#slotsreqd)

	while true									' move cursor back to start
		if col>#startcol
			MoveLeft()
		else
			exit while
		end if
	end while
  	repaint off									'
END FUNCTION 'ReserveRebook()


FUNCTION BookRebook() '1=ALL ; 2=SOME ; 0=NONE resv'd; -1=Esc/NULL return - ' from L578
' re-booking prev attended measure
local ba k $resref $m4 z
	#count=0
	z=0
	while true
		if indirect("[A"|str(col-3)|"]") = "None"
	    		$dfa   = [DayFitter]|str(col-3) 			'message " L784 $dfa is:"&str($dfa)
    			$appth = case #appt (1,"1st")(2,"2nd")(3,"3rd") else str(#appt)|"th"
    			ba = RebookBooking()          			' L1032 message "1=Booked; 0=Not booked:"&str(ba)' message "L607 ba) is:"&str(ba)
        		if ba = 0                      			' Appt NOT booked
    	     		repaint on
         			repaint
    			elseif ba = 1                   			' Appt BOOKED
												' message "L608 Slots reqd:"&str(#slotsreqd)
				if #slotsreqd=1					'done to refresh screen
          			mr = MoveRight()
         				return (1)                      	'Null return
          		end if
				z=#slotsreqd						'message "#slotsreqd) is:"&str(#slotsreqd)
				#count=#count+1					'message "z - slotsreqd - 1  is:"&str(z)
												'message "#count) is:"&str(#count)
				if #count=z
         	  			return (1)                      	'Null return
				end if
         			mr = MoveRight()
     			if mr=1
    	  				return (1)                      	'Null return
         			end if
      			repaint on
    				repaint
    				continue while
	    		end if
    		else
      		messbox(" Appointment already booked - 924 ",0,0,1)
      		return (-1)                      'Null return
    		end if
  	end while
END FUNCTION ' BookRebook()


FUNCTION RebookBooking()
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			' if none - then return
    		x = messbox("MO L973 Job Nr not found ",0,0,1)
    		return (0)                         ' NOT booked
  	end if
	x="Res'v'd by"&userid&"at"&str(left(time,5))			' message "L730 is:"&str(x)
	$post=format(delpostcode,"L8")|"ÿÿ"|jobnr			'message "post) is:"&str($post)
  	lock-record									' in "bookappt.vw"
    		[Job_Nr]       =jobnr
    		[DelAddr&Code] = x
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = "N"						' Mi(N)imal info - shows as RED on LT GREY
 		[Post_Job]	= $post
  	write-record
  	repaint off
    	vloadif(dpath|"measure3.vw")
  	lock-record			       					' update CUST_ORD record
 	    	[Ftr_Code]     =$ftrcode
 		[MeasDate]	=rebkdate
 		[MeasTime]	=""
' 			[Ftrcode1]	=""
' 			[MeasStatus]	="F"							' mark MEASURE record as Delayed ftg
 	write-record
  	vloadif(dpath|"shwapte6.vw")         				'message "768 jobnr is:"&str(jobnr)
  	lock-record
    		dbput("[A"|str(col-3)|"]",$post)
    		dbput("[B"|str(col-3)|"]","N")
  	write-record
  	return (1)
END FUNCTION 'RebookBooking()


FUNCTION CheckJobNr()
  	vloadif(dpath|"measure3.vw")         				' message "jobnr is:"&str(jobnr)
	order change key "[Job_Nr]"	
  	data find "[Job_Nr]" equal jobnr options ""
  	if cerror                               			' if none - then return
    		x = messboxwait(" "|jobnr&" not found in MEASURES file ",0,0,1)
    		return (0)                         ' NOT booked
	else
    		deladdr1=[Delivery_Address_1]		'message "deladdr1 is:"&str(deladdr1)
		delpostcode=[Del_Postcode]		'message "1002 delpostcode is:"&str(delpostcode)
		if len(delpostcode)=0
messboxwait(" Postcode not found - report to HO ",0,0,1)
	    		return (0)                         ' NOT booked
 		end if
    		custname=[CustOrd_Name]				'message "1001 name is:"&str(custname)
  		messbox(custname&"at"&deladdr1|"? (y/n) ",1,1,1)
  		if ptstr == "y"
	    		return (1)                         '
		else								'if YES return 1
	    		return (0)                         ' NOT booked
 		end if
	end if
END FUNCTION 'CheckJobNr()


FUNCTION UpdateReservn()
'1=ALL ; 2=SOME ; 0=NONE resv'd; -1=Esc/NULL return
local ba k $resref $m4 w w1
	#count=0
	z=0
	while true
		w=str(col-3)								'message " L997 w) is:"&str(w)
		w1=indirect("[A"|str(col-3)|"]")				'message "w1) is:"&str(w1)
		if indirect("[A"|str(col-3)|"]") =userid
	    		$dfa   = [DayFitter]|str(col-3) ' message "$dfa is:"&str($dfa)
    			$appth = case #appt (1,"1st")(2,"2nd")(3,"3rd") else str(#appt)|"th"
    			ba = ReservnUpdate()          			'L755 - message "1=Booked; 0=Not booked:"&str(ba)' message "L607 ba) is:"&str(ba)
        		if ba = 0                      			' Appt NOT booked
    	     		repaint on
         			repaint
    			elseif ba = 1                   			' Appt BOOKED' message "L725 Slots reqd:"&str(#slotsreqd)
				if #slotsreqd=1					'done to refresh screen
          			mr = MoveRight()
         				return (1)                      	'Null return
          		end if
				z=#slotsreqd						'message "#slotsreqd) is:"&str(#slotsreqd)
				#count=#count+1					'message "z - slotsreqd - 1  is:"&str(z)
												'message "#count) is:"&str(#count)
				if #count=z
         	  			return (1)                      	'Null return
				end if
  				if w<7
    					w=w+1
    					if col>10     							' check that cursor does not go to col 11
      					beep
      					return (1)
    					end if
    					col=col+1									'message "L 1486 Moving Right col) is:"&str(col)
    					suspendone
    					keys Right,F8
			  	end if
      			repaint on
    				repaint
    				continue while
	    		end if
    		else
      		messbox(" Appointment already booked - 1024 ",0,0,1)
      		return (-1)                      			'Null return
    		end if
  	end while
END FUNCTION ' UpdateReservn()


FUNCTION ReservnUpdate()
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			'   if none - then return
    		x = messbox(" MO L1038 - Job Nr not found ",0,0,1)
    		return (0)                         			' NOT booked
  	end if
	x="Res'v'd by"&userid&"at"&str(left(time,5))			' message "L657 is:"&str(x)
	$post=format(delpostcode,"L8")|"ÿÿ"|jobnr			' message "L755 $post) is:"&str($post)
  	lock-record									' in "bookappt.vw"
    		[Job_Nr]       =jobnr
'     		[DelAddr&Code] = left(time,5)
    		[DelAddr&Code] = x
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = "N"						' Mi(N)imal info - shows as RED on LT GREY
 		[Post_Job]	= $post
  	write-record
  	repaint off
  	vloadif(dpath|"shwapte6.vw")         				'message "768 jobnr is:"&str(jobnr)
  	lock-record
    		dbput("[A"|str(col-3)|"]",$post)
    		dbput("[B"|str(col-3)|"]","N")
  	write-record
  	return (1)
END FUNCTION 'ReservnUpdate()


FUNCTION MoveLeft()
	if col=4     ' check that cursor does not go to col 11
   		beep
    		return (1)
	end if
												' message "moving Left L775"
	col=col-1
	suspendone
    	keys Left,F8
  	return (0)
END FUNCTION ' MoveLeft()


FUNCTION EnterMinInfo1()								' from L586 - gets customer name - NO cancellations!!
local s1 s2 $continue y1 y2							' s1 s2 s3 s4 s5 s6 s7
	while true									'new job nr
		x=CheckNr()								'L1557
            				' L1439
     	if x = -2									'message "L882 #slotsreqd) is:"&str(#slotsreqd)
			x=RemoveBooking()						' L1509
			return (-1)							' only allowed if Esc from CheckNr() at beginning

		elseif x=2								'exist order & therefore exist customer in CUST_ORD
			$newcust="N"
         		deladdr1=[Delivery_Address_1]
         		deladdr2=[Delivery_Address_2]
			delcity=[Del_City]
			delpostcode=[Del_Postcode]
     		custcode  = [Customer_Code]
     		custname  = [CustOrd_Name]				' message "L720 name is:"&str(custname)
    			vloadif(dpath|"customer.vws")
			custaddr1=filelookup([customer.Customer_Code],[customer.Address_1],custcode)	'
			$hometel=filelookup([customer.Customer_Code],[customer.Home_Tel],custcode)	'
			$offtel=filelookup([customer.Customer_Code],[customer.Office_Tel],custcode)	'
			$mobile=filelookup([customer.Customer_Code],[customer.Mobile/Other_Nr],custcode)	'
			$email=filelookup([customer.Customer_Code],[customer.Email_Addr],custcode)	'message "894 $email) is:"&str($email)
    			vunloadif("customer.vws")
			exit while
 		else
 			$neword="Y"
	    	end if

	 	while true								' new JOBNR already created
			s1="ÿÿSurnamesÿ"
			s2="ÿPostÿCodesÿ"
			x = popuplist(11,47,15,s1&s2,"{Esc} to re-select",1,0)	'message "L210 x is:"&str(x)
			if x=-1
				continue while	
			end if
			$continue=ptstr					' message "L721 $continue is:"&str($continue)
	  		if $continue=""
				continue while	
			end if
  			if $continue=s1					'SURNAMES
      			x = fentrybox(" Enter Customer's Name (or 1st SEVEN letters if existing customer)",35,"","")
	      		if x = 0
     	   			if ptstr = ""
          				continue while
	        			end if
      			elseif x = -1
         				continue while
	      		end if
    				custname=proper(ptstr)
				repaint off
    				vloadif(dpath|"custsel4.vw")
    				order change key [Abbrv_Name]
		    		abbrv_name = proper(left(custname,7))
    				data find "[Abbrv_Name]" equal abbrv_name options ""

    			elseif $continue=s2					' POSTCODE
											' message "L858 custname is:"&str(custname)
				custpostcode=""
				custname=""
				while true
x=fentrybox(" Enter FULL customer Postcode ",8,"AU*7{[A-Za-z1234567890\ ]U}",custpostcode)	'message "x) is:"&str(x)
					if x = 0
						custpostcode=ptstr	'message "custpostcode) is:"&str(custpostcode)
						if len(custpostcode)<6
							messboxwait(" Must enter FULL postcode ",0,0,1)
							continue while
						else
				      		exit while
						end if
					else
						messboxwait("Incorrect format"&custpostcode&"re-enter",0,0,1)
						continue while
					end if
				end while
				vloadif(dpath|"custsel4.vw")
' order sort now dictionary "codename" fields "[Postcode;Customer_Name]" ascending
    				order change key "[Postcode]"
    				data find "[Postcode]" equal custpostcode options "gw"
			end if

		    	repaint on
    			repaint
    			ptval=0
    			y1 = format(" CUSTOMERS ALREADY HELD ON FILE ","M89")
			if $continue=s1					' SURNAME
 		    		y2 = format(" {A}dd"&chr(34)|custname|chr(34)|" - {S}elect - any other key to retry ","M89")
			else
 		    		y2 = format(" {S}elect - {Esc} to retry name/postcode ","M89")
			end if
			screen print 4 11 fgp bgp y1
			screen print 28 11 fgp bgp y2
	 		ptval = navrecs()					'message "L885 ptval) is:"&str(ptval)
   			if ptval = {S} or ptval = {s}				' message " L1187 EXISTING customer"
    				if (deleted)
         				messboxwait(" Deleted record - choose another ",0,0,1)
          			continue while
     	   		end if
    				$newcust = "N"
 				custcode = [Customer_Code]
    				custname = [Customer_Name]
        			abbrv_name = [Abbrv_Name]
    	   			if len([Address_1]) <> 0       ' Same name
	     	    		$msg=custname&"of"&[Address_1]|"?" 'message "len($msg)) is:"&str(len($msg))
    		     		messbox($msg,1,1,1)
         				if ptstr == "y"
						deladdr1=[Address_1]
         					deladdr2=[Address_2]
						delcity=[City/Town]
						delpostcode=[Postcode]
     		     		custcode  = [Customer_Code]
	          	  		custaddr1 = [Address_1]
     	       			$hometel=[Home_Tel]
          	  			$offtel=[Office_Tel]
						$mobile=[Mobile/Other_Nr]
						$email=[Email_Addr]
		         		else
				    		y2 = format(" {A}dd"&chr(34)|custname|chr(34)|" - {S}elect highlight - {R}etry - {Esc} exits ","M88")
          				screen print 28 11 fgp bgp y2
            				continue while
	          		end if
			    		repaint off
					vunloadif("custsel4.vw")
					vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)
	        			return (2)						' EXIST customer rtn to L688
        			else                           	'if no [Address_1]
					deladdr1=""
     				deladdr2=""
					delcity=""
					delpostcode=""
     		     	custcode=""
	          	  	custaddr1=""
     	       		$hometel=""
          	  		$offtel=""
					$mobile=""
					vunloadif("custsel4.vw")
	        			return (2)						' EXIST customer
        			end if

' 	      	elseif ptval = {R} or ptval = {r} 	' retry SURNAME/POSTCODE
' 				Background()
' 				continue while

	      	elseif ptval = {A} or ptval = {a}			' NEW customer
     	   		x=messbox(" Add"&chr(34)|custname|chr(34)&"to Customers? (y/n)",1,1,1)
	        		if ptstr ! "y"
     	     		$newcust = "Y"
				else
					Background()
     				exit while
         			end if
	        		repaint off

				$mobile=""
				$hometel=""
				$offtel=""
				deladdr1=""
         			deladdr2=""
				delcity=""
				delpostcode=""
     		    	custcode =""
	            	custaddr1=""
				$email=""
				vunloadif("custsel4.vw")
				vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)
        			return (1)						' NEW customer
			else
 				continue while
      		end if
			exit while
		end while									' for choice of SURNAME/POSTCODE
		exit while
	end while
END FUNCTION ' EnterMinInfo1()						' at L575


FUNCTION EnterMinInfo2()								' at L575
' message "L1038 jobnr is:"&str(jobnr)
' message " L1273 $newcust) is:"&str($newcust)
	if $newcust="Y"
	 	custcode=jobnr									'message "L986 custcode) is:"&str(custcode)
	end if
' message "$neword) is:"&str($neword)
' message "custname) is:"&str(custname)
' message "custcode) is:"&str(custcode)
' MUST enter min of
'	full customer name - DONE
' message "L888 deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "delcity) is:"&str(delcity)
' message "delpostcode) is:"&str(delpostcode)
' message "custcode) is:"&str(custcode)
' message "custaddr1) is:"&str(custaddr1)
' message "$hometel) is:"&str($hometel)
' message "$offtel) is:"&str($offtel)
' message "$mobile) is:"&str($mobile)

	x=DeliveryAddr()   								' L1092
	
	x=EnterPhones()								' L1287

	x=EnterEmailAddress()							' at L690

' message " L1289 deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "delcity) is:"&str(delcity)
' message "delpostcode) is:"&str(delpostcode)
' message "custcode) is:"&str(custcode)
' message "custaddr1) is:"&str(custaddr1)
' message "$hometel) is:"&str($hometel)
' message "$email) is:"&str($email)
' message "$mobile) is:"&str($mobile)

' RECORDS to be created
' 	if $newcust="Y"
' create skeleton CUSTOMER record using jobnr as custcode
' 	end if

' message " L1077 new entry in MEASURES"
' message "jobnr) is:"&str(jobnr)
' message "custname) is:"&str(custname)
' message "custcode) is:"&str(custcode)
' message "deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "delpostcode) is:"&str(delpostcode)
' message "delcity) is:"&str(delcity)
' message "#measdate) is:"&str(#measdate)
' message "$ftgdate) is:"&str($ftgdate)
' message "ftgdate) is:"&str(ftgdate)
' message "#slotsreqd) is:"&str(#slotsreqd)
' message "$estimator) is:"&str($estimator)
' message "$ftrcode) is:"&str($ftrcode)
' message "$ftrname) is:"&str($ftrname)
' $ftrname)
' message "creating new MEASURE record"

'***********************************************************
'	NEW MEASURES record
'***********************************************************
  	vloadif(dpath|"measures.vws")
  	data enter lock								' create new entry in MEASURES
    		[Job_Nr]            =jobnr
    		[CustOrd_Name]      =custname
    		[Abbrv_Name]        =left(custname,7)
		[Customer_Code]	=custcode
    		[Delivery_Address_1]=deladdr1
		[Delivery_Address_2]=deladdr2
    		[Updated_By]        =userid
    		[Last_Update]       =today
		[Del_Postcode]		=delpostcode
    		[Branch]            =left(jobnr,1)
		[Del_City]		=delcity
		[MeasStatus]		="N"
		[MeasDate]		=$ftgdate
		[MeasSlots]		=str(#slotsreqd)
		[FtrName]			=$ftrname
		[Ftr_Code]		=$ftrcode
  	write-record
	if $neword="Y"									'update new CUST_ORD skeleton order inc [Order_Status]="N"
		vloadif(dpath|"cust_ord.vws")					'message "CO_recnr) is:"&str(CO_recnr)
		data goto record record-number CO_recnr			' message "jobnr) is:"&str(jobnr)
  		$type  = case left(jobnr,1)("C","S")("R","S")("S","S")("F","S")("P","F")("W","H")("T","H")("Y","H")
	  	$sales = case left(jobnr,1)("C","X")("R","R")("S","S")("F","F")("P","P")("W","W")("T","T")("Y","Y")
		abbrv_name = proper(left(custname,7))
  		lock-record
			[Customer_Code]	=custcode
			[CustOrd_Name]		 = custname
			[Abbrv_Name]		 = abbrv_name
    			[SalesAnalysis]      = $sales
	    		[Type_Branch]        = $type
    			[Delivery_Address_1] = deladdr1
' 			[SameAddr]=$sameaddr
			[Delivery_Address_2] = deladdr2
			[Del_Postcode]		 = delpostcode
' 			[City/Town]		 = delcity
			[Del_City]		 = delcity
    			[Invoice_Total]      = 0
	    		[Net_Invoice]        = 0
	    		[Balance_Due]        = 0
    			[Customer_Code]      = custcode
    			[Updated_By]         = userid
	    		[Last_Update]        = today
    			[Order_Status]       = "M"	
    			[Completed]          = "N"
	  	write-record
	end if

	vloadif(dpath|"customer.vws")						' message "CO_recnr) is:"&str(CO_recnr)
 	if $newcust="Y"								' create min CUSTOMER rec
		custcode=jobnr								'message "1383 custcode) is:"&str(custcode)
		custcity=delcity							'message "custcity) is:"&str(custcity)
		custpostcode=delpostcode						'message "custpostcode) is:"&str(custpostcode)
		custaddr1=deladdr1							'message "1388 apperas as CITY custaddr1) is:"&str(custaddr1)
		custaddr2=deladdr2							'message "custaddr2) is:"&str(custaddr2)
		abbrv_name = proper(left(custname,7))

'***********************************************************
'	new CUSTOMER record
'***********************************************************
		data enter lock							' create new entry in CUSTOMER
          	[Branch]   	=left(custcode,1)
 			[City/Town]	=custcity
  			[Postcode]	=custpostcode
 			[Address_1]	=custaddr1
 			[Address_2]	=custaddr2
			[Email_Addr]	 =$email
          	[Customer_Name] =custname
          	[Abbrv_Name]    =abbrv_name
          	[Customer_Code] =custcode
          	[Profile]       ="A"
          	[Credit_Status] ="C"
			[Home_Tel]	 =$hometel
			[Mobile/Other_Nr]=$mobile
			[Office_Tel]	 =$offtel
          	[Updated_By]    =userid
          	[Last_Update]   =today
          	[ChkAddr]       ="Y"
        	write-record
	else										' update existing record
		data find "[Customer_Code]" equal custcode options "gw"		'check custcode exists
  		lock-record
			[Mobile/Other_Nr]=$mobile
			[Home_Tel]=$hometel
			[Email_Addr]=$email
		write-record
	end if
  	vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)
END FUNCTION ' EnterMinInfo2()


FUNCTION DeliveryAddr()   							'message "enter deladdr using deladdr"
	if len(deladdr1)=0
		deladdr1=""
	end if
   	while true
    		x = fentrybox(" Enter Measure/Delivery Address - Line 1 ",35,"",deladdr1)
    		if x = 0
      		deladdr1 = proper(ptstr)
      		exit while
    		end if
  	end while

	if len(deladdr2)=0
		deladdr2=""
	end if
   	while true
    		x = fentrybox(" Enter Measure/Delivery Address - Line 2 ",35,"",deladdr2)
    		if x = 0
      		deladdr2 = proper(ptstr)
      		exit while
    		end if
  	end while

	if len(delcity)=0
		delcity="LONDON"
	end if
  	while true
    		x = fentrybox(" Enter Measure/Delivery Town/City ",20,city,delcity)
    		if x = 0
      		delcity=ptstr
      		exit while
    		end if
  	end while

	if len(delpostcode)=0
		delpostcode=""
	end if
 	while true

'  		x = fentrybox(" Enter Measure/Delivery Postcode ",8,"AU*7{[A-Za-z1234567890\ ]U}",delpostcode)	'message "x) is:"&str(x)
'  		if x = 0
'  			delpostcode=ptstr						'message "custpostcode) is:"&str(custpostcode)
'  		else
'         		continue while
'  		end if
'     		exit while
' 		while true

 		x=fentrybox(" Enter FULL Delivery Postcode ",8,"AU*7{[A-Za-z1234567890\ ]U}",delpostcode)	'message "x) is:"&str(x)
		if x = 0
			delpostcode=ptstr	'message "delpostcode) is:"&str(delpostcode)
			if len(delpostcode)<6
				messboxwait(" Must enter FULL Delivery postcode ",0,0,1)
				continue while
			else
		    		messbox(" Confirm"&str(delpostcode)|"? (y/n) ",1,1,1)
		    		if ptstr == "Y"
		      		exit while
		    		else
		      		continue while
		    		end if
			end if
		else
			messboxwait("Incorrect format"&delpostcode&"re-enter",0,0,1)
			continue while
		end if
  	end while
 	if $newcust="Y"
		messbox(" Is this the Customer's Home Address as well? (y/n) ",1,1,1)
		if ptstr == "y"
			custaddr1=deladdr1
			custaddr2=deladdr2
			custcity=delcity
			custpostcode=delpostcode
			$sameaddr="Y"
		else	
			custaddr1=""
			custaddr2=""
			custcity=""
			custpostcode=""
			$sameaddr="N"
			CustomerAddr()
		end if	
' 		return (1)
 	end if
END FUNCTION ' DeliveryAddr()


FUNCTION CustomerAddr()			' called from L257
'   	while true
' 		if len(cust_title)>0
'       		x = fentrybox(" Customer name and title ",35,"",cust_title)
'       		cust_title =ptstr
' 	    		exit while
' 		end if
'     		y = popuplist(10,20,18,"Mr Mrs Mrÿ&ÿMrs Miss Ms Other LtdÿCo","Select",1,0)
'     		if ptstr = "Other"
'       		while true
'         			x=fentrybox(" Enter title ",20,"",cust_title)
'         			if x = 0
'           			cust_title = ptstr
'           			exit while
'         			end if
'       		end while
'     		elseif ptstr = "LtdÿCo"
'       		cust_title = ""
'       		exit while
'     		else
'       		cust_title = ptstr
'       		x = fentrybox(" Enter Forename or Initial ",35,"","")
'       		cust_title = cust_title&proper(ptstr)
'     		end if
'     		exit while
'   	end while
'   	while true
' '     		y1 = format(" ","M70")
' '     		screen print 21 5 15 1 y1
'     		x = fentrybox(" Contact name (if different to customer name) ",45,"",custcontact)
'     		if x = 0
'       		custcontact = ptstr
'       		exit while
'     		end if
'   	end while
	
	Background()
  	while true
    		x = fentrybox(" Customer's Address - 1st line ",35,"",custaddr1)' message "x is:"&str(x)
    		if x = 0
      		custaddr1 = proper(ptstr)
      		exit while
    		end if
  	end while

  	while true
    		x = fentrybox(" Customer's Address - 2nd line (NOT Town or City) ",35,"",custaddr2)' message "x is:"&str(x)
    		if x = 0
      		custaddr2 = proper(ptstr)
      		exit while
    		end if
  	end while

'   	while true
'     		y1 = format(" Select Town/City ","M24")
'     		screen print 10 35 19 1 y1
' 		c1="Notÿlisted"
' 		c2="LONDON"
' 		c3="RICHMOND"
' 		c4="KINGSTON-UPON-THAMES"
' 		c5="TWICKENHAM"
' 		c6="KEW"
'     		y = popuplist(11,35,18,c1&c2&c3&c4&c5&c6,"",1,0) ' message "y) is:"&str(y)
'     		if ptstr = c1

' message "SO7 L1105 custcity) is:"&str(custcity)
	if len(custcity)=0
		custcity="LONDON"
	end if
	while true
    		x=fentrybox(" Customer's Town/City NOT county ",20,city,custcity)
	    	if x = 0
     		if len(ptstr)=0
     			continue while
	     	end if
     		custcity=ptstr
     		exit while
		end if
  	end while
'     		else
'       		custcity=ptstr
'       		exit while
'     		end if
'     		exit while
'   	end while
' message "custcity) is:"&str(custcity)

' message "SO7 L1121 custpostcode) is:"&str(custpostcode)
   	while true
    		x=fentrybox(" Customer's Postcode (NOT County!) ",8,"AU*7{[A-Za-z1234567890\ ]U}",custpostcode)
    		if x=0
' 			if custcity="LONDON"
	    		custpostcode = ptstr						'message "custpostcode) is:"&str(custpostcode)
' 			y=CheckPostCode()
' 			vunloadif("post1.vws")
' 				if y=1				'correct
' 	      			exit while
' 				elseif y=0			'postcode not in "LONDON"
' 					messboxwait(custpostcode&"is NOT a LONDON code - check CITY or POSTCODE ",0,0,1)
' 	     	 		continue while
' 				end if
		end if
  		exit while
'     		else
'       		continue while
'     		end if
	end while
' message "city is correct for postcode"
END FUNCTION 'CustomerAddr()


FUNCTION EnterEmailAddress()							' from L470
local j r i n x $mess
' message " L1309 $email) is:"&str($email)
	if len($email)=0
		$email=""
	end if
	while true
   		while true
    			x = fentrybox(" EMAIL address - {Esc} if none ",50,"",$email)
	    		if x = 0
 			     $email=ptstr
       			exit while
	    		else
 			     $email = ""
     	  		return (0)
    			end if
	   	end while

		messbox(" Confirm"&$email|"? (y/n) ",1,1,1)
   		if ptstr == "n"
			continue while
		else
			exit while
		end if

' temporary rem out until keyboard mapping corrected
' 		if left($email,1)="@"
' 			messboxwait(" Invalid email address - 1st char is @ ",0,0,1)
' 			continue while
' 		end if

' 		if right($email,1)="."
' 			messboxwait(" Invalid email address - last char is .  ",0,0,1)
' 			continue while
' 		end if

' 		if right($email,1)="@"
' 			messboxwait(" Invalid email address - last char is @  ",0,0,1)
' 			continue while
' 		end if

' 		for j=1 to len($email)
' 			r = mid($email,j,1)						' message "r is:"&str(r)
' 			if r=chr(64)
' 				exit while
' 			end if
' 		end for
' 		messboxwait(" Invalid email address format - no @ sign ",0,0,1)
	end while
END FUNCTION 'EnterEmailAddress()


FUNCTION EnterPhones()
	$nophone="N"									' no number yet entered
  	while true
    		y1 = format(" Phone ","M10")
    		screen print 10 50 15 1 y1
 		c1="Mobile"
		c2="Home"
		c3="Office"
    		y = popuplist(11,50,18,c1&c2&c3,"",1,0) ' message "y) is:"&str(y)
		if y=-1
			if $nophone="N"
				messboxwait(" Must enter at least 1 'phone number ",0,0,1)
				continue while
			else
				exit while
			end if
		end if
    		if ptstr = c1
    			while true
      			if $mobile="N/P"
        				$mobile=""
      			end if
      			x=fentrybox(" Mobile 'phone number - {Esc} if none ",12,mobfone,$mobile)
      			if x = 0
        				if ptstr = ""
          				$mobile = ""
        				else
						if len(ptstr)=0
							continue while
						end if
          				$mobile = ptstr
          				$nophone = "Y"
						$mobnr="Y"
          				exit while
        				end if
      			elseif x = -1
        				$mobile = ""
         				exit while
      			end if
    			end while

    		elseif ptstr = c2
			while true
    				if $hometel = "N/P"
    					$hometel = ""
   				end if
    				x = fentrybox(" Home 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",$hometel)
    				if x = -1
    					$hometel = ""
    					exit while
				end if
    				if x = 0
   					if ptstr = "0"
         					$hometel = ""
    					else
						if len(ptstr)=0
							continue while
						end if
        					$hometel = ptstr
         					$nophone = "Y"
						$homenr="Y"
         					exit while
    					end if
    				end if
			end while

    		elseif ptstr = c3
    			while true
      			if $offtel = "N/P"
        				$offtel = ""
      			end if
      			x = fentrybox(" Office 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",$offtel)
      			if x = 0
        				if ptstr = "0"
          				$offtel = ""
        				else
						if len(ptstr)=0
							continue while
						end if
          				$offtel = ptstr
          				$nophone = "Y"
						$offnr="Y"
          				exit while
        				end if
      			elseif x = -1
        				$offtel = "N/P"
         				exit while
      			end if
    			end while
    		end if
'     		exit while
  	end while
END FUNCTION 'EnterPhones()


FUNCTION RemoveBooking()								'message "L1509 RemoveBooking()"
  	vloadif(dpath|"shwapte6.vw")         				' message "jobnr is:"&str(jobnr)
	repaint on
	repaint
	for i=1 to #slotsreqd							'
	   	#appt=col-3
		x=indirect("[A"|str(col-3)|"]")				'message "user in field is:"&str(x)
		if indirect("[A"|str(col-3)|"]")=userid
	    		$dfa=[DayFitter]|str(col-3) ' message "$dfa is:"&str($dfa)
  			repaint off
		  	vloadif(dpath|"bookappt.vw")
		  	order change key "[DFA]"
  			data find "[DFA]" equal $dfa options ""
	  		if cerror                               '   if none - then return
    				x = messbox(" Job Nr not found - L1461 ",0,0,1)
	    			return (0)                         ' NOT booked
  			end if
  			lock-record
    				[Job_Nr]       = "None"
			     [DelAddr&Code] = ""
			     [Entered_By]   = userid
				[Date_Altered] = today
    				[Time]         = now
    				[N_name]       = ""
    				[Status]       = ""
			write-record
  			repaint off
  			vloadif(dpath|"shwapte6.vw")         ' message "jobnr is:"&str(jobnr)
  			lock-record
    				dbput("[A"|str(col-3)|"]","None")
    				dbput("[B"|str(col-3)|"]","")
  			write-record
    			mr=MoveRight()
		end if
	end for
END FUNCTION ' RemoveBooking()


FUNCTION MoveRight()								'message " L1715 #appt) is:"&str(#appt)
  	if #appt < 7
    		#appt=#appt+1
    		if col=10     							' check that cursor does not go to col 11
      		beep
      		return (1)
    		end if
    		col=col+1									'message "L 1486 Moving Right col) is:"&str(col)
    		suspendone
    		keys Right,F8
  	end if
  	return (0)
END FUNCTION ' MoveRight()


FUNCTION CheckNr()                     					' called from 916
'enters JobNr (if Known); searches for existing or creates new complete or creates holding appt
  	jobnr = ""
  	repaint off
  	newrec = 0
  	invtot = 0
  	telnr = ""
  	deladdr1 = ""
    	while true									' create new jobnr and find existing customer or enter new customer
		x=NewJobNr()								' L1620
 		if x=0
			$neword="Y"
			exit while
  		elseif x = -2								' create abandoned - go back and remove appts
			return (-2)
		end if
     end while
												' message "L1503 create new JobNr"
  	vloadif(dpath|"cust_ord.vws")
	custname=userid&"temp entry"
												' message "jobnr) is:"&str(jobnr)
												' message "custname) is:"&str(custname)
  	data enter lock								' create new, brief entry in CUST_ORD
 		[Job_Nr]       = jobnr
    		[Branch]       = left(jobnr,1)
	    	[CustOrd_Name] = custname
'     		[Abbrv_Name]         = left(custname,7)
		[Order_Status]	="N"
		[VAT]		="S"	
    		[Date_Of_Order]= today
	    	[Updated_By]   = userid
    		[Last_Update]  = today
	write-record
	CO_recnr=precord
	return (0)
END FUNCTION ' CheckNr()								' back to 536


FUNCTION ApptReservn()
  	$dfa = [DayFitter]|str(col-3)    ' message "$dfa is:"&str($dfa)
  	#appt   = col - 3
  	$ftrname = [Nickname]
  	$ftrcode= right([DayFitter],6)   'message "$ftrcode) is:"&str($ftrcode)
  	$dow    = [DOW]
  	if indirect("[A"|str(col-3)|"]") = "None"
    		z=BookReservn()							' L701
    		if z=-1                      ' Esc
      		return (-1)
    		elseif z = 1                   ' NULL return
      		return (1)
    		end if
  	else                             ' jobnr <> "None"
    		return (-1)
  	end if
END FUNCTION 'ApptReservn()


FUNCTION NewJobNr()									'from L1571
local leftjob currec s1 s2 s3 s4 s5 s6 s7
	while true
  		s1 = "Warehouse"
  		s3 = "Fulham"
  		s4 = "Raynes"
  		s5 = "Sheen"
  		s7 = "Putney"
    		leftjob=Job_Locn()
    		if x = -1
			messbox(" Abandon entry and release appt slots? (y/n) ",1,0,1)
			if ptstr == "y"
     			return (-2)
			else
     			continue while
			end if
 	  	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
		messbox(" This will create a new order"&jobnr&"- continue? (y/n) ",1,1,1)
		if ptstr == "y"
     		return (0)
		else
 	   		messbox(" Abandon entry and release appt slots? (y/n) ",1,0,1)
 			if ptstr == "y"
      			return (-2)
 			else
      			continue while
 			end if
		end if
 	end while
END FUNCTION 'NewJobNr()


FUNCTION Job_Locn()									' from L1500
local  s1 s2 s3 s4 s5 s6 s7
  	$locn = case base ("R","Raynes")("S","Sheen")("T","Trade")("P","Putney")("F","Fulham")("O","Warehouse")
  	s1 = "Warehouse"
  	s3 = "Fulham"
  	s4 = "Raynes"
  	s5 = "Sheen"
  	s7 = "Putney"
   	while true
	  	x = findpopup(10,49,19,s3&s7&s4&s5&s1,$locn,"Base Shop",1,0)
   		if x = -1
' 			Background()
       		return (-1)
    		end if
    		$place = ptstr
	     return (left($place,1))
   	end while
END FUNCTION 'Job_Locn()


FUNCTION EnterCustName()								' from L484
 	x=FindShop()								'message "leftjob) is:"&str(leftjob)
   	if x = -1
		return (-1)
     end if
	while true
    		x = fentrybox(" Enter Customer's Name (or 1st SEVEN letters if existing customer)",35,"","")
    		if x = 0
    			if ptstr = ""
         			continue while
    			end if
    			exit while
    		elseif x = -1
			return (-1)
     	end if
    	end while
    	custname=proper(ptstr)
    	abbrv_name = proper(left(custname,7))
	repaint off
	x=vloadif(dpath|"prcmeas2.vw")				'find Branch measures which are Status <> "N"
	order change key "[Branch]"
	data query execute "meassel4.dfq" index "meassel4.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Branch]=leftjob
' and
' [MeasStatus]<>"N"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror
		messboxwait(" No measures yet entered ",0,0,1)
		return (-1)
	end if
	order sort now dictionary "meassel5.idx" fields "[Abbrv_Name]" ascending
	if cerror
		messboxwait(" sort failed at L611 ",0,0,1)
		return (-1)
	end if
  	while true
    		x=bpopdb("prcmeas2",7,"fi"&abbrv_name,"[VU_ALL]","L88","[Abbrv_Name]","L0","[Job_Nr]",11,11,28,100,"",0)
    		if x = -1
			return (-1)
    		else
			jobnr=ptstr
		     exit while
    		end if
  	end while						' message " L572 jobnr is:"&str(jobnr)
	return (0)
END FUNCTION 'EnterCustName()							back to L495


FUNCTION BookAppt()									' called from L502
   	$apptstat = "M" '??????
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               '   if none - then return
    		x = messboxwait(" $dfa not found ",0,0,1)
    		Show()
    		return (0)                         ' NOT booked
  	end if
  	lock-record                          ' Book appt on screen
    		[Job_Nr]       = jobnr
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = $apptstat
    		[Date_Code]    = str(date2([Date])&[Fitter_Code])
  	write-record
  	repaint off
  	vloadif(dpath|"prcmeas2.vw")
  	lock-record			  ' MEASURES
     	[MeasDate]=ftgdate
     	[MeasTime]=$meastime
  	write-record
  	vunloadif("prcmeas2.vw")
  	repaint off
  	vloadif(dpath|"shwapte6.vw")						'   vloadif(dpath|"shwapte6.vw")
  	lock-record
    		dbput("[A"|str(col-3)|"]",jobnr)
    		dbput("[B"|str(col-3)|"]",$apptstat)
  	write-record
  	return (0)
END FUNCTION ' BookAppt() ' return to L458


FUNCTION ShowTimes()								' from L301
local $t1 $t2 $t3 $t4 $t5 $t6 $t7 $buff j $mt
	$options=""
	$buff="/"
	for j=1 to 7
	 	#count=1
  		jobnr = ""
   		$dfa = [DayFitter]|str(j)        				'message "$dfa is:"&str($dfa)
  		y=indirect("[A"|str(j)|"]")					'message "L 1818 y) is:"&str(y)
		if y="None"
			$mt="No appointment"|$buff
		elseif y="ABSENT"
			$mt=y|$buff
		elseif y="SHOWRM"
			$mt=y|$buff
		elseif y="BNKHOL"
			$mt=y|$buff
		elseif len(y)=6
			$mt=" Appt from old system "|$buff
		else
			jobnr=right(y,6)						'message "L1831 jobnr) is:"&str(jobnr)
			x=LookUpMeasTime(jobnr)
			if len($meastime)=0
				$meastime="Not entered"
			end if
			$mt=$meastime|$buff
		end if
		$options=$options|$mt						' message "L1836 $options is:"&str($options)
	 	#count=#count+1
	end for
	$title	= "Times of Measures for"&date2(today)
	$text	= "{Enter} or {Esc} to Return"
	vunloadif("measures.vws")
	x=_GEMS_ListBox($title,$text,$options,0,47)
END FUNCTION 'ShowTimes()							


FUNCTION LookUpMeasTime(jn)
	vloadif(dpath|"measures.vws")
	$meastime=filelookup([measures.Job_Nr],[measures.MeasTime],jn)	'message "meastime is:"&str($meastime)
  	vloadif(dpath|"shwapte6.vw")
END FUNCTION 'LookUpMeasTime()


FUNCTION  ShowDetails()						'from L287
local $chk $mess m
  	jobnr = ""
  	$dfa = [DayFitter]|str(col-3)        		'message "$dfa is:"&str($dfa)
  	y=indirect("[A"|str(col-3)|"]")			'message "L 1866 y) is:"&str(y)
	if y="None"
		messboxwait(" Blank appointment - no details ",0,0,1)
    		return (0)
	elseif y="ABSENT"
    		return (0)
	elseif y="SHOWRM"
    		return (0)
	elseif y="FULHAM"
    		return (0)
	elseif y="SHEENÿ"
    		return (0)
	elseif y="RAYNES"
    		return (0)
	elseif y="PUTNEY"
    		return (0)
	elseif y="BNKHOL"
    		return (0)
	elseif len(y)=6
		messboxwait(" Appt from old system - no details available ",0,0,1)
    		return (0)
	end if

	jobnr=right(y,6)								'message "jobnr) is:"&str(jobnr)
	$measpcode=left(y,8)							'message "L1933 $measpcode) is:"&str($measpcode)
  	$measstat = indirect("[B"|str(col-3)|"]") 			'message " L1895 $measstat is:"&str($measstat)
	if $measstat="N"
		repaint off
		vloadif(dpath|"measure3.vw")
     	order change key "[Job_Nr]"
		data find "[Job_Nr]" equal jobnr options ""
		custname=[CustOrd_Name]						' message "name is:"&str(custname)
		$measaddr1=[Delivery_Address_1]				' message "$measaddr1 is:"&str($measaddr1)
		messboxwait(jobnr|"/"|custname&"at"&$measaddr1&"- requires updating ",0,0,1)
    		return (0)
	end if

  	$chk = mid(jobnr,2,1)                    'message "$chk is:"&str($chk)
	repaint off
	vloadif(dpath|"measure3.vw")
     order change key "[Job_Nr]"
	data find "[Job_Nr]" equal jobnr options ""
	custname=[CustOrd_Name]						' message "name is:"&str(custname)
	$measinst=[Instructions]						' message "$measinst) is:"&str($measinst)
	$measdesc=[Description]						' message "$measdesc) is:"&str($measdesc)				
	$mustread=[MustRead]						' message "$mustread is:"&str($mustread)
	$meastime=[MeasTime]						' message "$meastime is:"&str($meastime)
	$measaddr1=[Delivery_Address_1]				' message "$measaddr1 is:"&str($measaddr1)
	vunloadif("measure3.vw")
  	vloadif(dpath|"shwapte6.vw")						'   vloadif(dpath|"shwapte6.vw")
	x=ViewMeasInfo()						' view Info for any Measure - diff colours for "N" and "M" status
    	return (0)
END FUNCTION 'ShowDetails()					' back to L276


FUNCTION  ShowStreetmap()						'from L287
local $chk $mess m
  	jobnr = ""
  	$dfa = [DayFitter]|str(col-3)        		'message "$dfa is:"&str($dfa)
  	y=indirect("[A"|str(col-3)|"]")			'message "L 1866 y) is:"&str(y)
	if y="None"
		messboxwait(" Blank appointment - no details ",0,0,1)
    		return (0)
	elseif y="ABSENT"
    		return (0)
	elseif y="SHOWRM"
    		return (0)
	elseif y="FULHAM"
    		return (0)
	elseif y="SHEENÿ"
    		return (0)
	elseif y="RAYNES"
    		return (0)
	elseif y="PUTNEY"
    		return (0)
	elseif y="BNKHOL"
    		return (0)
	elseif len(y)=6
		messboxwait(" Appt from old system - no details available ",0,0,1)
    		return (0)
	end if
	jobnr=right(y,6)								'message "MO L2258 jobnr) is:"&str(jobnr)
	$measpcode=left(y,8)							'message "MO L2260 $measpcode) is:"&str($measpcode)
  	$measstat = indirect("[B"|str(col-3)|"]") 			'message " L1895 $measstat is:"&str($measstat)
	StreetMap($measpcode)
    	return (0)
END FUNCTION 'ShowStreetmap()						'from L287


FUNCTION ViewMeasInfo()								' from L2818 & L1744
local $text1 $text2 #unused $text3
 	if $measstat="N"
 		$text3="(Needs Updating)"
 	else
 		$text3=""
 	end if

	if len($measdesc)=0
		$measdesc="Not entered"
	end if	
	if len($measinst)=0
		$measinst="Not entered"
	end if	
	if len($meastime)=0
		$meastime="Not entered"
	end if	
	if len($measdesc)=0
		$measdesc="Not entered"
	end if	
	if len($mustread)=0
		$mustread="Not entered"
	end if	
 	$GEMS_RADFuncTitle=jobnr|"/"|custname|","&$measaddr1|","&$measpcode
	$text1=format(left($measdesc|"                                                                                                                    ",200)&"- Time:"&upper($meastime),"L250")
	$text2=$measinst&"/"&upper($mustread)
	_GEMS_Display_Message($text1,$text2,#unused)
	$GEMS_RADFuncTitle=""
END FUNCTION 'ViewMeasInfo()


FUNCTION UnReserve()							' from L2392
local cod cag
	$dfa=[DayFitter]|str(col-3)						' message "$dfa) is:"&str($dfa)
  	$dateout=[Date]                   					'message "$dateout is:"&str($dateout)
  	while true
    		repaint off
	    	vloadif(dpath|"findmeas.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)
	    	end if
     	$appth = case #appt (1,"1st")(2,"2nd")(3,"3rd") else str(#appt)|"th"
     	x = messbox(" Cancel"&jobnr&"as"&$ftrname|"'s"&$appth&"appointment on"&$dow&date2(ftgdate)|"? (y/n) ",1,1,1)
     	if ptstr == "Y"                    			' message "ftgdate is:"&date2(ftgdate)
       		x = DeleteAppt()                 			' at L2054			1=deleted; 0=NOT deleted; 2=ALL deleted
	          return (0)
		else
      		return (-1)
    		end if
  	end while
END FUNCTION 'UnReserve()							' return L1226


FUNCTION DeleteAppt()								'from L754
local nextnr
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	if lr=0
    		order change key "[DFA]"
    		data find "[DFA]" equal $dfa options "F"
    		if cerror                               		'if none - then return
      		x=messbox(" Job Nr not found - L2055 ",1,0,0)
      		return (0)
    		end if
    		lr=1
  	elseif lr=1
    		data goto record next
    		nextnr = [Job_Nr]
    		if nextnr <> jobnr
      		return (2)                         		' NONE booked/ALL appts deleted
    		end if
  	end if
  	lock-record
    		[Job_Nr]       ="None"
    		[DelAddr&Code] =""
    		[Entered_By]   =userid
    		[Date_Altered] =today
    		[Time]         =now
    		[N_name]       =""
    		[Status]       =""
		[Post_Job]	=""
  	write-record

  	repaint off
  	vloadif(dpath|"shwapte6.vw")
  	lock-record
    		dbput("[A"|str(col-3)|"]","None")
    		dbput("[B"|str(col-3)|"]","")
  	write-record
  	repaint off
  	vloadif(dpath|"bookappt.vw")
     order change key "[Job_Nr]"
     data query execute "job_reqn.dfq" index "job_reqn.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ QUERY is:  [Job_Nr] = jobnr                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	if cerror                               '   if none - then return
	    	vloadif(dpath|"findmeas.vw")
    		lock-record			       					' update CUST_ORD record
      		[Fitting_Date] =blank
	     	[Ftr_Code]     =""
			[MeasDate]	=blank
			[MeasTime]	=""
			[Ftrcode1]	=""
			[MeasStatus]	="F"							' mark MEASURE record as Delayed ftg
	    	write-record
 	end if
    	return (2)
END FUNCTION ' DeleteAppt()


FUNCTION CheckFree()
	x=indirect("[A"|str(col-3)|"]")			'message " L2100 x) is:"&str(x)
  	if indirect("[A"|str(col-3)|"]") = "None"
    		return (0)
  	else
    		return (-1)
  	end if
END FUNCTION ' CheckFree()


FUNCTION PrntAppts()								' L254
local  m1 m2 m3 m4 m5 m6 m7 m8 m9 $ch ma m0 as cfp
  	vloadif(dpath|"prtmeas4.vw")
   	order change index "estdate1.idx"
 	x=PrntInsts(1,1,1)									' L2158
     if x=1
    		Show()
    		return (1)                         ' NOT ready
     end if
END FUNCTION ' PrntAppts()


FUNCTION PrntInsts(a,b,c)
local  m1 m2 m3 m4 m5 m6 m7 m8 m9 $ch ma m0 as cfp
' message " L2055 check loaded views"
   	x=NotReady()									'L2238
  	if x=1										' NOT ready
  	  	vunloadif("prtmeas4.vw")     					' was PRTMEAS2.vw
  		return (1)
  	end if
  	vunloadif("prtmeas4.vw")
 	vloadif(dpath|"prtmeas5.vw")
  	order change index "estdate1.idx"
  	vunloadif("X_meas1.vws")
  	x=remove(X_path|"X_meas1.*")
	data query execute "not_del.dfq" Smart4 X_path|"X_meas1" fields "[JobNumber|Nickname]"
	if a=1										'message "Printing Attend List"
    		_SWIP_Crystal(Xreppath|"Xmeasur0","S",0,1,"")		'message "L2172 should have printed Xmeasur0"
	end if
  	vunloadif("prtmeas3.vw")

   	vloadif(dpath|"prtmeas4.vw")							' based on dpath|APPNTMNT
   	order change index "estdate1.idx"

	x=Duplicates()

   	vloadif(dpath|"measure3.vw")
   	order change index "insts2prt.idx"
    	remove(X_path|"X_nar_a.*")
    	data query execute "not_del.dfq" Smart4 X_path|"X_nar_a" fields "[Job_Nr|MeasAddr1]"
    	vunloadif("X_nar_a.vws")
	if b=1
    		_SWIP_Crystal(Xreppath|"Xaptnot4","S",0,1,"")
	end if
	if c=1
    		_SWIP_Crystal(Xreppath|"Xaptnot5","S",0,1,"")
	end if
    	vunloadif("X_nar_a.vws")
    	vunloadif("X_nar_b.vws")
  	vunloadif("prtmeas5.vw")
  	vunloadif("prtmeas4.vw")
  	vunloadif("prtmeas3.vw")
  	vunloadif("measure3.vw")
END FUNCTION ' PrintInsts()


FUNCTION NotReady()									' [Status] must be BLANK or M; T or N are not ready
local z z1 $ready
' already in dpath|"prtmeas2.vw")
	$ready=""
  	data goto record first							'$jobnrs=[JobNumber]
	$ready=[MeasStatus]
	if $ready=""
		$ready=""
	end if
  	data goto record next
  	for i = 2 to 7                 'create text string of Job Nrs
    		x = chkstr([MeasStatus],$ready)
		z=len([MeasStatus])
		z1=[MeasStatus]							'message "length of"&z1&"is:"&str(z)
		if [MeasStatus]=""
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		end if
    		if x = -1
      		$ready=$ready|[MeasStatus]				' message "L2262 $ready) is:"&str($ready)
    		end if
    		data goto record next
  	end for										'message "De-duplicated job nrs are:"&str($ready)
												'message "L2279 $ready) is:"&str($ready)
	if $ready=""
    		x = messboxwait(" No measure appointments to print out ",0,0,1)
	  	vunloadif("measures.vws")
		return (1)
	end if
  	x=strcount($ready)                  				'message "ptval is:"&str(ptval)
  	#jobnrs = ptval								' message "#jobnrs) is:"&str(#jobnrs)
												' message " L2291 $ready is:"&str($ready)

	if $ready!"T"
	  	messbox(" This day has some Temporary appts - continue anyway? (y/n) ",1,0,1)
  		if ptstr == "n"
	  		vunloadif("measures.vws")
			return (1)
    		end if

	elseif $ready!"N"
	  	messbox(" Some Measures have NOT had details updated - continue? (y/n) ",1,0,1)
  		if ptstr == "n"
	  		vunloadif("measures.vws")
			return (1)
    		end if
	end if
  	vunloadif("measures.vws")
END FUNCTION ' NotReady()


FUNCTION Duplicates()
local z z1 jobnr1										' already in dpath|"prtmeas4.vw")
	$jobnrs=""
  	data goto record first
	$jobnrs=[JobNumber]
	if $jobnrs="None"
		$jobnrs=""
	elseif $jobnrs="ABSENT"
		$jobnrs=""
' 	elseif $jobnrs="SHEEN"
' 		$jobnrs=""
' 	elseif $jobnrs="FULHAM"
' 		$jobnrs=""
' 	elseif $jobnrs="SHOWRM"
' 		$jobnrs=""
' 	elseif $jobnrs="SHOWRM"
' 		$jobnrs=""
' 	elseif $jobnrs="SHOWRM"
' 		$jobnrs=""
' 	elseif $jobnrs="SHOWRM"
' 		$jobnrs=""
' 	elseif $jobnrs="SHOWRM"
' 		$jobnrs=""
	end if
  	data goto record next
  	for i = 2 to records                 				'create text string of Job Nrs
    		x = chkstr([JobNumber],$jobnrs)
		z=len([JobNumber])
		z1=[JobNumber]								'message "length of"&z1&"is:"&str(z)
		if [JobNumber]="None"
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		elseif [JobNumber]="ABSENT"
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		end if
    		if x = -1
      		$jobnrs = $jobnrs&[JobNumber]
    		end if
    		data goto record next
  	end for										' message "De-duplicated job nrs are:"&str($jobnrs)
  	x=strcount($jobnrs)                  				'message "ptval is:"&str(ptval)
  	#jobnrs = ptval								' message "#jobnrs) is:"&str(#jobnrs)
												'
	if $jobnrs!"X99999"
		messboxwait(" Cannot print - this day has some Temporary appt's ",0,0,1)
		return (1)
	end if

  	vloadif(dpath|"measures.vws")
  	order change key "[Job_Nr]"
  	x=remove("insts2prt.idx")					'message "remove x is:"&str(x)
  	x=makeidx("measures","insts2prt","0",3)     		'message "makeidx x is:"&str(x)
 	order change key "[Job_Nr]"
  	for i = 1 to #jobnrs
    		jobnr1 = group($jobnrs,i)						'message "jobnr1 is:"&str(jobnr1)
    		data find "[Job_Nr]" equal jobnr1 options "g"
		if cerror										'message jobnr1&"not found in MEASURES"
		else
	    		x = addidxrec("insts2prt.idx",precord,7)    'message "addidxrec x is:"&str(x)
		end if
  	end for
	order change index "insts2prt.idx"
  	vunloadif("measures.vws")
END FUNCTION ' Duplicates()


FUNCTION ShowMin()
local y1 y2 y3 y4 y5
   	y1 = format(" {P}rint - {T}imes - {A}ppts - {U}pdate - {M}anage - {D}etail - {F}itting - {S}treetmap {Esc} ","M94")
  	screen print 2 9 fgp bgp y1
   	y2 = format("ÿAll details entered ","M31") '19 long
   	screen print 28 9 2 7 y2					' 2,7 Green on Lt Grey
   	y4 = format(" Provisional ","M33")	'13 long
   	screen print 28 40 13 0 y4				' 13,0 Purple on BlackRed
   	y3 = format(" Incomplete information ","M30") '24 long
   	screen print 28 73 4 7 y3				' 4,7 Red on Lt Grey
   	y5 = format("ÿABSENT or working at NAMED shop ","M94")
  	screen print 29 9 8 7 y5
END FUNCTION ' ShowMin()


FUNCTION WC()
  	error off
  	while true
    		window close
    		if cerror
      		exit while
    		end if
  	end while
END FUNCTION  ' WC()


FUNCTION Show()
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
	ShowMin()
END FUNCTION ' Show()


FUNCTION StreetMap(dpc)
local $p_code
     $p_code=dpc              						'message "$p_code) is:"&str($p_code)
     $p_code=replacestr($p_code," ","+")  				'message "$p_code) is:"&str($p_code)
     $url="www.streetmap.co.uk/streetmap.dll?postcode2map?"|$p_code|chr(32)
     _GEMS_Web($url)
END FUNCTION ' StreetMap()


FUNCTION RemoveAbsent()
  	repaint off
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
 	while true
		$dfa = [DayFitter]|str(col-3)
		$comment =""
   		x = MarkAbsent("None","")
    		if x = 0
    			repaint on
    			repaint
    			if col = 10     ' check that cursor does not go to col 11
         			return (1)
    			end if
    			col = col + 1
    			suspendone
    			keys Right,F8
    		end if
 	end while
END FUNCTION ' RemoveAbsent()


FUNCTION Absent(ms,st)
  	repaint off
  	jobnr = ms
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
 	while true
  		if indirect("[A"|str(col-3)|"]") = "None"
    			$dfa = [DayFitter]|str(col-3)
    			$comment =""
      		x = MarkAbsent(ms,st)
      		if x = 0
        			repaint on
        			repaint
        			if col = 10     ' check that cursor does not go to col 11
          			return (1)
        			end if
        			col = col + 1
        			suspendone
        			keys Right,F8
      		end if
  		else
    			messbox(" Appointment already booked - 2493 ",0,0,1)
    			return (1)
  		end if
 	end while
END FUNCTION ' Absent()


FUNCTION MarkAbsent(ms1,st)
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			'   if none - then return
    		return (0)
  	end if
  	lock-record
    		[Job_Nr]       = ms1
    		[DelAddr&Code] = $comment
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = st
		[Post_Job]     = ms1
  	write-record

  	vloadif(dpath|"shwapte6.vw")
  	lock-record
    		dbput("[A"|str(col-3)|"]",ms1)
    		dbput("[B"|str(col-3)|"]",st)
  	write-record

  	if #appt < 7
    		#appt = #appt + 1
    		if col = 10   								' check that cursor does not go to col 11
      		beep
      		return (0)
	     end if
    		col = col + 1
    		suspendone
    		keys Right,F8
  	else
    		return (0)
  	end if
  	return (1)
END FUNCTION ' MarkAbsent()


FUNCTION RemoveShowRm()
  	repaint off
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
    	$dfa = [DayFitter]|str(col-3)
    	$comment =""
     x = MarkShowRm("None","")
     if x = 0
     	repaint on
     	repaint
     	if col = 10     							' check that cursor does not go to col 11
        		return (1)
     	end if
     	col = col + 1
     	suspendone
     	keys Right,F8
     end if
END FUNCTION ' RemoveShowRm()


FUNCTION ShowRm(ms,st)
  	repaint off
  	jobnr = ms
  	vloadif(dpath|"shwapte6.vw")
  	repaint on
  	repaint
	while true
  		if indirect("[A"|str(col-3)|"]") = "None"
    			$dfa = [DayFitter]|str(col-3)
			messbox(" Mark this appt as"&ms|"? (y/n) ",1,1,1)
			if ptstr == "y"
	    			$comment =""
     			x = MarkShowRm(ms,st)
	     		if x = 0
     				repaint on
	     			repaint
     				if col = 10     						' check that cursor does not go to col 11
          				return (1)
	        			end if
		        		col=col+1
     		   		suspendone
        				keys Right,F8
		      	end if
  			else
    				messbox(" Appointment already booked - 2587 ",0,0,1)
	    			return (1)
	  		end if
  		else
    			messbox(" Appointment already booked - 2591 ",0,0,1)
    			return (1)
  		end if
	end while
END FUNCTION ' ShowRm()


FUNCTION MarkShowRm(ms1,st)						' from L569
  	repaint off
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			'   if none - then return
    		return (0)
  	end if
  	lock-record
    		[Job_Nr]       = ms1
    		[DelAddr&Code] = $comment
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[N_name]       = $ftrname
    		[Status]       = st
    		[Post_Job]     = ms1
  	write-record
  	vloadif(dpath|"shwapte6.vw")
  	lock-record
    		dbput("[A"|str(col-3)|"]",ms1)
    		dbput("[B"|str(col-3)|"]",st)
  	write-record
  	if #appt < 7
    		#appt = #appt + 1
    		if col = 10     ' check that cursor does not go to col 11
      		beep
      		return (0)
    		end if
    		col=col+1
    		suspendone
    		keys Right,F8
  	else
    		return (0)
  	end if
	return (1)
END FUNCTION ' MarkShowRm()


FUNCTION ClearAppt()								' L330
	#appt   = col - 3
  	$ftrname = [Nickname]
	$dow    = [DOW]
  	if $menu = "offc" or $menu = "shop"  '
    		resvdat = left(jobnr,1)
		x = ChkAreas(resvdat,areas)      'message "x is:"&str(x)
    		if x = -1   '0=found in string; -1= NOT found
     		messbox(" You can only cancel your own shop's app'ts! Contact HO (ref 1) ",0,0,1)
     		return (-1)
		end if
  	end if
	z = UnReserve()								'at L2017 '1=ALL ; 2=SOME ; 0=NONE resv'd
    	Show()
  	vloadif(dpath|"shwapte6.vw")
END FUNCTION 'ClearAppt()					' back to L330


FUNCTION Clear2MoveAppt()
' move to leftmost APPT with this Jobnr
	while true
		if col=4
			exit while
		end if
  		y=indirect("[A"|str(col-3-1)|"]")			'message "L2490 next left is:"&str(y)
		$job=right(y,6)						'message "$job is:"&str($job)
		if $job=jobnr
			MoveLeft()
		else
			exit while
		end if
	end while

  	#appt   = col - 3
	$ftrname = [Nickname]
  	$dow    = [DOW]
	if $menu = "offc" or $menu = "shop"  '
		resvdat = left(jobnr,1)
    		x = ChkAreas(resvdat,areas)      'message "x is:"&str(x)
		if x = -1   '0=found in string; -1= NOT found
   			messbox(" You can only cancel your own shop's app'ts! Contact HO (ref 1) ",0,0,1)
    			return (-1)
    		end if
	end if
  	$dateout=[Date]                   					'message "$dateout is:"&str($dateout)
  	while true
    		repaint off
	    	vloadif(dpath|"findmeas.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)
	    	end if
     	$appth = case #appt (1,"1st")(2,"2nd")(3,"3rd") else str(#appt)|"th"
     	x = messbox(" Cancel"&jobnr&"as"&$ftrname|"'s"&$appth&"appointment on"&$dow&date2(ftgdate)|"? (y/n) ",1,1,1)
     	if ptstr == "Y"                    			' message "ftgdate is:"&date2(ftgdate)
       		x=DeleteAppt()                 			' at L1369			1=deleted; 0=NOT deleted; 2=ALL deleted
		  	vloadif(dpath|"shwapte6.vw")
			#col1=col+1
   			rightjob=indirect("[A"|str(#col1)|"]")    			'message "leftjob is:"&str(leftjob)
			if rightjob=jobnr
				MoveRight()				
				continue while
			else
				return (2)	' to proceed to Move Appt
		   	end if
		else
      		return (-1)
    		end if
  	end while

    	Show()
  	vloadif(dpath|"shwapte6.vw")
END FUNCTION 'Clear2MoveAppt()


FUNCTION LookRight()				' returns 1 if last appt of day
								' 		2 if
local rightj1                          ' message "$job is:"&str($job)
  	repaint off
  	if col = 10					' right hand edge - cannot create anymore
    		return (1)
  	end if
  	rightj1 = indirect("[A"|str(col-4)|"]")    'message "leftj1 is:"&str(leftj1)	
	if rightj1 = $job
  		if "[B"|str(col-3)|"]" <> "C"
    			if "[B"|str(col-3)|"]" <> "P"
      			vloadif(dpath|"bookappt.vw")
      			order change key "[DFA]"
      			data find "[DFA]" equal $dfa options ""
      			if cerror                               '   if none - then return
        				x = messbox(" $dfa not found ",0,0,1)
        				Show()
        				return (0)                         ' NOT booked
      			end if
      			lock-record
        				[Status] = "C"
      			write-record
  				vloadif(dpath|"shwapte7.vw")
      			lock-record
        				dbput("[B"|str(col-3)|"]","C")
      			write-record
      			return (0)
    			end if
  		end if
	else
  		return (1)
	end if
END FUNCTION  ' LookRight()


FUNCTION MoveAppt()								' L330
local ba
	$dayftr=[DayFitter]					'message "$dayftr is:"&str($dayftr)
	$ftrcode=right($dayftr,6)				'
  	#appt   = col - 3
	$ftrname = [Nickname]
  	$dow    = [DOW]
	if $menu = "offc" or $menu = "shop"  '
		resvdat = left(jobnr,1)
    		x = ChkAreas(resvdat,areas)      'message "x is:"&str(x)
		if x = -1   '0=found in string; -1= NOT found
    			messbox(" You can only cancel your own shop's app'ts! Contact HO (ref 1) ",0,0,1)
    			return (-1)
    		end if
	end if
'confirm nr of appts to move
message "navigate to new slot"
' confirm date/time/nr slots
' if YES - enter temp slots (as done in Initial)
'		
'find nr of slots to right
	#emptyslots=0
	#startcol=0
	#startcol=col
 	while true									'
	  	if indirect("[A"|str(col-3)|"]") = "None"		'if current slot is empty
 			#emptyslots=#emptyslots+1				'add 1 to #emptyslots
    			vucol=col+#emptyslots					'look right one column' message "Column nr is vucol) is:"&str(vucol)
												' x=indirect("[A"|str(vucol-3)|"]")' message "x) is:"&str(x)
			if vucol=11					' message "Column nr is vucol) is:"&str(vucol)
				#slotsempty=#emptyslots
 				exit while
			end if
		  	if indirect("[A"|str(vucol-3)|"]")<>"None"
 				#slotsempty=#emptyslots
 				exit while
 			else
 				continue while
 			end if
 		else
 			exit while
 		end if	
	end while
										' message "Max nr of slots is:"&str(#slotsempty)
  	while true
		#slotsreqd=0
    		x = fentrybox(" Enter Nr of Measure slots to book - max is"&str(#slotsempty),1,"*1#","")
    		if x = -1
	    		return (-1)
    		end if
    		#slotsreqd=val(ptstr)						'message "#slotsreqd is:"&str(#slotsreqd)
												'message "slots empty is:"&str(#slotsempty)
    		if #slotsreqd=0
 			messboxwait(" Cannot enter zero for slots req'd ",0,0,1)
       		continue while
		end if			
    		if #slotsreqd>#slotsempty
			messboxwait(" Only"&str(#slotsempty)&"slot(s) available - retry ",0,0,1)
       		continue while
		end if			
    		messbox(" Confirm"&str(#slotsreqd)|" slot(s)? (y/n) ",1,1,1)
    		if ptstr == "Y"
      		exit while
    		else
      		continue while
    		end if
  	end while										' message "Slots reqd:"&str(#slotsreqd)

	BookMove()									' L686

	while true									' move cursor back to start
		if col>#startcol
			MoveLeft()
		else
			exit while
		end if
	end while
  	repaint off									'
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' message "L584	Job Nr has been created - no more cancellations!!! - true???"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
' 	z = UnReserve()								'at L2017 '1=ALL ; 2=SOME ; 0=NONE resv'd

    	Show()
  	vloadif(dpath|"shwapte6.vw")
END FUNCTION 'MoveAppt()					' back to L330


FUNCTION BookMove()									'


END FUNCTION '	BookMove()									'


FUNCTION ChkAreas(r,a)   '  '0=found in string; -1= NOT found
local m n				' message "r is:"&str(r)	' message "a is:"&str(a)
  	n=len(a)										' message "n is:"&str(n)
  	for i = 1 to n
    		m=mid(a,i,1)									' message "m is:"&str(m)
    		if m=r
      		return (0)
    		end if
  	end for
  	return (-1)
END FUNCTION ' ChkAreas()


FUNCTION CheckBkdDelAppt()						' L2595
	clear x
	clear y
	clear jobnr
	clear $job	
  	x=indirect("[B"|str(col-3)|"]")      		' message "indirect B# (status) is:"&str(x)
  	y=indirect("[A"|str(col-3)|"]")			' message "L2606 y) is:"&str(y)
	if len(y)>6
		jobnr=right(y,6)
		$job="Y"
' 	elseif indirect("[A"|str(col-3)|"]") = "None"
' 		jobnr=y
'      return (-1)
'      elseif indirect("[A"|str(col-3)|"]") = "SUNDAY"
'     return (-1)
'   elseif indirect("[A"|str(col-3)|"]") = "BNKHOL"
'     return (-1)
'   elseif indirect("[A"|str(col-3)|"]") = "ABSENT"
'     return (-1)
'   elseif indirect("[A"|str(col-3)|"]") = "SHOWRM"
'     return (-1)
'    	elseif indirect("[A"|str(col-3)|"]") = "ÛÛÛÛÛÛÛÛÛÛ"
'     return (-1)
'   	else
'     		return (0)
	else
		$job="N"
  	end if
												' message "L2706 y) is:"&str(y)
	return (y)
END FUNCTION ' CheckBkdDelAppt()					


FUNCTION CheckBooked()
  	x=indirect("[B"|str(col-3)|"]")      				'message "x is:"&str(x)
  	if indirect("[B"|str(col-3)|"]") = "A"
    		return (0)
  	elseif indirect("[B"|str(col-3)|"]") = "R"
    		return (0)
  	end if
  	y=indirect("[A"|str(col-3)|"]")
  	#asc=asc(right(y,1))                 				'message "#asc is:"&str(#asc)
  	if #asc > 57 or #asc < 48            				'message "Not number"
    		return (-1)                        			'NOT a job nr
  	else
    		return (0)
  	end if
END FUNCTION ' CheckBooked()


FUNCTION NewDate()									' from 490
local  datecode newdate daytitle #appts $daynr lday
  	lday = filemax([Date])                				'message "lday is:"&date2(lday)
   	x = ChooseFitter()
   	if x = -1
    		return(-1)
   	end if
   	while true
     	x = fentrybox(" Enter Date of Appointment ",10,"##\/##\/####",date2($ftgdate))
     	if x = 0
       		newdate = ptstr
       		if chkdate(newdate,1) = -1
         			messbox(" Incorrect date - re-enter ",0,0,1)
         			continue while
       		end if
    		else
       		Show()
       		return (-1)
     	end if
     	if days(newdate)-days(today) > 90
       		messbox(" Cannot book more than 90 days in advance - re-enter ",0,0,1)
       		continue while
     	end if
     	exit while
   	end while

												'create records in APPNTMNT.VWS
   	vloadif(dpath|"shwappt3.vw")
   	$daynr = str(days(newdate))        				'message "L2783\ $daynr is:"&str($daynr)
   	$dfa = $daynr|ftrcode|str(1)         				'message "$dfa is:"&str($dfa)
   	data find "[DFA]" equal $dfa options "g"
   	if cerror
     	daytitle = "None"
     	vloadif(dpath|"creatapp.vw")
     	for #appts = 1 to 7            				'for each appt continue creating
       		$dfa = $daynr|ftrcode|str(#appts)			'message "$dfa is:"&str($dfa)
       		data enter lock
         			[Fitter_Code] = ftrcode
         			[Date]        = newdate
         			[Day_Nr]      = $daynr
         			[DFA]         = $dfa
         			[Job_Nr]      = daytitle
         			[Appointment_Order] = str(#appts)
         			[Date_Code]   = str(date2(newdate)&ftrcode)
         			[Post_Job]    = daytitle
       		write-record
     	end for
   	else											' message "L2801\ $ftrname is:"&str($ftrname)
     	messbox(" Appointments already exist for"&$ftrname&"on this Date ",0,0,1)
     	Show()
     	return (-1)
   	end if

   	$date = newdate
   	$dow  = left(dayname(newdate),3)
   	$dfa  = left($dfa,11)
   	$name = ftrassist
   	$a1 = daytitle
   	$a2 = daytitle
   	$a3 = daytitle
   	$a4 = daytitle
   	$a5 = daytitle
   	$a6 = daytitle
   	$a7 = daytitle

   	DrawLine()									'L2837

   	$a1 = daytitle
   	WriteApptDate()
 	vloadif(dpath|"shwapte6.vw")						' message "#prec) is:"&str(#prec)
  	repaint on
  	repaint
END FUNCTION ' NewDate()


FUNCTION DrawLine()
local $a1 $b1
  	vloadif(dpath|"aptedate.vws")
  	$a1="ÛÛÛÛÛÛÛÛÛÛ"
  	$b1   = "S"
  	data enter lock
    		[Date]     = blank
    		[DOW]      = blank
    		[DayFitter]= blank
    		[Nickname] = blank
    		[A1]       = $a1
    		[A2]       = $a1
    		[A3]       = $a1
    		[A4]       = $a1
    		[A5]       = $a1
    		[A6]       = $a1
    		[A7]       = $a1
    		[B1]       = $b1
    		[B2]       = $b1
    		[B3]       = $b1
    		[B4]       = $b1
    		[B5]       = $b1
    		[B6]       = $b1
    		[B7]       = $b1
  	write-record
  	vloadif(dpath|"shwappt4.vw")
END FUNCTION ' DrawLine()


FUNCTION WriteApptDate()
local $shwdate
' message "$name) is:"&str($name)
' message "$a1) is:"&str($a1)
' message "$a2) is:"&str($a2)
' message "$a3) is:"&str($a3)
' message "$a4) is:"&str($a4)
' message "$a5) is:"&str($a5)
' message "$a6) is:"&str($a6)
' message "$a7) is:"&str($a7)
' message "$b1) is:"&str($b1)
' message "$b2) is:"&str($b2)
' message "$b3) is:"&str($b3)
' message "$b4) is:"&str($b4)
' message "$b5 is:"&str($b5)
' message "$b6 is:"&str($b6)
' message "$b7 is:"&str($b7)
' message "$location is:"&str($location)
' message "$shwdate is:"&str($shwdate)

	$shwdate = left(date1($date),6)
  	vloadif(dpath|"aptedate.vws")
  	data enter lock
    		[Date]     = $date
    		[Shw_Date] = $shwdate
    		[DOW]      = $dow
    		[DayFitter]= $dfa
    		[Nickname] = $name
    		[A1]       = $a1
    		[A2]       = $a2
    		[A3]       = $a3
    		[A4]       = $a4
    		[A5]       = $a5
    		[A6]       = $a6
    		[A7]       = $a7
    		[B1]       = $b1
    		[B2]       = $b2
    		[B3]       = $b3
    		[B4]       = $b4
    		[B5]       = $b5
    		[B6]       = $b6
    		[B7]       = $b7
    		[Location] = $location
  	write-record
  	vloadif(dpath|"shwappt4.vw")
END FUNCTION 'WriteApptDate()


FUNCTION ChooseFitter()
  	repaint off
  	vloadif(dpath|"ftr_list.vws")
  	data query execute "chs_ftr.dfq" index "ftrs1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Ftr_Est]="E"
' and
' not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
  	order sort now dictionary "nickname.idx" fields "[Nickname]" ascending
  	while true
    		x=bpopdb("ftr_list",5,"","[Nickname]","L8","[Fitter_Name]","L0","[Fitter_Code]",3,84,20,94,"",0)
    		if x = -1
      		repaint off
      		vunloadif("ftr_list.vws")
      		Show()
      		return(-1)
    		else
      		ftrcode   = ptstr                      'message "ptstr) is:"&str(ptstr)
      		ftrassist = [Nickname]
     		$ftrname=[Nickname]
      		$location = [Location]
    			exit while
    		end if
  	end while
  	repaint off
  	screen shortrestore dsa
  	vunloadif("ftr_list.vws")
END FUNCTION  ' ChooseFitter()


FUNCTION FindShop()
local s1 s2 s3 s4 s5 s6 s7
	while true
  		s1 = "Warehouse"
'   		s2 = "Trade"
  		s3 = "Fulham"
  		s4 = "Raynes"
  		s5 = "Sheen"
  		s7 = "Putney"

  		if base="O"                         			'choice of Warehouse etc
    			leftjob=CustLocn()
    			if leftjob=-1
	      		return (-1)
      		end if
	
	  	elseif base="F"
    			while true
      			x = popuplist(8,57,15,s3&S7&s4&s5&s1,"Find measure",1,0)
      			if x = -1
		      		return (-1)
	      		end if
     	 		$place = ptstr						'messbox(" Confirm"&upper($place)&"job? (y/n) ",1,1,1)'       if ptstr == "y"
      			leftjob=left($place,1)
      			exit while
	    		end while

	  	elseif base="S"
    			while true
      			x = popuplist(8,57,15,s3&S7&s4&s5&s1,"Find measure",1,0)
      			if x = -1
		      		return (-1)
	      		end if
     	 		$place = ptstr
        			leftjob=left($place,1)
    	   			exit while
    			end while

	  	else
    			leftjob=CustLocn()
    			if leftjob=-1
	      		return (-1)
      		end if
	  	end if
    		return (0)
 	end while
END FUNCTION ' FindShop()


FUNCTION CustLocn()
local s1 s2 s3 s4 s5 s6 s7
  	s1 = "Warehouse"
'   	s2 = "Trade"
  	s3 = "Fulham"
  	s4 = "Raynes"
  	s5 = "Sheen"
  	s7 = "Putney"
   	while true
	  	x = popuplist(10,49,19,s3&s7&s4&s5&s1,"Find measure",1,0)
   		if x = -1
       		return (-1)
    		end if
    		$place = ptstr
	     return (left($place,1))
   	end while
END FUNCTION 'CustLocn()


FUNCTION CheckEstimator()							'from L233
local $est_yn										'message "$ftrcode) is:"&str($ftrcode)
	vloadif(dpath|"shwappt3.vw")
	$est_yn=filelookup([shwappt3.Fitter_Code],[shwappt3.Ftr_Est],$ftrcode)	' message "name is:"&str(custname)
	if $est_yn="E"
	  	vloadif(dpath|"shwapte6.vw")
		return (0)
	else
  		vloadif(dpath|"shwapte6.vw")
		return (-1)
	end if
END FUNCTION 'CheckEstimator()


FUNCTION ReturnToMenu()
  	screen clear box 1 1 sch scw 0 0 no-border
  	repaint off
  	file unload all
  	transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION Update1() 									'from L311 - completes/updates all fields in MEASURES, CUST_ORD & CUSTOMER
local j $chk $mess $shop $updstat
	$updstat=""
  	y=indirect("[A"|str(col-3)|"]")					'message " L3120 y) is:"&str(y)
 	jobnr=right(y,6)								'message "jobnr) is:"&str(jobnr)
 	if jobnr="None"
		return (-2)
	end if
	$shop=left(jobnr,1)								'message "$shop is:"&str($shop)
  	repaint off
	while true
  		if col = 4
    			exit while
		else
		  	y=indirect("[A"|str(col-3-1)|"]")			'message "L3257 next left is:"&str(y)
			$job=right(y,6)						'message "$job is:"&str($job)
			if $job=jobnr
				MoveLeft()
			else
				exit while
			end if
		end if
	end while

	$measdesc=blank
	$measinst=blank
	$mustread=blank
' [B1]="A" or [B1]="U" or [B1]="R" or [B1]="H" or [B1]="V" or [B1]="L" or [B1]="D" or [B1]="I"
	$meastime=blank
	custcontact=blank
	$email=""
  	m4 = " Correct? (y/n) "
  	jobnr = ""
  	$dfa = [DayFitter]|str(col-3)        				'message "L3081 $dfa is:"&str($dfa)
  	y=indirect("[A"|str(col-3)|"]")					'message "y) is:"&str(y)
	jobnr=right(y,6)								'message "jobnr) is:"&str(jobnr)
  	#asc=asc(right(jobnr,1))                 			'message "#asc is:"&str(#asc)
	$measpcode=left(y,8)							'message "L3086 $measpcode) is:"&str($measpcode)
  	$measstat = indirect("[B"|str(col-3)|"]") 			'message " L3087 $measstat is:"&str($measstat)

  	if #asc > 57 or #asc < 48            				'message "L2974 Not number"
    		x=indirect("[B"|str(col-3)|"]")    			'message "x) is:"&str(x)
    		if indirect("[B"|str(col-3)|"]") <> "R"
      		return (-1)                        		' NOT a job nr
    		end if
  	end if
												'jobnr = indirect("[A"|str(col-3)|"]")    'message " L2950 jobnr) is:"&str(jobnr)
  	$ordstat = indirect("[B"|str(col-3)|"]") 			' message " L2982 $ordstat is:"&str($ordstat)
  	$chk = mid(jobnr,2,1)                    			' message "$chk is:"&str($chk)
  	if chkstr($chk,"1 2 3 4 5 6 7 8 9 0") = 0 'messbox(" Not a Reservationÿ",0,1,1) ' in SHWAPPT5.VW
		repaint off
    		vloadif(dpath|"measure3.vw")
	    	order change key "[Job_Nr]"
    		data find "[Job_Nr]" equal jobnr options ""
    		if cerror                               '   if none - then return
      		x = messbox(" Job Nr not found - confirm as"&jobnr|"? (y/n) - {Esc} to exit ",1,0,0)
		     if x = 0
			end if
		end if
		custname=[CustOrd_Name]						'message "name is:"&str(custname)
		custcode=[Customer_Code]
		custcontact=[Contact_Name]
		cust_title=[Title]
 		$ordstat=[MeasStatus]						'message " L2995 $ordstat is:"&str($ordstat)
		$measinst=[Instructions]						'message "$measinst) is:"&str($measinst)
		$measdesc=[Description]						'message "$measdesc) is:"&str($measdesc)
		$mustread=[MustRead]						'message "$mustread is:"&str($mustread)
		$meastime=[MeasTime]						'message "$meastime is:"&str($meastime)
		$mobile=[Mobile]
		$hometel=[Home_Tel]
		$offtel=[Office_Tel]
		$email=[Email_Addr]
		$measaddr1=[Delivery_Address_1]				' message "L3095 $measaddr1 is:"&str($measaddr1)
		if len($measdesc)=0
			$measdesc="Not entered"
		end if	
		if len(custcontact)=0
			custcontact="As customer details"
		end if	
		if len($measinst)=0
			$measinst="Not entered"
		end if	
		if len($meastime)=0
			$meastime="Not entered"
		end if	
		if len($measdesc)=0
			$measdesc="Not entered"
		end if	
		if len($mustread)=0
			$mustread="Not entered"
		end if
  		while true
			if len(cust_title)>0
      			x = fentrybox(" Customer name and title ",35,"",cust_title)
	      		cust_title =ptstr
		    		exit while
			end if
	    		y = popuplist(10,24,18,"Mr Mrs Mrÿ&ÿMrs Miss Ms Other LtdÿCo","Select",1,0)
    			if ptstr = "Other"
      			while true
        				x=fentrybox(" Enter title ",20,"",cust_title)
        				if x = 0
          				cust_title = ptstr
	          			exit while
     	   			end if
      			end while
	    		elseif ptstr = "LtdÿCo"
     	 		cust_title = ""
      			exit while
	    		else
     	 		cust_title = ptstr
      			x = fentrybox(" Enter Forename or Initial ",35,"","")
      			cust_title = cust_title&proper(ptstr)
	    		end if
    			exit while
	  	end while

		while true
			$measdesc=_GEMS_Input("Areas to be done and Description of Measure for:"&custname&jobnr,"",$measdesc,125,0,"")
			if #GEMS_Cancel=1
	    			messbox(" Abandon 'Update'? (y/n) ",1,1,1)
				if ptstr == "Y"
					return (-1)
				else
					continue while
				end if
			elseif #GEMS_Cancel=0
				exit while
			end if
		end while

		while true
			$measinst=_GEMS_Input("Details of and Instructions for Measure - samples to take, caveats etc.","",$measinst,100,0,"")
			if #GEMS_Cancel=1
	    			messbox(" Abandon 'Update'? (y/n) ",1,1,1)
				if ptstr == "Y"
					return (-1)
				else
					continue while
				end if
			elseif #GEMS_Cancel=0
				exit while
			end if
		end while
		while true
			$mustread=_GEMS_Input("MUST READ notes - access instructions etc.","",$mustread,50,0,"")
			if #GEMS_Cancel=1
	    			messbox(" Abandon 'Update'? (y/n) ",1,1,1)
				if ptstr == "Y"
					return (-1)
				else
					continue while
				end if
			elseif #GEMS_Cancel=0
				exit while
			end if
		end while
		while true
			$meastime=_GEMS_Input(" Time of Measure e.g. 4pm 1030am 12 prompt ","",$meastime,20,0,"")
			if #GEMS_Cancel=1
	    			messbox(" Abandon 'Update'? (y/n) ",1,1,1)
				if ptstr == "Y"
					return (-1)
				else
					continue while
				end if
			elseif #GEMS_Cancel=0
				if len($meastime)=0
					messboxwait(" Must enter a time or TBC (to be confirmed) ",0,0,1)
					continue while
				end if
				exit while
			end if
		end while
		while true
	 		custcontact=_GEMS_Input(" Contact name & phone etc. (if different to customer) ","",custcontact,45,0,"")
			if #GEMS_Cancel=1
	    			messbox(" Abandon 'Update'? (y/n) ",1,1,1)
				if ptstr == "Y"
					return (-1)
				else
					continue while
				end if
			elseif #GEMS_Cancel=0
				exit while
			end if
		end while

		x=fentrybox(" Mobile 'phone number - {Esc} if none ",12,mobfone,$mobile)
		if x = 0
        		if ptstr = ""
          		$mobile = ""
        		else
          		$mobile = ptstr
        		end if
      	elseif x = -1
        		$mobile = ""
      	end if

	 	x = messbox(" Enter other phone numbers? (y/Esc) ",1,1,0)
		if x<>-1
			if ptstr=="y"
				EnterPhones()							' at L1287
			end if
		end if

		EnterEmailAddress()

		ViewMeasInfo()								' L1958

  	else
    		repaint off
    		vloadif(dpath|"appntmnt.vws")
    		$mess = filelookup([appntmnt.DFA],[appntmnt.DelAddr&Code],$dfa)
    		$user = left($mess,6)
    		$mess = right($mess,len($mess)-7)
    		colmessbox(" "|$mess|"ÿ",0,10,5,1)
    		Show()
    		return (1)
  	end if

	x=UpdateFile()									' L3250 MEASURES file only

  	vloadif(dpath|"shwapte6.vw")         				'message "jobnr is:"&str(jobnr)
  	y=indirect("[A"|str(col-3)|"]")					'message "L 1866 y) is:"&str(y)
	jobnr=right(y,6)								'message "current job is:"&str(jobnr)
  	repaint off
	while true
  		if col = 4
    			exit while
		else
		  	y=indirect("[A"|str(col-3-1)|"]")			'message "L3257 next left is:"&str(y)
			$job=right(y,6)						'message "jobnr) is:"&str(
			if $job=jobnr
				MoveLeft()
			else
	    			exit while
			end if
		end if
	end while

	#emptyslots=0
	#startcol=0
	#startcol=col
	j=0
	messbox(" Have you updated this Measure sufficiently for the appt? (No=finish update later on) (y/n) ",1,1,1)
  	if ptstr == "y"
		$updstat="M"
	 	while true									'message "L3507 j) is:"&str(j)					
			w=col-3+j									'message "L3509 w) is:"&str(w)
			if w>7
				exit while
			end if
		   	y=indirect("[A"|str(col-3+j)|"]")				'message "y) is:"&str(y)
			if right(y,6)=jobnr
		   		lock-record
	    				dbput("[B"|str(col-3+j)|"]","M")
			   	write-record
				j=j+1
				continue while
			else
				exit while
			end if
 		end while	
	else
		$updstat="N"
	 	while true									'message "L3507 j) is:"&str(j)					
			w=col-3+j									'message "L3509 w) is:"&str(w)
			if w>7
				exit while
			end if
		   	y=indirect("[A"|str(col-3+j)|"]")				'message "y) is:"&str(y)
			if right(y,6)=jobnr
		   		lock-record
	    				dbput("[B"|str(col-3+j)|"]","N")
			   	write-record
				j=j+1
				continue while
			else
				exit while
			end if
		end while	
  	end if
' NOW UPDATE APPTMNT
  	$dfa=[DayFitter]|str(col-3)    			' message " L3371 $dfa) is:"&str($dfa)
  	vloadif(dpath|"bookappt.vw")
  	order change key "[DFA]"
  	data find "[DFA]" equal $dfa options ""
  	if cerror                               			'   if none - then return
    		x = messbox(" Job Nr not found ",0,0,1)
	  	vloadif(dpath|"shwapte6.vw")         				'message "jobnr is:"&str(jobnr)
    		return (0)                         			' NOT booked
  	end if
  	lock-record									' in "bookappt.vw"
    		[Entered_By]   = userid
    		[Date_Altered] = today
    		[Time]         = now
    		[Status]       = $updstat						' Mi(N)imal info - shows as RED on LT GREY
		[MeasStatus]	= $updstat
  	write-record
	vloadif(dpath|"shwapte6.vw")         				'message "jobnr is:"&str(jobnr)
'     	mr=MoveRight()								' message " L3501 mr) is:"&str(mr)
  	return (1)
END FUNCTION 'Update1()


FUNCTION UpdateFile()								' from L3226
 	vloadif(dpath|"measure3.vw")
  	lock-record
		[Customer_Code]	=custcode
		[Instructions]		=$measinst
		[Description]		=$measdesc
		[MustRead]		=$mustread
		[MeasTime]		=$meastime
		[Contact_Name]		=custcontact
 		[Email_Addr]		=$email
  		[Mobile]			=$mobile
  		[Home_Tel]		=$hometel
  		[Office_Tel]		=$offtel
		[Title]			=cust_title
          [CustUpdated]		=today
		[CustUpdate]		=userid
		[MeasUpdater]		=userid
		[MeasUpdated]		=today
		[MeasStatus]		="M"	
    		[Updated_By]        =userid
    		[Last_Update]       =today
	write-record
	recnr=precord
' 		[MeasAddr1]		=measaddr1
' 		[MeasAddr2]		=measaddr2
' 		[MeasCity]		=meascity
' 		[MeasPostCode]		=measpostcode
' 		[MeasDate]		=#measdate
' 		[FtrName]			=$estimator
' 		[Title]			=cust_title
' 		[Address_1]		=custaddr1
' 		[Address_2]		=custaddr2
' 		[City/Town]		=custcity
' 		[Postcode]		=custpostcode
												' message "L115 recnr) is:"&str(recnr)
END FUNCTION' UpdateFile()							' from L291


FUNCTION CollectData()
		x=vloadif(dpath|"measure3.vw")				'
		data goto record record-number #prec
		jobnr=[Job_Nr]								'
'MEASURES.DB
	 	$inst		=[Instructions]
		$desc		=[Description]		
		$mustread		=[MustRead]		
		$estimator	=[FtrName]			
		$meastime		=[MeasTime]
' 	  	measaddr1		=[MeasAddr1]					'message "measaddr1) is:"&str(measaddr1)
'   		measaddr2		=[MeasAddr2]					'
' 	  	meascity		=[MeasCity]
'   		measpostcode	=[MeasPostcode]				'message "measpostcode) is:"&str(measpostcode)
' 		#measdate		=[MeasDate]					' message "#measdate) is:"&str(#measdate)

' CUST_ORD.DB

' CUSTOMER.DB
		$hometel		=[Home_Tel]
     	$offtel		=[Office_Tel]
		$mobile		=[Mobile]
		cust_title	=[Title]		
		custcontact	=[Contact_Name]	
		$email		=[Email_Addr]	
		custaddr1 	=[Address_1]
		custaddr2		=[Address_2]	
		custcity		=[City/Town]	
		custpostcode	=[Postcode]	
		$email		=[Email_Addr]
END FUNCTION ' CollectData


FUNCTION UpdateDetails()               					
	Background()
	$desc=_GEMS_Input("Areas to be done and Description of Measure","",$desc,125,0,"")
	$inst=_GEMS_Input("Details of and Instructions for Measure - samples to take, caveats etc.","",$inst,100,0,"")
	$mustread=_GEMS_Input("MUST READ; access instructions etc.","",$mustread,50,0,"")
	$meastime=_GEMS_Input(" Time of Measure e.g. 4pm 1030am 12 prompt ","",$meastime,20,0,"")

	EnterPhones()								' at L527

	Background()

	x = fentrybox(" Contact name (if different to customer name) ",45,"",custcontact)
	custcontact=ptstr

	EnterEmailAddress()

END FUNCTION ' UpdateDetails()               					


FUNCTION clearvar()
	clear jobnr
 	clear custname
 	clear  custcode
 	clear  deladdr1
	clear  deladdr2
	clear  delpostcode
 	clear  delcity
 	clear  $ftrname
 	clear  $ftrcode
 	clear  custcity
 	clear  custpostcode
 	clear  custaddr1
	clear  custaddr2
	clear  $email
	clear  custname
	clear  custcode
	clear  $hometel
	clear  $mobile
	clear  $offtel
	clear  jobnr
END FUNCTION ' clearvar()


FUNCTION CreateIndex()
'create index of FTR_LIST by stepping thro' text string and using ADDIDXRECS
' message " L3457 $dayftr) is:"&str($dayftr)
	vloadif(dpath|"appntmnt.vws")
  	order change key "[DFA]"
  	x=remove("estdate1.idx")							' message " L3458 remove estdate1 x is:"&str(x)
  	x=makeidx("appntmnt","estdate1","0",3)     			'message "x is:"&str(x)
  	for i = 1 to 7
    		$dfa=$dayftr|str(i)							'message " L3457 $dfa) is:"&str($dfa)
    		data find "[DFA]" equal $dfa options ""
    		x=addidxrec("estdate1.idx",precord,7)    		'message "x is:"&str(x)
  	end for
	vunloadif("appntmnt.vws")
'   	order change index "estdate1.idx"
END FUNCTION '	CreateIndex()


FUNCTION RemoveUSERID()								'message "L1509 RemoveBooking()"
	#appt=col-3
	x=indirect("[A"|str(col-3)|"]")				'
	if indirect("[A"|str(col-3)|"]")=userid
	 	$dfa=[DayFitter]|str(col-3) ' message "$dfa is:"&str($dfa)
  		repaint off
		vloadif(dpath|"bookappt.vw")
		order change key "[DFA]"
  		data find "[DFA]" equal $dfa options ""
	  	if cerror                               '   if none - then return
    			x = messbox(" Job Nr not found - L1461 ",0,0,1)
	    		return (0)                         ' NOT booked
  		end if
  		lock-record
    			[Job_Nr]       = "None"
		     [DelAddr&Code] = ""
		     [Entered_By]   = userid
			[Date_Altered] = today
    			[Time]         = now
    			[N_name]       = ""
    			[Status]       = ""
		write-record
  		repaint off
  		vloadif(dpath|"shwapte6.vw")         ' message "jobnr is:"&str(jobnr)
  		lock-record
    			dbput("[A"|str(col-3)|"]","None")
    			dbput("[B"|str(col-3)|"]","")
  		write-record
    		mr=MoveRight()
	end if
END FUNCTION ' RemoveUSERID()
