
external	vloadif() dpath vunloadif() remove() X_path Xreppath _SWIP_Crystal() strcount() chkstr() messboxwait()
external	addidxrec() makeidx() messbox()

public	ptstr $jobnrs ptval $dfa $dayftr #jobnrs

global	x PrntAppts() $ftrcode $apptdate PrntInsts() i JobList() Duplicates() $jobstr
global	CreateIndex() NotReady()

' message "MO L2096 $ftrcode) is:"&str($ftrcode)
' message "MO L2111 $apptdate is:"&str($apptdate)

MAIN
single-step off
repaint off
  	vloadif(dpath|"appntmnt.vws")     '
	$dayftr="41988EST001"
	CreateIndex()
 	PrntAppts()								' L254
END MAIN


FUNCTION CreateIndex()
'create index of FTR_LIST by stepping thro' text string and using ADDIDXRECS
  	order change key "[DFA]"
  	x=remove("estdate1.idx")					'message "x is:"&str(x)
  	x=makeidx("appntmnt","estdate1","0",3)     	'message "x is:"&str(x)
  	for i = 1 to 7
    		$dfa=$dayftr|str(i)					' message "$dfa) is:"&str($dfa)
    		data find "[DFA]" equal $dfa options ""
    		x=addidxrec("estdate1.idx",precord,7)    'message "x is:"&str(x)
  	end for
  	order change index "estdate1.idx"
END FUNCTION '	CreateIndex()


FUNCTION PrntAppts()								' L254
local  m1 m2 m3 m4 m5 m6 m7 m8 m9 $ch ma m0 as cfp

  	vloadif(dpath|"prtmeas4.vw")
   	order change index "estdate1.idx"
 	x=PrntInsts(1,1,1)									' L2158
     if x=1
'     		Show()
    		return (1)                         ' NOT ready
     end if
END FUNCTION ' PrntAppts()


FUNCTION PrntInsts(a,b,c)
local  m1 m2 m3 m4 m5 m6 m7 m8 m9 $ch ma m0 as cfp
  	x=NotReady()									'L2238
 	if x=1										' NOT ready
 	  	vunloadif("prtmeas4.vw")
 		return (1)
 	end if

  	vunloadif("X_meas2.vws")
  	x=remove(dpath|"X_meas2.*")						' message "MO L2163 x) is:"&str(x)
  	data query execute "not_del.dfq" Smart4 dpath|"X_meas2" fields "[Fitter_Code;Job_Nr;Appointment_Order;JobNumber;MeasureDate]"
' single-step off
	vloadif(dpath|"prtmeas3.vw")
  	vunloadif("X_meas1.vws")
  	remove(X_path|"X_meas1.*")
	data query execute "not_del.dfq" Smart4 X_path|"X_meas1" fields "[JobNumber|Nickname]"
	if a=1
' message "Printing Attend List"
    		_SWIP_Crystal(Xreppath|"Xmeasur0","S",0,1,"")		'message "L2172 should have printed Xmeasur0"
	end if
  	vunloadif("prtmeas3.vw")

  	vloadif(dpath|"prtmeas4.vw")
   	order change index "estdate1.idx"

	x=Duplicates()

' 		'create index of CUST_ORD by stepping thro' text string and using ADDIDXRECS
' message "MO L2161 $jobnrs is:"&str($jobnrs)
   	x=strcount($jobnrs)                  				' message "Nr of de-duplicated jobs is:"&str(ptval)
   	vloadif(dpath|"measure3.vw")
   	order change index "insts2prt.idx"
    	remove(X_path|"X_nar_a.*")
    	data query execute "not_del.dfq" Smart4 X_path|"X_nar_a" fields "[Job_Nr|MeasUpdated]"
    	vunloadif("X_nar_a.vws")
	if b=1
    		_SWIP_Crystal(Xreppath|"Xaptnot4","S",0,1,"")
	end if
	if c=1
    		_SWIP_Crystal(Xreppath|"Xaptnot5","S",0,1,"")
	end if
' message "L2196 should have printed Xaptnot4 & 5"

  	vloadif(dpath|"measure3.vw")
   	order change index "insts2prt.idx"
    	remove(X_path|"X_nar_b.*")
    	data query execute "not_del.dfq" Smart4 X_path|"X_nar_b" fields "[1|"|str(dbinfo(db_fields))|"]"
