'SALORD02 - enters full details for customer's order, requisitions & PURCHORD's
' check sign < on L499

' 28/06/02 - amended to exclude old Trade order system
' 10/03/10 - creates new record for CTG_PLAN.DB

external   messbox() fentrybox() dpath vloadif() sch scw cpath shopmask nr5
external   fgp userid scr dsa strtoary() arytostr() vkeybox() $enternow
external   lpath bge popuplist() city wraptext() #maxleft #minleft remove()
external   entryline() messline() strcount() posnpopup() jobnr jobs[6]
external   messboxwait() Background() makeidx() PrintReport() vatrate vunloadif()
external   X_path _SWIP_Crystal() Xreppath

public     ptstr ptval custcode ptary[1] codes[1] prodcode $dayftr #due #net
public     #vat #receipts #gross

global     UpdApptRecs() $newstat $showdel custref $jobstr i $test AddToArray()
global     FindJobNr() ReturnToMenu() WriteDetails() CheckCustomer() $nrreqs
global     EnterInstructions() ChooseArea() EnterAreas() $salanal
global     #jobrec #bline #tline ftgdate slotrec hometel offtel linenr refcode
global     x custname ftgscrn ftginstr ftgplan CheckAddress()
global     deladdr1 custpostcode deladdr2 deladdr3 EnterCtgPlan()
global     deladdr4 $color carpettypes $ctgplan ftgcomm ftginit
global     $instruct y custaddr custpost m1 m5 #pagessent $notes
global     offax mobile custaddr1 custaddr2 custcity custcontact cust_title
global     z y1 y2 CuttingPlan() #minrsvn #rem ShowCustomer() ques jobdesc
global     #lower LengthMessage() #midlength #upper OrderSheet()
global     a1 a2 a3 a4 a5 $unitdes $unit $areainit fcud bcud df
global     $nextarea $allareas $area_list #start #lenareas #listcount ShowCustDetails()
global     #startr #startc j #volume $line x1 x2 c1 c2 c3 c4 c5 c6
global     $email CheckPostCode() $mincode MainCode() b EnterPhones()
global     CopyDelivery() namelist[1,2] DeliveryAddr() poplist[1] $chkaddr
global     CreateStr() CheckDetails() CustomerAddr() ReviewAddr() EnterEmailAddress()
global     deladdr ShowDetails() $sameaddr $delonly CopyCustomer() PopJobs() $nophone


MAIN
  	single-step off
	Background()
  	file unload all
  	$line = 0
  	quiet on
  	trace on
  	refcode = ""
  	prodcode = ""
  	carpettypes = "" ' string to show types of stock requsn'd in this session
'                    so that allocations can be carried out if necessary
' message "New SALORD02 at 020315"
  	while true
    		clear global
    		redimension ptary[6]
    		for i = 1 to 6
      		ptary[i] = jobs[i]
    		end for
    		x=arytostr(6)
    		$jobstr = ptstr                    'message "$jobstr) is:"&str($jobstr)
    		slotrec = 1
$area_list = "Total’Sq’Metres Stair’Charges Uplift Furniture Vinyl Carpet’tiles Vinyl’tiles Wood’flooring Lino Amtico Screed Hardboard Plywood"
    		#minrsvn = .2
    		x = FindJobNr()                    ' find Cust_Ord & update - L921
    		if x = -1
      		screen clear box 1 1 sch scw 0 0 no-border
      		repaint off
      		exit while
    		elseif x = 1		       ' already updated
      		screen clear box 1 1 sch scw 0 0 no-border
      		repaint off
        		OrderSheet()
	    		messbox(" Enter requisitions for"&jobnr&"now? (y/n) ",1,1,1)
      		if ptstr == "y"
        			$enternow = 1
        			transfer "ent_reqn.rf3" in-memory
      		else
        			exit while
      		end if
    		end if

    		x = CheckDetails()
    		x = EnterInstructions()          ' return 0 - success
    		if x = 0                         ' return 2 - Supply or Delivery only
      		CuttingPlan()
      		screen clear box 22 1 22 scw 0 0 no-border
    		end if
    		x = messline(" Write details to file? (y/n) ",1,1,1,22,14,53)
    		if x = 0
      		if ptstr == "y"
        			screen clear box 1 1 sch scw 0 0 no-border
        			repaint off
      		else
        			screen clear box 1 1 sch scw 0 0 no-border
        			repaint off
        			$delonly = "N"
        			continue while
      		end if
    		end if
    		$newstat = "U"
    		WriteDetails()
    		OrderSheet()
    		messbox(" Enter requisitions for"&jobnr&"now? (y/n) ",1,1,1)
    		if ptstr == "y"
      		$enternow = 1
      		transfer "ent_reqn.rf3" in-memory
    		end if
  	end while

  	ReturnToMenu()

END MAIN


FUNCTION CheckCustomer()
  	while true
    		y1 = format(" Select Title ","M70")
    		screen print 21 5 15 1 y1
    		y = popuplist(11,5,18,"Mr Mrs Mr’&’Mrs Miss Ms Other Ltd’Co","",1,0)
    		if ptstr = "Other"
      		while true
        			x = entryline(" Enter title ",20,"","",21,5,70)
        			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 = entryline(" Enter Forename or Initial ",35,"","",21,5,70)
      		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 = entryline(" Contact name (if different to customer name) ",45,"",custcontact,21,5,70)
    		if x = 0
      		custcontact = ptstr
      		exit while
    		end if
  	end while

'   $nophone = "N"
'   while true
'     while true
'       if hometel = "N/P"
'         hometel = "0"
'       end if
'       x = entryline(" Home 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",hometel,21,5,70)
'       if x = 0
'         if ptstr = "0"
'           hometel = "N/P"
'         else
'           hometel = ptstr
'           $nophone = "Y"
'           exit while
'         end if
'       elseif x = -1
'         hometel = "N/P"
'         exit while
'       end if
'     end while

