'SALORD07 - as SALORD02 but enters details for customer's order not already collected for Measure appt,
'then enters requisitions & PURCHORD's
' must create VARN record
' DEPOSIT amount rem'd out at L187

external   messbox() fentrybox() dpath vloadif() sch scw cpath shopmask nr5 keybox() increment()
external   fgp userid scr dsa strtoary() arytostr() vkeybox() $enternow $menu mobfone #est_amt
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     $newstat $showdel custref $jobstr i $test $saltype $method $vat $sameaddr	#deposit
global     FindJobNr() ReturnToMenu() WriteDetails() $nrreqs #netinv recnr invtot initbalance
global     EnterInstructions() ChooseArea() EnterAreas() $salanal $allreas $deptype locn
global     #jobrec #bline #tline ftgdate slotrec hometel offtel linenr refcode newbalance
global     x custname ftgscrn ftginstr ftgplan DepositMethod() NewBACS() $sales
'  TransactRcvd()
global     deladdr1 custpostcode deladdr2 deladdr3 EnterCtgPlan() MakeReceiptNr()
global     deladdr4 $color carpettypes $ctgplan ftgcomm ftginit  receiptnr CustomerAddr() CheckPostCode()
global     $instruct y custaddr custpost m1 m5 #pagessent $notes balancedue rcvd MainCode()
global     offax mobile custaddr1 custaddr2 custcity custcontact cust_title
global     z y1 y2 CuttingPlan() #minrsvn #rem ques jobdesc $newcust DeliveryAddr()
global     #lower LengthMessage() #midlength #upper OrderSheet() a1 a2 a3 a4 a5 $unitdes $unit $areainit
global    $nextarea $allareas $area_list #start #lenareas #listcount #startr #startc j #volume $line x1 x2 c1 c2 c3 c4 c5 c6
global    $email $mincode b EnterPhones() AddVarn() namelist[1,2] poplist[1] $chkaddr
global    CreateStr() CheckDetails() EnterEmailAddress() deladdr $delonly $nophone
global  	$reas1 $reas2 $reas3 $reas4 $reas5 $free $reas #vat_amt
' DepositMethod()
' message "cust_title) is:"&str(cust_title)
' message "custname) is:"&str(custname)
' message "custcontact) is:"&str(custcontact)
' message "offtel) is:"&str(offtel)
' message "hometel) is:"&str(hometel)
' message "offax) is:"&str(offax)
' message "mobile) is:"&str(mobile)
' message "custaddr1) is:"&str(custaddr1)
' message "custaddr2) is:"&str(custaddr2)
' message "custcity) is:"&str(custcity)
' message "custpostcode) is:"&str(custpostcode)
' message "deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "deladdr3) is:"&str(deladdr3)
' message "deladdr4) is:"&str(deladdr4)
' message "jobdesc) is:"&str(jobdesc)
' message "ftginstr) is:"&str(ftginstr)
' message "$ctgplan) is:"&str($ctgplan)
' message "ftgcomm) is:"&str(ftgcomm)
' message "slotrec) is:"&str(slotrec)
' message "$showdel) is:"&str($showdel)
' message "custref) is:"&str(custref)
' message "$sameaddr) is:"&str($sameaddr)
' message "$email) is:"&str($email)
' message "#deposit) is:"&str(#deposit)
' message "SO7 L58 #est_amt) is:"&str(#est_amt)

'

MAIN
' get details not previously taken [PDA] & type of sale/VAT rate
' check phones and email
' message "CONFIRM CUSTOMER DETAILS"
  	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 SALORD07 at 111012"
' message "L74 #est_amt) is:"&str(#est_amt)
' message "SA7 L77 jobnr) is:"&str(jobnr)

   	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()                    ' L919' message "L89 custaddr1) is:"&str(custaddr1)
    		if x = -1
			Background()
      		exit while
		elseif x=1					' already converted
			Background()
      		exit while
    		end if

    		x = CheckDetails()				'L132
    		if x = -1
			Background()
      		exit while
    		end if

    		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,34,53)
    		if x = 0
      		if ptstr == "y"
				Background()
