' IMMT_RSV - lists imminent, unconverted reservations shown in Fitting Diary

'copied from IMMT_BKG

external   vkeybox() sch scw progress() messbox() vloadif() base $menu addidxrec() makeidx()
external   vunloadif() dpath fentrybox() chkdate() areas greeting cpath remove() userid
external   PrintReport() popuplist() fgp bgp ChooseBranches() messboxwait() Background()
external   _SWIP_Crystal() Xreppath X_path strcount() findpopup()

public     ptstr indate monthend fullmonth briefmonth enddate $base $basenames #basenames ptval
public     choice $shop_name $shop $phonenr $ctg jobnr

global     x ReturnToMenu() i custcode s1 s2 s3 s4 s5 s6 s7 $place leftjob p br_name Job_Locn() ChooseShops2Select()


MAIN
  	single-step off
	Background()
  	file unload all

 	while true
		screen clear box 1 1 sch scw 0 0 no-border
	  	x=ChooseShops2Select()			'message "x) is:"&str(x)
     	if x = -1
			ReturnToMenu()
	     end if

		$base=leftjob						'message "leftjob is:"&str(leftjob)
		enddate=date2(days(today)+7)				'message "enddate is:"&str(enddate)
		x=remove("immrsv1.idx")			'message "remove is:"&str(x)
	     vloadif(dpath|"appntmnt.vws")
		x=makeidx("appntmnt","immrsv1.idx","0",1)	'message "makeidx is:"&str(x)
	     order change key "[Date]"
		data find "[Date]" equal enddate options ""
		data goto record previous
	 	progress(15,10," Building file of appointments from"&date2(today)&"to"&date2(enddate)&" ",0)
		while days([Date])>days(today)
		     x = addidxrec("immrsv1.idx",precord,7)    'message "x is:"&str(x)
			data goto record previous
		end while
		order change index "immrsv1.idx"		' set number of days selected
' TOTAL LIST OF APPTS FOR NEXT 7 DAYS NOW LISTED

' now query to find left([DelAddr&Code],2)=$base|"R"
		data query execute "immtrsv1.dfq" index "immrsv2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'  left([DelAddr&Code],2)=$base|"R"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		if cerror
			messboxwait(" No Fitters' reservations found for next 7 days (50) ",0,0,1)
			exit while
		end if

'now exclude right([Nickname],3)="EST"
		data query execute "not_est2.dfq" index "immrsv3.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' right([N_name],3)<>"EST"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		if cerror
			messboxwait(" No Fitters' reservations found for next 7 days (60) ",0,0,1)
			exit while
		end if

    		vunloadif("appntmnt.vws")
     	vloadif(dpath|"imm_rsv1.vw")
		order change index "immrsv3.idx"
		remove(X_path|"X_immrs2.*")
		data query execute "not_del.dfq" Smart4 X_path|"X_immrs2" fields "[Date|Location]"
		if cerror
			messboxwait(" No Fitters' reservations found for next 7 days (70) ",0,0,1)
' 			messbox(" No data found ",0,0,1)
' 				continue while
			exit while
		end if
	
		vunloadif("X_immbkg.vws")
     	vunloadif("imm_rsv1.vw")
		vunloadif("imm_bkg3.vw")
		vunloadif("imm_bkg2.vw")					'   ClearHardSpaces()
		_SWIP_Crystal(Xreppath|"X_immrs1","S",0,1,"")
		exit while

	end while
	
	ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  screen clear box 1 1 sch scw 0 0 no-border
  repaint off
  file unload all
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION Job_Locn()
  	s1 = "Warehouse"
  	s2 = "Trade"
  	s3 = "Fulham"
  	s4 = "Raynes"
  	s5 = "Sheen"
  	s7 = "Putney"
  	while true
    		x = popuplist(8,37,15,s3&s7&s4&s5&s2&s1,"Order",1,0)
    		if x = -1
      		return (-1)
    		end if
    		$place = ptstr
    		messbox(" Confirm"&upper($place)&"shop? (y/n) ",1,1,1)
    		if ptstr == "y"
      		leftjob=left($place,1)
      		return (0)
    		else
      		continue while
    		end if
  	end while
END FUNCTION 'Job_Locn()


FUNCTION ChooseShops2Select()
local leftjob currec
	s1 = "Warehouse"
  	s2 = "Trade"
  	s3 = "Fulham"
  	s4 = "Raynes"
  	s5 = "Sheen"
  	s7 = "Putney"

  	if base="O"                         ' choice of Warehouse etc
    		leftjob=Job_Locn()
    		if leftjob = -1
	      	return (-1)
      	end if

  	elseif base="F"
    		while true
      		x = popuplist(8,57,15,s3&S7&s2,"",1,0)
      		if x = -1
	      		return (-1)
      		end if
      		$place = ptstr
      		leftjob=left($place,1)
      		exit while
    		end while

  	elseif base="S"
    		while true
	      	x = popuplist(8,57,15,s5&s4,"",1,0)
      		if x = -1
	      		return (-1)
      		end if
      		$place = ptstr
      		leftjob=left($place,1)
      		exit while
    		end while
	else
		leftjob=Job_Locn()
	end if
END FUNCTION 'ChooseShops2Select()
