'ADDNANCL - records details of add'n stk ancls needed by fitters for existing jobs

' Paul selects fitter; job nr; items (using F4 selection from ADD_REQN.PF3)

' prints record for signature by fitter

' record created in new file ADDNANCL.db

external	fentrybox() vloadif() dpath bpopdb() shopmask Background() makeidx() ipath fgp bbd vkeybox()
external	messbox() fdp entryline() messline() bgp strcount() delstr() addidxrec() remove()
external  messboxwait() userid vunloadif() cpath
external  X_path _SWIP_Crystal() Xreppath sch scw

public	ptstr dsa jobnr ptval psa s_shwreq	#recnr $save_screen

global	x SelectFitter() ftrcode ftrname prodcode lastsuppcode suppcode
global	prodMRC #unitcost $seltype $itemtype #ordwidth $backing desMRC $unit $keypress $prodend
global	#refnr refcode #prodrec $uos suppname #deflen $resvn $popstr prodname ChooseLength()
global	#ordlength ordref orderby purchorderdate delquot $comment specterm #reqncost
global	$auth $ccwcode $rollnr $o_ride $mess1 y1 y3 y2 $mess2 nr6 #maxupd upd_new #reqnrec
global    #area $mess3 $text1 $text2 $text3 $smlr $disc priceauthority #ftrs
global	#nritems strtrow $stat $ftrs $nickname deladdr1 custname
global	WriteRecord() #precnr PrintList() AddAncillary() OrderedBy() CheckCustomer() ReturnToMenu()



MAIN
single-step off
file unload all
	Background()
	while true
		x=SelectFitter()
		if x = -1
			file unload all
      		exit while
    		end if					' message "ftrname) is:"&str(ftrname)
	
		while true
			x = fentrybox(" Enter Job Nr ",6,shopmask,"")
			if x = -1
			     ReturnToMenu()
			end if
			jobnr = ptstr    'message "show custname and delivery address"

			x=CheckCustomer()
		     if x = -1
 				continue while
		     end if

			x=messbox(custname&"at"&deladdr1|"? (y/n) ",1,1,1)
			if ptstr == "y"
				exit while
 		     else
			     continue while
			end if
		     if x = -1
			     continue while
' 		     else
' 			     exit while
			end if

		end while

		repaint off

      	AddAncillary("stckancl.idx")

		PrintList()				' print list for signature

	end while

END MAIN


FUNCTION ReturnToMenu()
	Background()
	file unload all
	transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION AddAncillary(typeidx)
local origview2 bdb y2
     vloadif(dpath|"prodselA.vw")
     order change index ipath|typeidx
     bdb = bpopdb("prodselA",4,"","[Product_MRC]","L35","[abbrv]","L4","[Product_Code]",7,33,20,70,"",0)
     if bdb = -1
		return (-1)
     else
     	prodcode = ptstr               '
		prodname=[Product_MRC]
     end if
     #prodrec = record
     $uos     = [Unit_Of_Sale]      'message "$uos is:"&str($uos)
	$itemtype  = [Item_Type]
     prodMRC    = [Product_MRC]
     $backing   = [Backing]
	$backing = "N/A"

	while true                      ' start selection of widths colours etc
     	x = ChooseLength()
          if x = -1
          	return (-1)
          end if
        	exit while
	end while

' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ Ordered by?                                                        ³
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
     repaint off
     y2 = format(" Person authorising extras ","M29")
     screen print 20 26 fgp bgp y2
     OrderedBy()
	Background()
     vloadif(dpath|"prodselA.vw")

	WriteRecord()

END FUNCTION ' AddAncillary()


FUNCTION OrderedBy()
local $save_screen $username
	while true
  		repaint off
	     vloadif(dpath|"userid.vw")
		$username = userid
	     data query execute "addancl3.dfq" index "addancl2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Menu]="Shop"
' and
' not (deleted)
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
		order sort now dictionary "x" fields "[author]" ascending
' 		data goto record first
		x = bpopdb("userid",26,"","[Name]","L26","[author]","L0","[greeting]",8,26,19,54,"",1)
		if x = -1
			messbox(" Must Select! ",0,0,1)
		else
	 	     orderby = [Name]