'     while true
'       if offtel = "N/P"
'         offtel = "0"
'       end if
'       x = entryline(" Office 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",offtel,21,5,70)
'       if x = 0
'         if ptstr = "0"
'           offtel = "N/P"
'         else
'           offtel = ptstr
'           $nophone = "Y"
'           exit while
'         end if
'       elseif x = -1
'         offtel = "N/P"
'         exit while
'       end if
'     end while

'     while true
'       if mobile = "N/P"
'         mobile = "0"
'       end if
'       x = entryline(" Mobile 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",mobile,21,5,70)
'       if x = 0
'         if ptstr = "0"
'           mobile = "N/P"
'         else
'           mobile = ptstr
'           $nophone = "Y"
'           exit while
'         end if
'       elseif x = -1
'         mobile = "N/P"
'         exit while
'       end if
'     end while

' 	    		if $nophone = "N"
'      		 	x = messline(" You cannot be serious! Everyone has a telephone. Re-enter? (y/n) ",1,1,1,21,5,70)
' 	      		if ptstr=="y"
'         				continue while
' 	      		else
'         				exit while
'      		 	end if
' 		    	else
'       			exit while
'     			end if
' 	  	end while
'
'   		while true
' 	    		if offax = "N/P"
'       			offax = "0"
'     			end if
'     			x=entryline(" Fax number (eg 0171-498-1455) - {Esc} if none ",15,"\0*14{[1234567890\-]}",offax,21,5,70)
' 	    		if x=0
'       			offax = @if(ptstr=="0","N/P",ptstr)
'      	 		exit while
' 	    		elseif x = -1
'       			offax = "N/P"
'       			exit while
'     			end if
' 	  	end while
'   	end while

	EnterPhones()

	EnterEmailAddress()

END FUNCTION 'CheckCustomer()


FUNCTION EnterPhones()
local $mobnr $homenr $offnr
	$mobnr="N"
	$homenr="N"
	$offnr="N"
  	$nophone = "N"
  	while true
    		y1 = format(" Phone type ","M24")
    		screen print 10 45 19 1 y1
 		c1="Mobile"
		c2="Home"
		c3="Office"
    		y = popuplist(11,45,18,c1&c2&c3,"",1,0) ' message "y) is:"&str(y)
    		if ptstr = c1
    			while true
      			if mobile="N/P"
        				mobile=""
      			end if
'       			x=entryline(" Mobile 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",mobile,21,5,70)
      			x=fentrybox(" Mobile 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",mobile)
      			if x = 0
        				if ptstr = "0"
          				mobile = "N/P"
        				else
          				mobile = ptstr
          				$nophone = "Y"
						$mobnr="Y"
          				exit while
        				end if
      			elseif x = -1
        				mobile = "N/P"
        				exit while
      			end if
    			end while

    		elseif ptstr = c2
			while true
    				if hometel = "N/P"
    					hometel = "0"
   				end if
'     				x = entryline(" Home 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",hometel,21,5,70)
    				x = fentrybox(" Home 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",hometel)
    				if x = 0
   					if ptstr = "0"
         					hometel = "N/P"
    					else
        					hometel = ptstr
         					$nophone = "Y"
						$homenr="Y"
         					exit while
    					end if
    				elseif x = -1
    					hometel = "N/P"
    					exit while
    				end if
			end while

    		elseif ptstr = c3
    			while true
      			if offtel = "N/P"
        				offtel = "0"
      			end if
'       			x = entryline(" Office 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",offtel,21,5,70)
      			x =fentrybox(" Office 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",offtel)
      			if x = 0
        				if ptstr = "0"
          				offtel = "N/P"
        				else
          				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

' enter other phones Y/N
 	x = messline(" Enter other phone numbers? (y/n) ",1,1,1,21,5,70)
	if ptstr=="y"
		if $mobnr="N"
			while true
   				if mobile="N/P"
    					mobile=""
	    			end if
'     				x=entryline(" Mobile 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",mobile,21,5,70)
    				x=fentrybox(" Mobile 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",mobile)
    				if x = 0
    					if ptstr = "0"
         					mobile = "N/P"
	    				else
     	    				mobile = ptstr
         					$nophone = "Y"
						$mobnr="Y"
         					exit while
	    				end if
    				elseif x = -1
   					mobile = "N/P"
   					exit while
	    			end if
			end while
		end if
	
		if $homenr="N"
			while true
				if hometel = "N/P"
					hometel = "0"
				end if
				x = fentrybox(" Home 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",hometel)
    				if x = 0
					if ptstr = "0"
    						hometel = "N/P"
					else
    						hometel = ptstr
    						$nophone = "Y"
						$homenr="Y"
	    					exit while
    					end if
    				elseif x = -1
    					hometel = "N/P"
    					exit while
				end if
			end while
		end if

		if $offnr="N"
    			while true
      			if offtel = "N/P"
        				offtel = "0"
      			end if
      			x =fentrybox(" Office 'phone number - {Esc} if none ",15,"\0*14{[1234567890\-]}",offtel)
      			if x = 0
        				if ptstr = "0"
          				offtel = "N/P"
        				else
          				offtel = ptstr
          				$nophone = "Y"
						$offnr="Y"
          				exit while
        				end if
      			elseif x = -1
        				offtel = "N/P"
        				exit while
      			end if
    			end while
		end if
	end if
END FUNCTION 'EnterPhones()


FUNCTION ReviewAddr()
   	while true
    		ShowDetails()
