'NEW_CUST - temp. holding program for new estimates/orders routines

'!!!!!!!!!!!!!! ?select SHOP user is dealing with

EXTERNAL	sch scw userid cpath dpath messboxwait() fentrybox() vloadif() messbox() fgp bgp
EXTERNAL	navrecs() messline() popuplist() Background()

PUBLIC	ptstr abbrv_name jobnr ptval

GLOBAL	ReturnToMenu() $jobstr EnterCustName() fentline x custname $newcust custcode y1 y2
GLOBAL	$origin $msg custaddr1 H_tel O_tel ESTIMATE_Menu() ORDER_Menu() CONTACT_Menu()
GLOBAL	OFFICE_Menu() EOD_Menu() REPORTS_Menu() OTHER_Menu() WORK_Menu() UpdateCustomer()


MAIN
local m1 m2 m3 m4
	Background()
' message "userid is:"&str(userid)
	if userid=="DAVIDC" or userid=="DAVIDG" or userid=="NSYMDS"
		while true
			m1 = "˙˙˙Jobs˙"
			m2 = "˙˙Office"
			m3 = "˙˙Restart˙"
			m4 = "˙˙˙EXIT˙"
 			x = popuplist(9,30,13,m1&m2&m3&m4,"{Esc} to exit",1,0) ' reinstate when new format used
' 		x = popuplist(9,30,13,m1&m2,"{Esc} to exit",1,0)
			if x = 0
				if ptstr = m1                   ' coming back in
					WORK_Menu()
				elseif ptstr=m2
					OFFICE_Menu()
				elseif ptstr=m3
					messboxwait(" Not yet in use ",0,0,1)
				elseif ptstr=m4
					messboxwait(" Not yet in use ",0,0,1)
				end if
			elseif x=-1
		 		ReturnToMenu()
			end if
		end while
	else
		messboxwait(" Module not yet in use ",0,0,1)
		ReturnToMenu()
	end if

' ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  Background()
  file unload all
  fopen dpath|userid|".jnr" as 1
  fwrite 1 from $jobstr
  fclose 1
  transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION WORK_Menu()
local w1 w2 w3
	Background()
	while true
		file unload all
		w1 = "˙Contacts"
		w2 = "Estimates"
		w3 = "˙˙Orders"
		x = popuplist(9,30,13,w1&w2&w3,"{Esc} to exit",1,0)
		if x = 0
			if ptstr = w1                   '
				CONTACT_Menu()
			elseif ptstr=w2
				ESTIMATE_Menu()
			elseif ptstr=w3
				ORDER_Menu()
			elseif x=-1
		 		return(-1)
			end if
		end if
	end while
END FUNCTION ' WORK_Menu()


FUNCTION OFFICE_Menu()
local o1 o2 o3
	Background()
	file unload all
	o1 = "End˙of˙Day"
	o2 = "˙Reports"
	o3 = "˙˙Other"
	x = popuplist(9,30,13,o1&o2&o3,"{Esc} to exit",1,0)
	if x = 0
		if ptstr = o1                   '
			EOD_Menu()
		elseif ptstr=o2
			REPORTS_Menu()
		elseif ptstr=o3
			OTHER_Menu()
		elseif x=-1
	 		return(-1)
		end if
	end if
END FUNCTION ' OFFICE_Menu()


FUNCTION CONTACT_Menu()
local c1 c2 c3 c4 c5 c6 c7
	Background()
	file unload all
 	EnterCustName()
	c1 = "Update Contact˙details"
	c2 = "˙˙˙˙Send˙samples"
	c3 = "˙˙Arrange˙Measure"
	c4 = "˙˙˙˙˙Send˙Email"
	c5 = "˙˙˙Send˙Statement"
	c6 = "˙˙Select˙ESTIMATE"
	c7 = "˙˙˙˙Select˙ORDER"
	x = popuplist(9,30,20,c1&c2&c3&c4&c5&c6&c7,"{Esc} to exit",1,0) ' reinstate when new format used
	if x=0
	elseif x=-1
		return (-1)
     end if
END FUNCTION ' CONTACTMenu()


FUNCTION ESTIMATE_Menu()
local e1 e2 e3
	Background()
	file unload all
	e1 = "Create˙Estimate"
	e2 = "Update˙Estimate"
	e3 = "Convert˙Estimate"
	x = popuplist(9,30,13,e1&e2&e3,"{Esc} to exit",1,0)
	if x = 0
		if ptstr = e1                   '