x=len(orderby)
message "x) is:"&str(x)
		     screen shortrestore dsa
		     repaint off
		     vunloadif("userid.vw")
		     exit while
		end if
	end while
END FUNCTION 'OrderedBy()


FUNCTION ChooseLength()        ' Enter & check Length
	#ordwidth = value([Widths_Available])
	while true
 		x = fentrybox(" Enter Quantity required ",3,"{#{#{#}}}",1)	'message "92/ x is:"&str(x)
	     if x = -1
		     continue while
		end if
		#ordlength = value(ptstr)
	     messbox(" Confirm"&str(#ordlength)&"off"&prodMRC|"? (y/n) ",1,1,1)
	     if ptstr == "Y"
			exit while
	     else
		     continue while
	     end if
	end while
	repaint off
END FUNCTION ' ChooseLength()


FUNCTION WriteRecord()
' message "ftrcode is:"&str(ftrcode)
' message "jobnr is:"&str(jobnr)
' message "prodcode is:"&str(prodcode)
' message "#ordlength is:"&str(#ordlength)
' message "prodMRC is:"&str(prodMRC)
' message "desMRC is:"&str(desMRC)

	vloadif(dpath|"addnancl.vws")
	data enter lock
		[FtrCode]			= ftrcode
     	[JobNr]             = jobnr
		[ProdCode]          = prodcode
		[DateCreated]		= today
		[LengthQuantity]    = #ordlength
' 		[Authority]		= userid
x=len(orderby)
message "x) is:"&str(x)
		[Authority]		= orderby
' 		[Width]             = #ordwidth
		[ProdMRC]			= prodMRC
	write-record
  	#recnr=[RecNr]					'message "#recnr) is:"&str(#recnr)

END FUNCTION 'WriteRecord()


FUNCTION PrintList()
	vloadif(dpath|"addancl1.vw")
	vunloadif("X_adancl.vws")
	remove(X_path|"X_adancl.*")
     data query execute "addancl2.dfq" index "addancl2.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' ³ [RecNr]=#recnr
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	data query execute "not_del.dfq" Smart4 X_path|"X_adancl" fields "[JobNr;DateCreated;ProdMRC;LengthQuantity;CustOrd_Name;Delivery_Address_1;Delivery_Address_2;Fitter_Name;issuer;Rec_Nr;Authority]"
'     _SWIP_Crystal(Xreppath|"addancl1","EP",0,1,"")

     _SWIP_Crystal(Xreppath|"addancl1","P",0,1,"")

'   _SWIP_Crystal(Xreppath|"$inv_1","EP",0,1,invpath|$nextinvnr|".pdf")

END FUNCTION ' PrintList()


FUNCTION SelectFitter()
local    bpop_ret i sr er
	vloadif(dpath|"ftrlist1.vw")
	order change physical
     data query execute "actftrs1.dfq" index "actftrs1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
' [Active]="YES"
' and
' [Ftr_Est]="F"
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
	bpop_ret = bpopdb("ftrlist1",6,"","[Fitter Name]","L25","[Fitter_Code]","L0","[Nickname]",7,31,21,58,"",0)' message "bpop_ret) is:"&str(bpop_ret)
	if bpop_ret = -1
    		return (-1)
	end if
     ftrcode = [Fitter_Code]			'message "ftrcode) is:"&str(ftrcode)
 	ftrname = [Fitter Name]			'message "ftrname) is:"&str(ftrname)
  	repaint off
END FUNCTION '  SelectFitter()


FUNCTION CheckCustomer()
	error off
     vloadif(dpath|"cust_ord.vws")
     order change key "[Job_Nr]"
     data find "[Job_Nr]" equal jobnr options ""
     if cerror                               '   if none - then return
  		x = messboxwait(" Job Nr not found ",0,0,1)
	     return (-1)
     end if
	deladdr1 = [Delivery_Address_1]		'message "deladdr1 is:"&str(deladdr1)
	custname = [CustOrd_Name]			'message "custname is:"&str(custname)
     vunloadif("cust_ord.vws")
END FUNCTION '  CheckCustomer()