'      		ShowCustDetails()
' 	y1 = format(" Select Town/City ","M24")
'   		screen print 10 35 19 1 y1
  		screen clear box 10 35 10 75 0 0 no-border
    		y1 = format("Change {C}ustomer/{D}elivery addresses or {S}undry details ","M70")
    		screen print 21 5 15 1 y1
    		y2 = format("{F10} to finish","M70")
    		screen print 22 5 15 1 y2
    		while true
      		x = inchar                    'message "x is:"&str(x)
      		if x = 99 or x = 67           ' c - change Customer
        			CustomerAddr()
        			exit while
      		elseif x = 100 or x = 68      ' d - change DELIVERY
        			DeliveryAddr()
        			exit while
      		elseif x = 115 or x = 83      ' s - change SUNDRY
        			CheckCustomer()
        			exit while
      		elseif x = 324                ' F10 - finish
        			x = CheckAddress()
        			if x = -1
          			messboxwait(" Address incorrect or insufficient ",0,0,1)
          			continue while
        			end if
        			screen clear box 1 1 sch scw 0 0 no-border
	        		repaint off
     	   		return (0)
      		end if
	    end while
  	end while
END FUNCTION 'ReviewAddr()


FUNCTION WriteDetails()         ' write customer & job details to SALORD02.VW
'   $chkaddr
local $patcomm
' message "$ctgplan is:"&str($ctgplan)
' message "L282\ $newstat is:"&str($newstat)
' message "$updated is:"&str($updated)
' message "SO2 L431 $email is:"&str($email)
	$patcomm="N"
  	lock-record
    		[Title]              = cust_title
	     [Customer_Name]      = custname
    		[Contact_Name]       = custcontact
    		[Office_Tel]         = offtel
    		[Home_Tel]           = hometel
    		[Office_Fax]         = offax
	     [Mobile/Other_Nr]    = mobile
    		[Address_1]          = custaddr1
  		[Address_2]          = custaddr2
    		[Customer City/Town] = custcity
    		[Postcode]           = custpostcode
  		[Delivery_Address_1] = deladdr1
    		[Delivery_Address_2] = deladdr2
    		[Del_City]           = deladdr3
    		[Del_Postcode]       = deladdr4
    		[Description]        = jobdesc
    		[Instructions]       = ftginstr
    		[Cutting Plan]       = $ctgplan
    		[Fitting_Comment]    = ftgcomm
    		[Appt_Slots]         = slotrec
    		[Slots_Rem]          = slotrec
    		[PDA]                = $showdel
    		[Customer_Ref]       = custref
    		[Last_Update]        = today
    		[Updated_By]         = userid
    		[Order_Status]       = $newstat
    		[OrderUpdated]       = "Y"
    		[Updated]            = today
    		[Updater]            = userid
    		[ChkAddr]            = $chkaddr
	     [PatComm]           = $patcomm
		[SameAddress]	  	= $sameaddr
' 		[OrderAccptRecvd]	="N"
		[Email_Addr]		=$email
		[ManualHold]		="N"
	write-record
END FUNCTION ' WriteDetails()


FUNCTION CuttingPlan()
  	screen shortrestore ftgscrn
  	messline(" Is there a Cutting Plan for this Job? (y/n) ",1,1,1,18,14,53)
  	$ctgplan = upper(ptstr)
  	if $ctgplan = "Y"
    		ftginit = "See Cutting Plan:"
		#lenareas = len(ftginit)
    		#startc = mod(#lenareas,50)+2
    		#startr = int(#lenareas/50)+1
    		while true
      		screen clear box 18 5 22 75 0 0 no-border
      		y = format("Press F10 to finish","M53")
      		screen print 22 14 15 1 y
      		screen editor 18 14 21 66 15 1 "Comments re fitting" VARIABLE ftgcomm ftginit\
      		MAX 2 50 START #startr #startc OPTIONS "" 0 0 1 RW_MODE
      		screen save 18 14 21 66 ftgplan
      		smartpeek $_lastkey z
      		if z <> {F10}
        			messbox(" Must use {F10} to save record!! ",0,0,1)
        			continue while
      		end if
      		screen shortrestore ftgplan
      		messline(" Confirm correct and continue? (y/n) ",1,1,1,22,14,53)
      		if ptstr == "y"
         			if ftgcomm ! ftginit    ' check to ensure ftginit is in ftgcomm

					EnterCtgPlan()

           			exit while
         			else
           			messline(" DO NOT erase `See Cutting Plan' ",0,0,1,22,14,53)
           			continue while
         			end if
      		else
        			continue while
      		end if
    		end while
  	else
    		while true
      		screen clear box 18 5 22 75 0 0 no-border
      		y = format("Press F10 to finish","M53")
      		screen print 22 14 15 1 y
      		ftginit = @if([Fitting_Comment]=blank,"",ftginit)
      		screen editor 18 14 21 66 15 1 "Comments re Fitting" VARIABLE ftgcomm ftginit
      		screen save 18 14 21 66 ftgplan
      		smartpeek $_lastkey z
      		if z <> {F10}
        			messbox(" Must use {F10} to save record!! ",0,0,1)
        			continue while
      		end if

      		screen shortrestore ftgplan
      		messline(" Confirm correct and continue? (y/n) ",1,1,1,22,14,53)
      		if ptstr == "y"
        			exit while
      		else
        			continue while
      		end if
    		end while
  	end if
END FUNCTION ' CuttingPlan()


FUNCTION EnterCtgPlan()					' create initial record of Ctg Plan

     vloadif(dpath|"ctg_plan.vws")           ' load view for updating
  	data enter lock
    		[Job_Nr]	 =jobnr
 		[Created]  =today		
		[Notes]	 =ftgcomm
	write-record
     vunloadif("ctg_plan.vws")           ' load view for updating
    	vloadif(dpath|"salord02.vw")           ' load view for return

END FUNCTION ' EnterCtgPlan()