' 		    		$newstat = "U"
    				x=WriteDetails()
' messboxwait(" Printing Order Sheet to be completed ",0,0,1)
 		    		OrderSheet()
      		else
				Background()
        			$delonly = "N"
        			continue while
      		end if
    		end if
			exit while
  	end while

  	ReturnToMenu()

END MAIN


FUNCTION CheckDetails()								' from L74
' message "L131 custaddr1) is:"&str(custaddr1)
  	$reas1="Original’order"
  	$reas2="As’per’attached’order"
  	$reas3="Labour/materials’supplied’to’Customer's’order"
  	$reas4="As’per’supporting’documents"
  	$reas5="Free’text"
  	$free ="Labour xx,xxx - Materials xx,xxx  (exc. VAT)"

	Background()
  	x = keybox("1Normal 1Zero’rate","Convert"&jobnr&"to order")
  	if x = -1
    		return (-1)
  	end if
  	$saltype = ptstr
  	$newstat = "A"
  	$method = "Cheque"
  	if $saltype == "n"
    		#vat = vatrate
    		$vat = "S"
  	elseif $saltype == "z"
    		$vat = "Z"
    		#vat = 0
  	end if

	while true
      	x = fentrybox(" Enter Invoice total (inc VAT) - Estimate value is shown if known ",8,"*8{[-1234567890.]}",#est_amt)
      	if x = 0
        		if ptstr = ""
          		continue while
        		end if
        		invtot = value(ptstr)
        		if $menu <> "boss"
          		if invtot = 0
          			messbox(" Cannot enter ZERO invoices ",0,0,1)
          			continue while
          		end if
        		end if
        		exit while
      	elseif x = -1
        		continue while
      	end if
    	end while
    	initbalance = invtot

	if invtot>500
		#deposit=invtot/2
	else
		#deposit=invtot
	end if

 	while true
       	x = fentrybox(" Amount of Deposit - enter 0 if none ",8,"*8{[-1234567890.]}",#deposit)
       	if x = 0
         		if ptstr=""
           		continue while
         		elseif ptstr=0
           		exit while
         		end if
         		#deposit = value(ptstr)
         		exit while
       	elseif x = -1
         		continue while
       	end if
    	end while
 	if #deposit>.01
 		DepositMethod()
 	end if

'   	#deposit=0
     $deptype=""

' 	if $deptype="B"
		x = messbox(" Create BACS record now? (y/n) ",1,1,1)
    		if ptstr == "y"
    			x=NewBACS()							'L988
		end if
' 	end if

' message "S7 L200 #deposit) is:"&str(#deposit)
' message "$deptype) is:"&str($deptype)

  	if $menu = "boss"
    		$allreas = $reas1&$reas2&$reas3&$reas4&$reas5
  	else
    		$allreas = $reas1&$reas2&$reas3&$reas4
  	end if
  	while true
    		x = popuplist(11,33,28,$allreas,"",1,0) ' message "x) is:"&str(x)
    		if x = -1
      		continue while
    		elseif x = 0
      		exit while
    		end if
  	end while

  	if ptstr = $reas5
    		while true
      		x = fentrybox(" Var'n description - the Customer reads this ",50,"",$free)
      		if x = -1
        			return (-1)
      		elseif x = 0
        			if ptstr = ""
          			continue while
        			end if
        			$reas = ptstr
        			exit while
      		end if
    		end while
  	else
    		$reas = ptstr
  	end if

' message "jobnr) is:"&str(jobnr)
' message "invtot) is:"&str(invtot)
' message "$reas) is:"&str($reas)
' message "S7 L237 #deposit) is:"&str(#deposit)
' message "$deptype) is:"&str($deptype)

   	AddVarn(jobnr|"-00",invtot,$reas,"Original","Original",today)

 	Background()

'   	messbox(" Are Delivery & Customer addresses the same? (y/n)",1,1,1)
'   	if ptstr == "y"
'     		$sameaddr = "Y"
'   	else
'     		$sameaddr = "N"
' 'enter Customer addr if diff
'   	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

' message "L262 custaddr1) is:"&str(custaddr1)
	CustomerAddr()									' L966

	DeliveryAddr()

 	EnterPhones()

' message "S7 L226 $email) is:"&str($email)

	EnterEmailAddress()
' message "S7 L229 $email) is:"&str($email)

  	$chkaddr = "Y"

END FUNCTION ' CheckDetails()


FUNCTION DepositMethod()
	WHILE TRUE
'   		if vkeybox(11,38,"4Cheque 1Cash 1BACS 1PDQ 1Not’known","Deposit method")=0
  		if vkeybox(11,38,"4Cheque 1Cash 1BACS 1PDQ","Deposit method")=0
	     	if ptstr == "q"
	 	    		$deptype=UPPER(ptstr)
				exit while	
    			elseif ptstr == "c"
	 		    	$deptype=UPPER(ptstr)
				exit while	
	    		elseif ptstr == "b"
		   	     $deptype=UPPER(ptstr)
				exit while	
' 	    		elseif ptstr == "n"
' 		   	     $deptype=""
' 				exit while	
    			elseif ptstr == "p"
	 		    	$deptype=UPPER(ptstr)
				exit while	
    			end if
	   	else	
			messboxwait(" VKEYBOX failed at S7 L 275 ",0,0,1)
			continue while
  		end if
	end while
END FUNCTION  'DepositMethod()


FUNCTION AddVarn(varnr,#gross,$reas,$ref,$notif,$varndate)
local lastbal newtotal oldtotal newnet oldnet #prec x
  	vloadif(dpath|"addvarn4.vw")
  	data enter lock
    		[Var_Nr]        = varnr
    		[VarnJobNr]     = left(varnr,6)
    		[Amount_Gross]  = #gross
    		[Reason]        = $reas
    		[Customers_Ref] = $ref
    		[Notif_Method]  = $notif
    		[Date]          = $varndate
    		[Entered_By]    = userid
		[VarNr]    =varnr
		[Time_Entd]=now
		[Entd_By]  =userid
		[Date_Entd]=today				
  	write-record
  	lastbal = round([Balance_Due],2)
  	balancedue = lastbal + #gross
  	oldtotal = round([Invoice_Total],2)
  	newtotal = oldtotal + #gross
  	oldnet   = round([Net_Invoice],2)
  	newnet   = oldnet + round(#gross*100/(100+#vat),2)
	#vat_amt =newtotal-newnet
  	lock-record
    		[Balance_Due]   = balancedue
    		[Invoice_Total] = newtotal
    		[Net_Invoice]   = newnet
		[Inv_Total]=newtotal
		[Inv_Net]  =newnet
		[varngros] =#gross
		[VAT_amt]  =#vat_amt
  	write-record
END FUNCTION 'AddVarn()


FUNCTION EnterPhones()
local $mobnr $homenr $offnr
	$mobnr="N"
	$homenr="N"
	$offnr="N"
  	$nophone = "N"
  	while true
    		y1 = format(" Phone ","M10")
    		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=fentrybox(" Mobile 'phone in format 07###-###### - {Esc} if none ",12,mobfone,mobile)
      			x=fentrybox(" Mobile 'phone in format 07###-###### - {Esc} if none ",12,"",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 = 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 = 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 = messbox(" Enter other phone numbers? (y/n) ",1,1,1)
	if ptstr=="y"
		if $mobnr="N"
			while true
   				if mobile="N/P"
    					mobile=""
	    			end if
    				x=fentrybox(" Mobile 'phone number - {Esc} if none ",12,"",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 WriteDetails()         ' write customer & job details to SALORD07.VW
'   $chkaddr
local $patcomm	orddate
	orddate=today
' message "$ctgplan is:"&str($ctgplan)
' message "L282\ $newstat is:"&str($newstat)
' message "$updated is:"&str($updated)
' message "$email is:"&str($email)
' message "jobnr) is:"&str([Job_Nr])
' message "L491 cust_title) is:"&str(cust_title)
' message "custname) is:"&str(custname)
' message "custcontact) is:"&str(custcontact)
' message "offtel) is:"&str(offtel)
' message "hometel) is:"&str(hometel)
' message "offax) is:"&str(offax)
' message "mobile) is:"&str(mobile)
' message "custaddr1) is:"&str(custaddr1)
' message "custaddr2) is:"&str(custaddr2)
' message "custcity) is:"&str(custcity)
' message "custpostcode) is:"&str(custpostcode)
' message "deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "deladdr3) is:"&str(deladdr3)
' message "deladdr4) is:"&str(deladdr4)
' message "jobdesc) is:"&str(jobdesc)
' message "ftginstr) is:"&str(ftginstr)
' message "$ctgplan) is:"&str($ctgplan)
' message "ftgcomm) is:"&str(ftgcomm)
' message "slotrec) is:"&str(slotrec)
' message "$showdel) is:"&str($showdel)
' message "custref) is:"&str(custref)
' message "$sameaddr) is:"&str($sameaddr)
' message "$email) is:"&str($email)
' message "#deposit) is:"&str(#deposit)
' message "L522 precord) is:"&str(precord)
' message "orddate) is:"&str(orddate)

    	vloadif(dpath|"salord07.vw")           ' load view for return
	orddate=date2(orddate)				'message "orddate) is:"&str(orddate)
	$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
		[Date_Of_Order]      = orddate
   		[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
' 		[Fitting_Date]=blank
    		[Updated_By]         = userid
'     		[Order_Status]       = "U"
    		[Order_Status]="U"
    		[OrderUpdated]="Y"
    		[Updated]     = today
    		[Updater]     = userid
    		[ChkAddr]     = $chkaddr
	     [PatComm]     = $patcomm
		[SameAddress] = $sameaddr
		[Email_Addr]	=$email
		[Dep_Amt]		=#deposit
' 		[ManualHold]	="N"
' 		[MeasStatus]	="N"			' already Marked as "V" in MEAS_UPD
	write-record
single-step off
' !!!!!!!!!!!!!!!!!!!! mark MEASURE [MeasStatus]
END FUNCTION ' WriteDetails()


FUNCTION CuttingPlan()
  	screen shortrestore ftgscrn
  	messline(" Is there a Cutting Plan for this Job? (y/n) ",1,1,1,18,34,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 34 15 1 y
      		screen editor 18 34 21 86 15 1 "Comments re fitting" VARIABLE ftgcomm ftginit\
      		MAX 2 50 START #startr #startc OPTIONS "" 0 0 1 RW_MODE
      		screen save 18 34 21 86 ftgplan
      		smartpeek $_lastkey z
      		if z <> {F10}
        			messbox(" Must use {F10} to save record!! ",0,0,1)
        			continue while
      		end if
      		screen shortrestore ftgplan
    			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,34,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 34 15 1 y
      		ftginit = @if([Fitting_Comment]=blank,"",ftginit)
      		screen editor 18 34 21 86 15 1 "Comments re Fitting" VARIABLE ftgcomm ftginit
      		screen save 18 34 21 86 ftgplan
      		smartpeek $_lastkey z
      		if z <> {F10}
        			messbox(" Must use {F10} to save record!! ",0,0,1)
        			continue while
      		end if

      		screen shortrestore ftgplan
    			exit while
    		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|"salord07.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(12,43,"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,19,39,23)
        			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,26,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 34 15 12 m5
	      	screen print 8 34 15 12 m1
     	 	mess5 = "Job details"|@if(slotrec=0,""," - (timeslots"&str(slotrec)|")")
      		screen editor 9 34 13 86 15 1 mess5 VARIABLE jobdesc jobdesc
	      	keys F10
     	 	y = format("Press F10 to finish","M53")
      		screen print 18 34 15 1 y
	      	screen editor 14 34 17 86 15 1 "Other comments (eg appointment times etc)" VARIABLE ftginstr ""
     	 	screen save 14 34 17 86 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,34,53)
    		if ptstr == "y"
      		screen clear box 18 34 22 86 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 FindJobNr()                   ' jobnr passed from MEAS_UPD
local l1 c3 c2 c1 ques $reqstr
  	$instruct = ""
  	ftgdate = blank
  	$nrreqs = 1
  	smartpoke $_ins 0
	vloadif(dpath|"salord07.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
     	messboxwait(" Job Nr NOT found - contact Head Office ",0,0,1)
      	return (-1)                      ' ReturnToMenu
    	end if
    	#jobrec 	  = precord    '???????????????????????
    	custcode    = [Customer_Code]
    	custname    = [Customer_Name]
    	custcontact = [Contact_Name]
    	offtel      = [Office_Tel]
    	offax       = [Office_Fax]
    	hometel     = [Home_Tel]
    	cust_title  = [Title]
    	mobile      = [Mobile/Other_Nr]
    	$salanal    = [SalesAnalysis]
	$email	  = [Email_Addr]	
	custaddr1	  = [Address_1]
	custaddr2   = [Address_2]
	custcity    = [Customer City/Town]
	custpostcode= [Postcode]
	deladdr1    = [Delivery_Address_1]
	deladdr2    = [Delivery_Address_2]
	deladdr3    = [Del_City]
	deladdr4    = [Del_Postcode]

' message "SO7 L921 deladdr3) is:"&str(deladdr3)
' message "deladdr4) is:"&str(deladdr4)
'
' message "SO7 L920 custaddr1) is:"&str(custaddr1)
' message "custaddr2) is:"&str(custaddr2)
' message "custcontact) is:"&str(custcontact)
' message "cust_title) is:"&str(cust_title)
' message " custcity) is:"&str(custcity)
' message "custpostcode) is:"&str(custpostcode)
' message "custcode) is:"&str(custcode)
' message "jobnr) is:"&str(jobnr)

' 	$sameaddr   = [SameAddress]	  	
' message "SO7 L904 custcity) is:"&str(custcity)

'   	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"
' 		[EmailAddr]		=$email
' 		[ManualHold]		="N"
' 	write-record

' message "SO7 L862 [Order_Status]) is:"&str([Order_Status])
' message "$email) is:"&str($email)
'     	if [Order_Status] <> "M"             ' "M"easure
'     	if [Order_Status]="K"             ' "M"easure
'      	messboxwait(" "|jobnr&custname&"not ready for conversion ",0,1,1)
'      	return (1)
'     	elseif [Order_Status]="N"             ' "M"easure
'      	messboxwait(" "|jobnr&custname&"already converted ",0,1,1)
'      	return (1)
'     	end if
    	return (0)
END FUNCTION ' FindJobNr()


FUNCTION CustomerAddr()			' called from L257
' message "L966 custaddr1) is:"&str(custaddr1)
' message "custaddr2) is:"&str(custaddr2)
' message "custcontact) is:"&str(custcontact)
' message "cust_title) is:"&str(cust_title)
' message "SO7 custcity) is:"&str(custcity)
' message "custpostcode) is:"&str(custpostcode)
' message "custcode) is:"&str(custcode)
' message "jobnr) is:"&str(jobnr)

' 	if custcode<>jobnr
' 		$newcust="N"
' 	else
' 		$newcust="Y"
' 	end if
' message "$newcust) is:"&str($newcust)

  	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(11,5,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

' message "$sameaddr) is:"&str($sameaddr)
' 	if $newcust="Y"
' 	  	if $sameaddr = "Y"
' 			if len(deladdr1)>0
' 				custaddr1=deladdr1
' 			else
' 				custaddr1=""
' 			end if
' ' message "L1019 custaddr1) is:"&str(custaddr1)
' 			if len(deladdr2)>0
' 				custaddr2=deladdr2
' 			else
' 				custaddr2=""
' 			end if
' ' 		custaddr2=deladdr2
' 			if len(deladdr3)>0
' 				custcity=deladdr3
' 			else
' 				custcity=""
' 			end if
' ' 		custcity =deladdr3
' 			if len(deladdr4)>0
' 				custpostcode=deladdr4
' 			else
' 				custpostcode=""
' 			end if
'   		end if
' 	end if
	
	Background()
' message "custaddr1) is:"&str(custaddr1)
' ca1=custaddr1
  	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

' message "custaddr2) is:"&str(custaddr2)
  	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)
	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 DeliveryAddr()			' called from L257
' message "custcontact) is:"&str(custcontact)
' message "cust_title) is:"&str(cust_title)
' message "deladdr1) is:"&str(deladdr1)
' message "deladdr2) is:"&str(deladdr2)
' message "deladdr3) is:"&str(deladdr3)
' message "deladdr4) is:"&str(deladdr4)

' 	if custcode<>jobnr
' 		$newcust="N"
' 	else
' 		$newcust="Y"
' 	end if
' message "$newcust) is:"&str($newcust)

' message "$sameaddr) is:"&str($sameaddr)
' 	if $newcust="Y"
' 	  	if $sameaddr = "Y"
' 			if len(deladdr1)>0
' 				custaddr1=deladdr1
' 			else
' 				custaddr1=""
' 			end if
' ' message "L1019 custaddr1) is:"&str(custaddr1)
' 			if len(deladdr2)>0
' 				custaddr2=deladdr2
' 			else
' 				custaddr2=""
' 			end if
' ' 		custaddr2=deladdr2
' 			if len(deladdr3)>0
' 				custcity=deladdr3
' 			else
' 				custcity=""
' 			end if
' ' 		custcity =deladdr3
' 			if len(deladdr4)>0
' 				custpostcode=deladdr4
' 			else
' 				custpostcode=""
' 			end if
'   		end if
' 	end if
	
' message "deladdr1) is:"&str(deladdr1)
  	while true
    		x = fentrybox(" Delivery Address - 1st line ",35,"",deladdr1)' message "x is:"&str(x)
    		if x = 0
      		deladdr1 = proper(ptstr)
      		exit while
    		end if
  	end while

' message "custaddr2) is:"&str(custaddr2)
  	while true
    		x = fentrybox(" Delivery Address - 2nd line (NOT Town or City) ",35,"",deladdr2)' message "x is:"&str(x)
    		if x = 0
      		deladdr2 = 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 "deladdr3) is:"&str(deladdr3)
	while true
    		x=fentrybox(" Delivery Town/City NOT county ",20,city,deladdr3)
	    	if x = 0
     		if len(ptstr)=0
     			continue while
	     	end if
     		deladdr3=ptstr
     		exit while
		end if
  	end while
'     		else
'       		custcity=ptstr
'       		exit while
'     		end if
'     		exit while
'   	end while
' message "custcity) is:"&str(custcity)

' message "deladdr4) is:"&str(deladdr4)
   	while true
    		x=fentrybox(" Delivery Postcode (NOT County!) ",8,"AU*7{[A-Za-z1234567890\ ]U}",deladdr4)
    		if x=0
' 			if custcity="LONDON"
	    		deladdr4 = 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
END FUNCTION 'DeliveryAddr()


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()


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)
	if x<>0
' message "SO7 MAKEIDX at L1155 failed"
	end if
  	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()							' 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 NewBACS()									' L209
' message "SO7 L1299 #deposit) is:"&str(#deposit)
' message "$deptype) is:"&str($deptype)
 	while true
       	x = fentrybox(" Value of BACS to be received ",8,"*8{[-1234567890.]}",#deposit)
       	if x = 0
         		if ptstr=""
           		continue while
         		elseif ptstr=0
           		exit while
         		end if
         		#deposit = value(ptstr)
         		exit while
       	elseif x = -1
			return (0)
'          		continue while
       	end if
    	end while

	locn="U"
	receiptnr = MakeReceiptNr(receiptnr)
     vloadif(dpath|"new_cash.vw")
   	$sales = case left(jobnr,1)("C","X")("R","R")("S","S")("F","F")("P","P")("W","W")("T","T")("Y","Y")
  	vloadif(dpath|"new_cash.vw")
' message "jobnr) is:"&str(jobnr)
' message "BACS or non-BACS rcvd) is:"&str(#deposit)
' message "initbalance) is:"&str(initbalance)
' message "SO7 L1055 newbalance is:"&str(newbalance)
' message "$method) is:"&str($method)
' message "locn) is:"&str(locn)
' 	if $deptype="B"

  	data enter lock
    		[Date_Of_Receipt]   = today
    		[SalAnal]           = $sales
    		[Job_Nr]            = jobnr
    		[Method_Of_Payment] = "BACS"
    		[Abbrv_M]           = "B"
    		[Receipt_Nr]        = receiptnr
    		[Amount_Received]   = #deposit
    		[Branch]            = "U"
    		[Time]              = now
    		[Authorisation]     = "Not yet received"
    		[Entered_By]        = userid
    		[PDQtype]           = ""
    		[Invoiced]          = "N"
  	write-record
END FUNCTION  'NewBACS()


FUNCTION MakeReceiptNr(receiptnr)
  increment(dpath|"receipts.dat",1)
  receiptnr = right("00000"|str(ptval),5)
  return (receiptnr)
END FUNCTION


' FUNCTION TransactRcvd()
'     	if $method="BACS"
' ' calc balance still remaining after prev BACS has been received
' ' message "initbalance is:"&str(initbalance)
' ' message "rcvd is the previous receipt:"&str(rcvd)
' '     		newbalance=initbalance-rcvd        '
' ' message "SO3 L1294 Non BACS newbalance is:"&str(newbalance)' message "Non-BACS newbalance is:"&str(newbalance)
' ' 		if newbalance>0
' ' 		  	messbox(" Enter the remaining"&currency(newbalance)&"as a future BACS receipt? (y/n) ",1,0,1)
' '   			if ptstr == "n"
'
' 		return (1)
' 	else
' 	  	messbox(" Balance shown as remaining is"&currency([Balance_Due])&"- correct? (y/n) ",1,0,1)
'   		if ptstr == "n"
'     			screen clear box 1 1 sch scw 0 0 no-border
' 	    		repaint off
' '     			progress(15,10," Re-calculating balance ",0)
'     			vloadif(dpath|"cust_ord.vws")
' ' 	    		#inv_total = [Invoice_Total]       'message "#inv_total is:"&str(#inv_total)
'     			vloadif(dpath|"cash_bal.vw")
'     			order change key "[Job_Nr]"
' 	    		data query execute "cash_bal.dfq" index "cash_bal.idx"
' ' ŚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄæ
' ' ³ QUERY is:  [Job_Nr] = jobnr                                        ³
' ' ĄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄŁ
'     			if cerror
' '       			#totalrecd = 0                          ' message "#totalrecd is:"&str(#totalrecd)
' 	    		else
' '      	 		#totalrecd = filesum([Amount_Received]) ' message "#totalrecd is:"&str(#totalrecd)
'     			end if                                    ' message "#inv_total is:"&str(#inv_total)
' ' 	    		newbalance = #inv_total - #totalrecd      ' message "newbalance is:"&str(newbalance)
'     			screen clear box 1 1 sch scw 0 0 no-border
'     			repaint off
' ' 	    		messbox(" Balance held in database is confirmed as"&currency(newbalance)&"- correct? (y/n) ",1,0,1)
' '     			if ptstr == "n"
' '       			screen clear box 1 1 sch scw 0 0 no-border
' '       			messbox(" Report details to Head Office ",0,1,1)
' ' ' 	      		$mess = jobnr&"- incorrect balance"&currency(newbalance)&"shown in CUST_ORD file"
' '      	 		cat="SUNDRY"
' '       			x=exception(userid,today,time24,cat,$mess)
' '       			vunloadif(dpath|"unread1.vw")
' ' 	      		vloadif(dpath|"cust_ord.vws")
' '     			end if
' 			return (1)
'  		else									' YES balance is correct
' 			return (1)
'   		end if
'   	end if
' END FUNCTION ' TransactcRcvd()