'    	_SWIP_Crystal(Xreppath|"Xaptnote","S",0,1,"")
'    	_SWIP_Crystal(Xreppath|"Xmeasur1","EP",0,1,"")
												'in X_nar_b, print/show StreetMap
    	vunloadif("X_nar_b.vws")
  	vunloadif("prtmeas4.vw")
  	vunloadif("prtmeas3.vw")
END FUNCTION ' PrintInsts()


FUNCTION NotReady()									' [Status] must be BLANK or M; T or N are not ready
local z z1 $ready
' already in dpath|"prtmeas???.vw")
	$ready=""
  	data goto record first							'$jobnrs=[JobNumber]
	$ready=[MeasStatus]
	if $ready=""
		$ready=""
	end if
  	data goto record next
  	for i = 2 to 7                 'create text string of Job Nrs
    		x = chkstr([MeasStatus],$ready)
		z=len([MeasStatus])
		z1=[MeasStatus]							'message "length of"&z1&"is:"&str(z)
		if [MeasStatus]=""
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		end if
    		if x = -1
      		$ready=$ready|[MeasStatus]				' message "L2262 $ready) is:"&str($ready)
    		end if
    		data goto record next
  	end for										'message "De-duplicated job nrs are:"&str($ready)
												'message "L2279 $ready) is:"&str($ready)
	if $ready=""
    		x = messboxwait(" No measure appointments to print out ",0,0,1)
	  	vunloadif("measures.vws")
		return (1)
	end if
  	x=strcount($ready)                  				'message "ptval is:"&str(ptval)
  	#jobnrs = ptval								' message "#jobnrs) is:"&str(#jobnrs)
												' message "MO L2291 $ready is:"&str($ready)

	if $ready!"T"
	  	messbox(" This day has some Temporary appts - continue anyway? (y/n) ",1,0,1)
  		if ptstr == "n"
	  		vunloadif("measures.vws")
			return (1)
    		end if

	elseif $ready!"N"
	  	messbox(" Some Measures have NOT had details updated - continue? (y/n) ",1,0,1)
  		if ptstr == "n"
	  		vunloadif("measures.vws")
			return (1)
    		end if
	end if
  	vunloadif("measures.vws")
END FUNCTION ' NotReady()



FUNCTION Duplicates()
local z z1 jobnr1										' already in dpath|"prtmeas4.vw")
	$jobnrs=""
  	data goto record first
	$jobnrs=[JobNumber]
	if $jobnrs="None"
		$jobnrs=""
	elseif $jobnrs="ABSENT"
		$jobnrs=""
	elseif $jobnrs="SHOWRM"
		$jobnrs=""
	end if
  	data goto record next
  	for i = 2 to records                 				'create text string of Job Nrs
    		x = chkstr([JobNumber],$jobnrs)
		z=len([JobNumber])
		z1=[JobNumber]								'message "length of"&z1&"is:"&str(z)
		if [JobNumber]="None"
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		elseif [JobNumber]="ABSENT"
			if i=records
				exit for
			end if
	    		data goto record next
 			continue for
		end if
    		if x = -1
      		$jobnrs = $jobnrs&[JobNumber]
    		end if
    		data goto record next
  	end for										' message "De-duplicated job nrs are:"&str($jobnrs)
  	x=strcount($jobnrs)                  				'message "ptval is:"&str(ptval)
  	#jobnrs = ptval								' message "#jobnrs) is:"&str(#jobnrs)
												' message "$jobnrs) is:"&str($jobnrs)
	if $jobnrs!"X99999"
		messboxwait(" Cannot print - this day has some Temporary appt's ",0,0,1)
		return (1)
	end if

  	vloadif(dpath|"measures.vws")
  	order change key "[Job_Nr]"
  	remove("insts2prt.idx")
  	x = makeidx("measures","insts2prt","0",3)     		'message "x is:"&str(x)
  	for i = 1 to #jobnrs
    		jobnr1 = group($jobnrs,i)
    		data find "[Job_Nr]" equal jobnr1 options ""
    		x = addidxrec("insts2prt.idx",precord,7)    ' message "x is:"&str(x)
  	end for
  	vunloadif("measures.vws")
END FUNCTION ' Duplicates()


FUNCTION 	JobList()
message "$jobnrs is:"&str($jobnrs)
  	x=strcount($jobnrs)                  				'
message "Nr of jobs in day is:"&str(ptval)
END FUNCTION '	JobList()