' 			EOD_Menu()
		elseif ptstr=e2
' 			REPORTS_Menu()
		elseif ptstr=e3
' 			OTHER_Menu()
		elseif x=-1
	 		return(-1)
		end if
	end if
END FUNCTION ' ESTIMATE_Menu()


FUNCTION ORDER_Menu()
local r1 r2 r3 r4 r5 r6 r7 r8 r9
	Background()
	while true
		file unload all
		r1 = "˙Appointments"
		r2 = "˙Order˙details"
		r3 = "˙Requisitions"
		r4 = "˙Reservations"
		r5 = "˙Cash˙received"
' 		r6 = "˙˙˙Comments"			' in ORD_STAT
		r7 = "Variation˙Order"
		r8 = "˙˙Alter˙Slots"
		r9 = "˙Order˙Status"
		x = popuplist(9,30,20,r1&r2&r3&r4&r5&r7&r8&r9,"{Esc} to exit",1,0) ' reinstate when new format used
		if x=0
			if ptstr = r1                   '
  				execute "altapptX.rf3" in-memory
			elseif ptstr=r2
  				execute "salord2X.rf3" in-memory
			elseif ptstr=r3
  				execute "entreqnX.rf3" in-memory
			elseif ptstr=r4
  				execute "rsvstkBX.rf3" in-memory
			elseif ptstr=r5

' 			elseif ptstr=r6
			elseif ptstr=r7
  				execute "addvarnX.rf3" in-memory
			elseif ptstr=r8
  				execute "altslotX.rf3" in-memory
			elseif ptstr=r9
  				execute "ordstatX.rf3" in-memory
			elseif x=-1
		 		return(-1)
			end if
		elseif x=-1
			return (-1)
	     end if
	end while
END FUNCTION ' ORDER_Menu()


FUNCTION EOD_Menu()
local d1 d2 d3
	Background()
	file unload all
	d1 = "˙Daily˙Routine"
	d2 = "Banking˙Summary"
	d3 = "˙˙Completions"
	x = popuplist(9,30,13,d1&d2&d3,"{Esc} to exit",1,0)
	if x = 0
		if ptstr = d1                   '
			execute "dlyroutX.rf3" in-memory
		elseif ptstr=d2
			execute "dlycashX.rf3" in-memory
		elseif ptstr=d3
			execute "despat2X.rf3" in-memory
		elseif x=-1
	 		return(-1)
		end if
	end if
END FUNCTION ' EOD_Menu()


FUNCTION REPORTS_Menu()
local p1 p2 p3 p4 p5 p6 p7
	Background()
	file unload all
	p1 = "˙Aged˙Debtors"
	p2 = "˙Monthly˙Orders"
	p3 = "˙Monthly˙Sales"
	p4 = "˙Order˙Confirmation"
	p5 = "˙Archived˙Sales"
' 	r6 = "˙˙˙Comments"
' 	r7 = "Variation˙Order"
' 	r8 = "˙˙Alter˙Slots"
' 	r9 = "˙Order˙Status"
	x = popuplist(9,30,20,p1&p2&p3&p4&p5,"{Esc} to exit",1,0) ' reinstate when new format used
	if x=0
		if ptstr = p1                   '
			execute "ageddrsX.rf3" in-memory
		elseif ptstr=p2
			execute "mthyordX.rf3" in-memory
		elseif ptstr=p3
			execute "mthysalX.rf3" in-memory
		elseif ptstr=p4
			execute "despat2X.rf3" in-memory
		elseif ptstr=p5
			execute "despat2X.rf3" in-memory
		elseif ptstr=p6
			execute "despat2X.rf3" in-memory
		elseif ptstr=p7
			execute "despat2X.rf3" in-memory
		elseif x=-1
	 		return(-1)
		end if
	elseif x=-1
		return (-1)
     end if
END FUNCTION ' REPORTS_Menu()


FUNCTION OTHER_Menu()
local t1 t2 t3 t4 t5 t6 t7
	Background()
	file unload all
	t1 = "˙Petty˙Cash"
	t2 = "˙Stock˙Prices"
	t3 = "˙Stockholding"
	t4 = "˙Stock˙Orders"
	t5 = "˙Fitters"
 	t6 = "˙Fitters'˙payments"
 	t7 = "Convert˙Imperial/Metric"