FUNCTION LengthMessage()
local $chckmeas
  #upper = #rem
  #midlength = #lower + 3.1
  $chckmeas = @if([ChckMeas]="*","has","has NOT")
  if #lower <= 0
    #lower = 0
    y1 = "Lengths from"&str(#midlength)&"to"&str(#upper)
    if #upper <= #minleft
      #midlength = 0
      y1 = "Lengths only upto"&str(#upper)
      if #upper <= #maxleft
        #midlength = 0
        y1 = "Lengths only upto"&format(str(#upper),"2r")
      end if
    end if
  else
    y1 = "Lengths to"&str(#lower)&"or from"&str(#midlength)&"to"&str(#upper)
  end if

  y2 = "It"&$chckmeas&"been check measured OK? (y/n)"
  screen print 16 18 15 1 (format(y1,"M45"))
  screen print 17 18 15 1 (format(y2,"M45"))
END FUNCTION ' LengthMessage()


FUNCTION ReturnToMenu()
  lock module jobnr
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  error off
  while true
    window close
    if cerror
      exit while
    end if
  end while
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION


FUNCTION EnterInstructions()
local mess5
  while true
    x = fentrybox(" Customer's reference ",20,"","None")
    if x = 0
      custref = ptstr
      exit while
    end if
  end while
  $delonly = "N"
  error off
  while true
    x = vkeybox(9,29,"2’Delivery’only 2’Supply’only 13’Supply’and’fit","")
    if x = -1
      continue while
    end if
    if ptstr == "d"
      while true
        screen shortrestore dsa
        x = entryline("Timeslots req'd",2,"",slotrec,14,29,18)
        if x = 0
          slotrec = ptstr
          exit while
        else
          continue while
        end if
      end while
      $delonly = "Y"
      jobdesc = "Delivery’only"

    elseif ptstr == "s"
      if $salanal <> "W"
        messboxwait(" Warehouse order needed for Supply Only ",0,0,1)
        continue while
      end if
      slotrec = 0
      $delonly = "Y"
      jobdesc = "Supply’only"

    elseif ptstr == "f"               ' message "jobdesc is:"&str(jobdesc)
      x = EnterAreas()
      while true
        x = entryline(" Nr of timeslots required ",3,nr5,slotrec,21,25,30)
        if x = 0
          slotrec = ptstr
          if len(ptstr) = 0
            continue while
          end if
          exit while
        else
          continue while
        end if
      end while
    end if

    while true
      screen clear box 1 1 sch scw 0 0 no-border

      m1 = format(trim(deladdr1)|","&left(deladdr3,16),"M53")
      m5 = format((jobnr&"-"&custname),"M53")
      screen print 7 14 15 12 m5
      screen print 8 14 15 12 m1

      mess5 = "Job details"|@if(slotrec=0,""," - (timeslots"&str(slotrec)|")")
      screen editor 9 14 13 66 15 1 mess5 VARIABLE jobdesc jobdesc
      keys F10

      y = format("Press F10 to finish","M53")
      screen print 18 14 15 1 y
      screen editor 14 14 17 66 15 1 "Other comments (eg appointment times etc)" VARIABLE ftginstr ""
      screen save 14 14 17 66 ftgscrn
      smartpeek $_lastkey z
      if z <> {F10}
        messbox(" Must use {F10} to save record!! ",0,0,1)
        continue while
      end if
      exit while
    end while

    screen shortrestore ftgscrn
    messline(" Confirm correct and continue? (y/n) ",1,1,1,18,14,53)
    if ptstr == "y"
      screen clear box 18 14 22 66 0 0 no-border
      if $delonly = "N"
        if len(ftginstr) = 0
          messbox(" Must enter instructions ",0,0,1)
          continue while
        else
          return (0)
        end if
      else
        if len(ftginstr) = 0
          messbox(" Must enter instructions ",0,0,1)
          continue while
        else
          return (2)
        end if
      end if
    else                               ' wrong re-enter
      screen clear box 1 1 sch scw 0 0 no-border
      clear ptary[]
      clear namelist[]
      clear poplist[]
      clear jobdesc
      repaint off
      continue while
    end if
  end while
END FUNCTION ' EnterInstructions()


FUNCTION EnterAreas()
  $allareas = ""
  linenr = 0
  #bline = 19
  strcount($area_list)
  #listcount = ptval
  #tline = #bline - #listcount
  if #tline < 1
    message "Too many selections in $area_list"
    stop
  end if
  redimension poplist[#listcount]
  redimension namelist[#listcount,4]
  x = strtoary($area_list)
  for i = 1 to #listcount
    namelist[i,1] = ptary[i]
  end for

  while true                           '
    for i = 1 to #listcount
      poplist[i] = left(namelist[i,1]|"’’’’’’’’’’’’’’’’",16)|@if(namelist[i,4]=0,right("’’’’’’’’’’’’’’",10),right("’’’’’’’’’’’’’’"|str(namelist[i,4]),10))
      ptary[i]   = poplist[i]
    end for
    x = arytostr(#listcount)           '
    $area_list = ptstr
    x = posnpopup(#tline,25,#bline,$area_list,"",1,1,linenr)  ' message "x is:"&str(x)
    screen shortrestore dsa
    if x = 0
      linenr = ptval
      $nextarea = namelist[linenr,1]   'message "$nextarea is:"&str($nextarea)

      x = ChooseArea()                 'message "#volume is:"&str(#volume)
      namelist[linenr,4] = #volume     'message "$unit is:"&str($unit)
      namelist[linenr,3] = $unit       'message "$areainit is:"&str($areainit)
      namelist[linenr,2] = $areainit   '
      if x = -1
        continue while
      end if
    else
      screen clear box 22 25 22 54 0 0 no-border
      x = messline(" Confirm correct? (y/n) ",1,1,1,21,25,30)
      if ptstr == "y"
        CreateStr()
        exit while
      end if
    end if
  end while
END FUNCTION ' EnterAreas()


FUNCTION ChooseArea()
  	while true
    		#volume = 0
    		if $nextarea = "Furniture"
      		$unitdes = "Units"
      		$unit = "x"
      		$areainit = "FURN"
    		else
      		$areainit = case $nextarea ("Total’Sq’Metres","TSM")("Stair’Charges","SCH")("Uplift","UPL")\
("Vinyl","VNL")("Carpet’tiles","CTL")("Amtico","AMT")("Screed","SCR")\
("Wood’flooring","WUD")("Hardboard","HDB")("Plywood","PLY")("Vinyl’tiles","VTL")("Lino","LNO")
      		$unitdes = "Area"
      		$unit = "sm "
    		end if
   	 	x = entryline(" Enter"&$unitdes|" ",5,"*5{#}","",#bline+2,25,30)
    		if x = 0
      		#volume = ptstr
    		elseif x = -1
      		screen clear box #bline 30 #bline+1 46 0 0 no-border
      		screen clear box 22 37 22 41 7 7 no-border
      		return (-1)
    		end if
    		screen clear box #bline+2 25 #bline+2 54 0 0 no-border
    		exit while
  	end while
  	return (0)
END FUNCTION ' ChooseArea()


FUNCTION   CreateStr()                    ' build string from arrays
  jobdesc = ""                         '
  for i = 1 to #listcount
    if namelist[i,4] = 0
      continue for
    elseif namelist[i,4] = ""
      continue for
    end if
    jobdesc = jobdesc|trim(format(namelist[i,4],"0r"))|namelist[i,3]|namelist[i,2]|"; "
  end for
END FUNCTION ' CreateStr()


FUNCTION CopyDelivery()   ' message "copy deladdr from custaddr"
  deladdr1 = custaddr1
  deladdr2 = custaddr2
  deladdr3 = custcity
  deladdr4 = custpostcode
END FUNCTION ' CopyDelivery()   ' copy deladdr from custaddr


FUNCTION CopyCustomer()
  custaddr1    = [Address_1]
  custaddr2    = [Address_2]
  custcity     = [Customer City/Town]
  custpostcode = [Postcode]
END FUNCTION 'CopyCustomer()


FUNCTION DeliveryAddr()   'message "enter deladdr using deladdr"
  while true
    x = entryline(" Enter Delivery Address - Line 1 ",35,"",deladdr1,21,5,70)
    if x = 0
      deladdr1 = proper(ptstr)
      exit while
    end if
  end while

  while true
    x = entryline(" Enter Delivery Address - Line 2 ",35,"",deladdr2,21,5,70)
    if x = 0
      deladdr2 = proper(ptstr)
      exit while
    end if
  end while

  while true
    x = entryline(" Enter Town/City ",20,city,deladdr3,21,5,70)
    if x = 0
      deladdr3 = ptstr
      exit while
    end if
  end while

  while true
    x = entryline(" Delivery Postcode ",8,"AU*7{[A-Za-z1234567890\ ]U}",deladdr4,21,5,70)
    if x = 0
      deladdr4 = ptstr
      exit while
    else
      continue while
    end if
  end while
END FUNCTION ' DeliveryAddr()


FUNCTION PopJobs()
local ljob ljobmax ls c1 c2 c3 mess1 mess2
  ljob = 0
  ljobmax = 0
  for i = 1 to 6
    ljob = len(group($jobstr,i))
    if ljob > ljobmax
      ljobmax = ljob
    end if
  end for
  c3 = int((scw-ljobmax)/2)+1
  c1 = c3-2
  if c1 <= 0
       c1 = 1
  end if
  mess1 = " Enter Full Details for Order Nr "
  mess2 = " {Esc} for unlisted order "
  screen print 7 39 15 1 mess1
  screen print 16 42 15 1 mess2
  x = popuplist(8,c1,15,$jobstr,"",1,0)
  if x = 0
    jobnr = left(ptstr,6)
    return (0)
  elseif x = -1
    jobnr = ""
    return (-1)
  end if
END FUNCTION 'PopJobs()


FUNCTION AddToArray()
local $new $newcust $hold h
  y = strtoary(custname)
  $newcust = ""
  for i = 1 to ptval
    if i = 1
      $newcust = ptary[i]                ' NB - space is Alt-255
    else
      $newcust = $newcust|"’"|ptary[i]    ' NB - space is Alt-255
    end if
  end for
  $new = jobnr|"’"|$newcust            ' HARD space
  for i = 1 to 6
    if left(jobs[i],6) = jobnr         ' jobnr already held
      $hold = jobs[i]
      for h = i-1 to 1 step -1
        if len(jobs[h]) = 0
          jobs[h+1] = ""
        else
          jobs[h+1] = jobs[h]
        end if
      end for
      jobs[1] = $hold
      return (0)
    end if
  end for
  for i = 5 to 1 step -1
    if len(jobs[i]) = 0
      jobs[i+1] = ""
    else
      jobs[i+1] = jobs[i]
    end if
  end for
  redimension ptary[6]
  jobs[1] = $new
  for i = 1 to 6
    ptary[i] = jobs[i]
  end for
END FUNCTION ' AddToArray()


FUNCTION FindJobNr()                   ' finds Job & updates Cust_Ord
local l1 c3 c2 c1 ques $reqstr fj

  	fj = PopJobs()
	Background()
  	$instruct = ""
  	ftgdate = blank
  	$nrreqs = 1
  	smartpoke $_ins 0
  	while true
    		if fj = -1
      		x = fentrybox(" Enter Full Details for Order Nr or {Esc} for Menu ",6,shopmask,jobnr)
      		if x = -1
        			return (-1)                      ' ReturnToMenu
      		end if
      		jobnr = ptstr
    		end if
    		vloadif(dpath|"salord02.vw")           ' load view for updating
    		order change physical
    		order change key "[Job_Nr]"
    		data find "[Job_Nr]" equal jobnr options "g"   '  find correct JOB
    		if cerror
      		messbox(" Job NOT entered - use INITIAL ORDER first ",0,0,1)
      		return (-1)                      ' ReturnToMenu
    		else
      		#jobrec = precord    '???????????????????????
    		end if
	     if [Order_Status]="M"             ' "U"pdated' message "SO2 L961 [Order_Status]) is:"&str([Order_Status])
      		messboxwait(" "|jobnr&custname&"- this is a MEASURE - use DIARY/UPDATE to process ",0,0,1)
      		return (-1)
		end if
    		custcode    =[Customer_Code]
    		custname    =[Customer_Name]
    		deladdr1    =[Delivery_Address_1]
    		custcontact =[Contact_Name]
    		offtel      =[Office_Tel]
    		offax       =[Office_Fax]
    		hometel     =[Home_Tel]
    		cust_title  =[Title]
    		mobile      =[Mobile/Other_Nr]
		$email	  =[Email_Addr]
    		$salanal    =[SalesAnalysis]
     	if [Order_Status] <> "A"             ' "U"pdated
      		messbox(" "|jobnr&custname&"- already confirmed and details entered! ",0,1,1)
      		return (1)
    		else       ' CUST_ORD not yet updated - Extract details from Initial Order
      		x = messbox(" "|custname&"@"&deladdr1|"?(y/n)",1,1,1)
      		if x = 0
        			if ptstr == "n"
          			fj = -1
          			continue while
        			end if
      		end if
      		repaint off
    		end if
    		AddToArray()
    		return (0)
  	end while
END FUNCTION ' FindJobNr()


FUNCTION UpdApptRecs()
local #apptnr
  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
    return (0)                         ' no appts made yet
  end if

  for i = 1 to records
    $dayftr = left([DFA],11)
    #apptnr = [Appointment_Order]
    lock-record
      [Entered_By] = userid
      [Date_Altered] = today
      [Time] = now
      [Status] = $newstat
    write-record

    repaint off
    vloadif(dpath|"apptdate.vws")         ' message "jobnr is:"&str(jobnr)
    order change key "[DayFitter]"
    data find "[DayFitter]" equal $dayftr options ""
    if cerror
      return (0)
    end if
    lock-record
      dbput("[B"|str(#apptnr)|"]",$newstat)
    write-record
    vloadif(dpath|"bookappt.vw")
    data goto record next
  end for
END FUNCTION 'UpdApptRecs()


FUNCTION ShowCustomer()
local c1 c2 c3 c4 d1 d2 d3 d4 cc1 cr1 cc2 cr2
  cr1 = 4
  cc1 = 2
  cr2 = cr1+5
  cc2 = cc1+37
  screen clear box cr1 cc1 cr2 cc2 15 1
  c1 = left(custaddr1|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c2 = left(custaddr2|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c3 = left(custcity|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c4 = left(custpostcode|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  screen print cr1 cc1+1 15 1 "’Customer's address’"
  screen print cr1+1 cc1+2 15 1 c1
  screen print cr1+2 cc1+2 15 1 c2
  screen print cr1+3 cc1+2 15 1 c3
  screen print cr1+4 cc1+2 15 1 c4
  screen save cr1 cc1 cr2 cc2 custaddr
END FUNCTION 'ShowCustomer()


FUNCTION CheckDetails()
  	custaddr1    = ""
  	custaddr2    = ""
  	custpostcode = ""
  	deladdr1     = [Delivery_Address_1]
  	deladdr2     = ""
  	deladdr3     = ""
  	deladdr4     = ""

  	custname     = [Customer_Name]
  	offtel       = @if([Office_Tel]=blank,"",[Office_Tel])
  	hometel      = @if([Home_Tel]=blank,"",[Home_Tel])

  	messbox(" Are Delivery & Customer addresses the same? (y/n)",1,1,1)
  	if ptstr == "y"
    		$sameaddr = "Y"
  	else
    		$sameaddr = "N"
  	end if

  	messbox(" Do you want the invoice to show the Delivery address? (y/n)",1,1,1)
  	if ptstr == "y"
    		$showdel = "Y"
  	else
    		$showdel = "N"
  	end if

' 	ShowCustDetails()
   	ShowDetails()

'   custcity = "LONDON"            ' message "jobnr is:"&str(jobnr)
  	custcity = ""            ' message "jobnr is:"&str(jobnr)
  	deladdr3 = "LONDON"            ' message "custcode is:"&str(custcode)

    	CheckCustomer()    ' title, phone etc

  	if jobnr = custcode  ' NEW customer 'message "custcode is same as jobcode"
'     CheckCustomer()    ' title, phone etc
    		if $sameaddr = "Y"
      		custaddr1 = deladdr1
      		CustomerAddr()   ' copy customer from file
      		CopyDelivery()   ' copy deladdr from custaddr
               		        ' go to FINISH
    		else
      		CustomerAddr()   ' enter custaddr
      		deladdr1 = [Delivery_Address_1]
      		DeliveryAddr()   ' enter deladdr using CUST_ORD
          		             ' go to FINISH
    		end if

  	else                ' existing customer '
    		if $sameaddr = "Y"
      		custaddr1    = [Address_1]
      		custaddr2    = [Address_2]
      		custcity     = [Customer City/Town]
      		custpostcode = [Postcode]
      		CopyDelivery()   ' copy deladdr from custaddr
							' replace deladdr with custaddr -
							' go to FINISH
    		else
      		deladdr1 = [Delivery_Address_1]
      		custaddr1    = [Address_1]
      		custaddr2    = [Address_2]
      		custcity     = [Customer City/Town]
      		custpostcode = [Postcode]
      		ShowCustomer()
      		DeliveryAddr()   ' enter deladdr using CUST_ORD
							' go to FINISH
    		end if
  	end if
  	x = ReviewAddr()
END FUNCTION ' CheckDetails()


FUNCTION ShowDetails()
local c1 c2 c3 c4 d1 d2 d3 d4 cc1 cr1 cc2 cr2 dc1 dr1 dc2 dr2 pc1 pr1 pc2 pr2 \
      ordets p1 p2 p3 p4 p5 p6 p7 p8 df
  if $showdel = "Y"
    df  = 15
  elseif $showdel = "N"
    df  = 8
  end if
  cr1 = 4
  cc1 = 2
  cr2 = cr1+5
  cc2 = cc1+37
  dr1 = cr1
  dc1 = 42
  dr2 = cr2
  dc2 = dc1+37
  pr1 = cr2+2
  pc1 = cc1+14
  pr2 = pr1+8
  pc2 = pc1+50

  screen clear box cr1 cc1 cr2 cc2 15 1
  c1 = left(custaddr1|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c2 = left(custaddr2|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c3 = left(custcity|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  c4 = left(custpostcode|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  screen print cr1 cc1+1 15 1 "’Customer's address’"
  screen print cr1+1 cc1+2 15 1 c1
  screen print cr1+2 cc1+2 15 1 c2
  screen print cr1+3 cc1+2 15 1 c3
  screen print cr1+4 cc1+2 15 1 c4
  screen save cr1 cc1 cr2 cc2 custaddr

  screen clear box dr1 dc1 dr2 dc2 df 1
  d1 = left(deladdr1|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  d2 = left(deladdr2|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  d3 = left(deladdr3|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  d4 = left(deladdr4|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  screen print dr1 dc1+1 df 1 "’Delivery address’"
  screen print dr1+1 dc1+2 df 1 d1
  screen print dr1+2 dc1+2 df 1 d2
  screen print dr1+3 dc1+2 df 1 d3
  screen print dr1+4 dc1+2 df 1 d4
  if $showdel = "N"
    screen print dr2 dc1+1 df 1 "’Not to be shown on invoice’"
  end if
  screen save dr1 dc1 dr2 dc2 deladdr

  screen clear box pr1 pc1 pr2 pc2 15 1
  p1 = format("Title:  ’   "|left(cust_title|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p2 = format("Name:     ’ "|left(custname|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p3 = format("Contact:   ’"|left(custcontact|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p4 = format("Office tel:’"|left(offtel|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p5 = format("Home tel:  ’"|left(hometel|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p6 = format("Email:"|left($email|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  p7 = format("Mobile nr: ’"|left(mobile|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35),"L47")
  screen print pr1 pc1+1 15 1 "’Sundry details’"
  screen print pr1+1 pc1+2 15 1 p1
  screen print pr1+2 pc1+2 15 1 p2
  screen print pr1+3 pc1+2 15 1 p3
  screen print pr1+4 pc1+2 15 1 p4
  screen print pr1+5 pc1+2 15 1 p5
  screen print pr1+6 pc1+2 15 1 p6
  screen print pr1+7 pc1+2 15 1 p7
  screen save pr1 pc1 pr2 pc2 ordets
END FUNCTION 'ShowDetails()


FUNCTION ShowCustDetails()
local c1 c2 c3 c4 d1 d2 d3 d4 cc1 cr1 cc2 cr2 dc1 dr1 dc2 dr2 pc1 pr1 pc2 pr2 \
      ordets p1 p2 p3 p4 p5 p6 p7 p8
' message "$showdel is:"&str($showdel)

	fcud=15		' foreground Letter colour
	bcud=1		' background Letter colour
	df  = 15		' BOX colour

  	cr1 = 11						' starting row for CUSTOMER - was 4
  	cc1 = 18						' starting column for CUSTOMER - was 2
  	cr2 = cr1+5
  	cc2 = cc1+37
  	dr1 = cr1						' starting row for MEASURE
  	dc1 = 56						' starting column for MEASURE - was 42
  	dr2 = cr2
  	dc2 = dc1+37
  	pr1 = cr2+1					' SUNDRY Row - was 2
'   	pc1 = cc1+13					' SUNDRY Column - was 14
  	pc1 = cc1+9					' SUNDRY Column - was 14
  	pr2 = pr1+9					' actions
'   	pc2 = pc1+50
  	pc2 = pc1+60

  	screen clear box cr1 cc1 cr2 cc2 fcud bcud
  	c1 = left(custaddr1|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	c2 = left(custaddr2|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	c3 = left(custcity|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	c4 = left(custpostcode|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
'   	screen print cr1 cc1+1 fcud bcud "’Customer's address’"
  	screen print cr1 cc1+1 14 1 "’Customer's address’"
  	screen print cr1+1 cc1+2 fcud bcud c1
  	screen print cr1+2 cc1+2 fcud bcud c2
  	screen print cr1+3 cc1+2 fcud bcud c3
  	screen print cr1+4 cc1+2 fcud bcud c4
  	screen save cr1 cc1 cr2 cc2 custaddr

  	screen clear box dr1 dc1 dr2 dc2 df 1
  	d1 = left(deladdr1|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	d2 = left(deladdr2|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	d3 = left(deladdr3|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
  	d4 = left(deladdr4|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",35)
'   	screen print dr1 dc1+1 df 1 "’Measure address’"
  	screen print dr1 dc1+1 14 1 "’Measure address’"
  	screen print dr1+1 dc1+2 df 1 d1
  	screen print dr1+2 dc1+2 df 1 d2
  	screen print dr1+3 dc1+2 df 1 d3
  	screen print dr1+4 dc1+2 df 1 d4
'   	if $showdel = "N"
'     		screen print dr2 dc1+1 df 1 "’Not to be shown on invoice’"
'   	end if
  	screen save dr1 dc1 dr2 dc2 deladdr

  	screen clear box pr1 pc1 pr2 pc2 15 1
  	p1 = format("Title:  ’   "|left(cust_title|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p2 = format("Name:     ’ "|left(custname|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p3 = format("Contact:   ’"|left(custcontact|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p4 = format("Office tel:’"|left(offtel|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p5 = format("Home tel:  ’"|left(hometel|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p6 = format("Fax nr:’’  ’"|left(offax|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	p8 = format("Email: "|left($email|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",50),"L57")
  	p7 = format("Mobile nr: ’"|left(mobile|"’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’",44),"L56")
  	screen print pr1 pc1+1 14 1 "’Sundry details’"
  	screen print pr1 pc2-8 14 1 " "|jobnr|" "
  	screen print pr1+1 pc1+2 15 1 p1
  	screen print pr1+2 pc1+2 15 1 p2
  	screen print pr1+3 pc1+2 15 1 p3
  	screen print pr1+4 pc1+2 15 1 p7
  	screen print pr1+5 pc1+2 15 1 p8
  	screen print pr1+6 pc1+2 15 1 p5
  	screen print pr1+7 pc1+2 15 1 p4
  	screen print pr1+8 pc1+2 15 1 p6
  	screen save pr1 pc1 pr2 pc2 ordets
END FUNCTION 'ShowCustDetails()





FUNCTION CheckAddress()
  $chkaddr = "Y"
  return (0)
END FUNCTION ' CheckAddress()



FUNCTION  OrderSheet()
local $index $file p1 p2 p3 p4 p5 p6
  	Background()
  	$index = "onlyone.idx"
  	$file = "cust_ord"
  	remove($index)
  	x=makeidx($file,$index,str(precord),3)    '   message "x is:"&str(x)
  	vloadif(dpath|"intordr1.vw")
  	order change index $index
  	if [ConfPrt]="Y"
    		return (1)
  	end if
  	#due = [Balance_Due]                 '
  	if #due > 0
    		#due = "’Balance due"&currency(#due)
  	elseif #due = 0
    		#due = "’’’Order paid in full"
  	end if
  	#gross = [Invoice_Total]             '
  	#receipts = "’’Payments received by"&date2(today)&"’’"&currency(tablesum([Amount_Received]))
  	#net = #gross/((100+vatrate)/100)    'message "#net is:"&str(#net)
  	#vat = #gross - #net                 'message "#vat is:"&str(#vat)
  	#net   = "Net:"&currency(#net)
  	#gross = "Total Order value:"&currency(#gross)
  	#vat   = "VAT at 20%:"&currency(#vat)
    	messboxwait(" Insert Logo'd paper for Order Confirmation ",0,1,1)
    	while true
      	remove(X_path|"X_ordcnf.*")
      	data query execute "not_del.dfq" Smart4 X_path|"X_ordcnf" fields "[Job_Nr|Order_Status]"
      	vunloadif("X_ordcnf.vws")
      	_SWIP_Crystal(Xreppath|"ord_conf","S",0,2,"")
      	messbox(" Has Order Nr"&jobnr&"printed correctly? (y/n) ",1,1,1)
      	if ptstr == "y"                      '  store file & exit
        		vloadif(dpath|"intordr1.vw")
        		lock-record                        ' update record with inv nr & date
          		[ConfPrt]="Y"
        		write-record
        		return (0)
      	else
        		vloadif(dpath|"intordr1.vw")
        		messbox(" Abandon and print later? (y/n) ",1,1,1)
        		if ptstr == "y"                      '  store file & exit
          		return (0)
        		else
          		continue while
        		end if
      	end if
    	end while
END FUNCTION ' OrderSheet()


' FUNCTION EnterEmailAddress()
' local j r i n x $mess
' 	while true
'    		while true
'     			x = entryline(" Customer's EMAIL address - {Esc} if none ",50,"","",21,5,92)
' 	    		if x = 0
'  			     $email=ptstr
'        			exit while
' 	    		else
' ' message "Confirm no email address"
'  			     $email = ""
'      	  		return (0)
'     			end if
' 	   	end while
'
' 		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 EnterEmailAddress()							' from L470
local j r i n x $mess
' message "MO 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 CustomerAddr()			' called from L257
  	while true
    		x = entryline(" Customer's Address - 1st line ",35,"",custaddr1,21,5,70)' message "x is:"&str(x)
    		if x = 0
      		custaddr1 = proper(ptstr)
      		exit while
    		end if
  	end while

  	while true
    		x = entryline(" Customer's Address - 2nd line (NOT Town or City) ",35,"",custaddr2,21,5,70)' message "x is:"&str(x)
    		if x = 0
      		custaddr2 = proper(ptstr)
      		exit while
    		end if
  	end while

  	while true
    		x = entryline(" Enter Town/City ",20,city,custcity,21,5,70)
    		if x = 0
      		custcity=ptstr
      		exit while
    		else
      		continue while
    		end if
  	end while

  	while true
    		x = entryline(" Customer's Postcode ",8,"AU*7{[A-Za-z1234567890\ ]U}",custpostcode,21,5,70)
    		if x = 0
      		custpostcode=ptstr
      		exit while
    		else
      		continue while
    		end if
  	end while


' 	Background()
' 	custcity=""
'    	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
'  		  	while true
'      			x = entryline(" Town/City NOT county ",20,city,custcity,19,35,24)
'      			x = fentrybox(" 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

'    	while true
'     		x=entryline(" Customer's Postcode (NOT County!) ",8,"AU*7{[A-Za-z1234567890\ ]U}",custpostcode,21,5,70)
'     		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 CheckPostCode()
local	left4code
 	$mincode=MainCode(custpostcode)					'message "$mincode) is:"&str($mincode)				'
	vloadif(dpath|"post1.vws")
    	order change key "[E1]"
    	data find "[E1]" equal $mincode options ""
    	if cerror                               '   if none - then return
		return (0)
	else
		return (1)					' found - is a LONDON code
	end if
END FUNCTION ' CheckPostCode()


FUNCTION MainCode(x)
local y j z
	z=""
	b=""
     for j = 1 to len(x)
      	z = mid(x,j,1)						'message "mid(y,j,1) is:"&str(z)
      	if z = " "					' SOFT space
 			return (b)				'
      	end if
		b=b|z							'message "b is:"&str(b)
    	end for
	return (b)				'
END FUNCTION ' MainCode()