' r8 = "˙˙Alter˙Slots"
' r9 = "˙Order˙Status"
	x = popuplist(9,30,20,t1&t2&t3&t4&t5&t6&t7,"{Esc} to exit",1,0) ' reinstate when new format used
	if x=0
		if ptstr = t1                   '
			execute "pcshentX.rf3" in-memory
		elseif ptstr=t2
' 			REPORTS_Menu()
		elseif ptstr=t3
' 			OTHER_Menu()
		elseif ptstr=t4
' 			OTHER_Menu()
		elseif ptstr=t5
' 			OTHER_Menu()
		elseif ptstr=t6
' 			OTHER_Menu()
		elseif ptstr=t7
' 			OTHER_Menu()
' elseif ptstr=t8
' 			OTHER_Menu()
' elseif ptstr=t9
' 			OTHER_Menu()
		elseif x=-1
	 		return(-1)
		end if
	elseif x=-1
		return (-1)
     end if
END FUNCTION ' OTHER_Menu()


FUNCTION EnterCustName()
  fentline = " Enter Customer's Name (or 1st SEVEN letters if existing customer)"
  while true
    while true
      x = fentrybox(fentline,35,"","")
      if x = 0
        if ptstr = ""
          continue while
        end if
        exit while
      elseif x = -1
        return (-1)
      end if
    end while
    custname = ptstr
    vloadif(dpath|"custsel4.vw")
    order change key [Abbrv_Name]
    abbrv_name = proper(left(custname,7))
    data find "[Abbrv_Name]" equal abbrv_name options ""
    if cerror
      messbox(" Name not on file, is"&chr(34)|custname|chr(34)|" a new customer? (y/n)",1,0,1)
      if ptstr == "y"
        $newcust = "Y"
        custcode = jobnr
        return (0)
      end if
    end if
    vloadif(dpath|"custsel4.vw")

    repaint on
    repaint
    ptval=0
    y1 = format(" CONTACTS ALREADY HELD ON FILE ","M71")
    y2 = format(" {A}dd"&chr(34)|custname|chr(34)|" - {S}elect highlight - {Esc} exits ","M71")
    screen print 4 6 fgp bgp y1
    screen print 21 6 fgp bgp y2
    while true
      ptval = navrecs()
      if ptval = {S} or ptval = {s}
        if (deleted)
          messboxwait(" Deleted record - choose another ",0,0,1)
          continue while
        end if
        $origin  = [Source]            ' message "$origin is:"&str($origin)
        $newcust = "N"
        custname = [Customer_Name]
        abbrv_name = [Abbrv_Name]
        if len([Address_1]) <> 0       ' Same name
          $msg = custname&"of"&[Address_1]|"?" 'message "len($msg)) is:"&str(len($msg))
          messbox($msg,1,1,1)
          if ptstr == "y"
            custcode  = [Customer_Code]
'             $parent   = [Parent]
            custaddr1 = [Address_1]
            H_tel     = [Home_Tel]
            O_tel     = [Office_Tel]
          else
            y2 = format(" {A}dd"&chr(34)|custname|chr(34)|" - {S}elect highlight - {Esc} exits ","M71")
            screen print 21 6 fgp bgp y2
            continue while
          end if
          repaint off
MESSAGE "update details?"
          $msg = "Update customer details? (y/n)" 'message "len($msg)) is:"&str(len($msg))
          messbox($msg,1,1,1)
          if ptstr == "y"
			UpdateCustomer()
		else
			return (0)
          end if
        else                           'if [Address_1] > 0
        end if

      elseif ptval = {A} or ptval = {a}
        messline(" Add"&chr(34)|custname|chr(34)&"to list of Customers? (y/n)",1,1,1,21,6,71)
        if ptstr ! "y"
          $newcust = "Y"
          if x = 0
            exit while
          end if
        else
          exit while
        end if
        repaint off
        return (0)

      elseif ptval = {Esc}
        return (-1)
      end if
    end while
  end while
END FUNCTION 'EnterCustName()


FUNCTION UpdateCustomer()
messboxwait(" Contact detail update routine to be written ",0,0,1)

END FUNCTION ' UpdateCustomer()

