'SUPP_PRC - Head Office; produces summary of unprocessed purchase invoice;
'           creates text file for reading into SUN Accounts

' 240615	 altered to deal with revised HMRC requirements re Input VAT - L296

external   vkeybox() sch scw progress() messbox() vloadif() base $menu userid
external   vunloadif() dpath fentrybox() chkdate() areas greeting cpath $drive
external   popuplist() fgp bgp ChooseBranch() remove() Background() vatrate
external   _SWIP_Crystal() Xreppath X_path bpopdb() increment() messboxwait()
external   navrecs()

public     ptstr ptval #total #vattotal #net #value z $rephdr #vat
public     $shop_name $shop_init $pcref

global     x ReturnToMenu() Report() nr i SUN_File() invdate Titles() $disc_yn #disc #discvalue
global     #lines $filename $today a baccpath $bxtfile ProcessInvoices()
global     accpath WriteLine() acc_code acc_period thisday $lineval $dr_cr
global     $jnl_type $operator $jnl_ref $jnl_desc $entry_date $entry_period
global     blank1 fixed1 y $line_end $value $jnl_nr $jnl_line CalcVal()
global     $due_date SetConstants() $hdr $txtfile acctgperiod ReportRedone()
global     txtfileday AmendRecords()


MAIN
  	single-step off
  	Background()
  	file unload all
'   ChooseSUNAccgPeriod()			'enter SUN accounting period
  	$rephdr = left(date2(today),2)|mid(date2(today),4,2)|right(date2(today),4)|".jif" ' message "$rephdr is:"&str($rephdr)
  	while true
    		x = fentrybox(" Enter Processing reference ",12,"",$rephdr)
    		if x = -1
      		file unload all
      		ReturnToMenu()
    		end if
    		$rephdr = upper(ptstr)
    		exit while
  	end while

	while true
  		x=Report()			' listing of invoices NOT processed
  		if x=-1
    			file unload all
    			ReturnToMenu()
  		elseif x=0				' draft correct
    			vloadif(dpath|"sinvproc.vw")		'
    			order change index "sinvprc1.idx"
    			#lines=records				'message "#lines is:"&str(#lines)
    			file unload all
    			vloadif(dpath|"sinvproc.vw")		'
    			order change index "sinvprc1.idx"
    			#total=filesum([Gross_Value])		'message "#total is:"&str(#total)
'       #vattotal=fixed(filesum([VAT]),2)		'message "#vattotal is:"&str(#vattotal)
    			messbox(" Confirm total on summary is"&str(currency(#total))&"? (y/n) ",1,1,1)
    			if ptstr == "n"
      			messbox(" Totals do not agree - amend records? (y/n) ",1,1,1)
      			if ptstr == "n"
        				file unload all
        				ReturnToMenu()
      			else
        				AmendRecords()
      			end if
    			else
      			messbox(" Do you wish to amend any records on this list? (y/n) ",1,1,1)
      			if ptstr == "y"
        				AmendRecords()
      			end if
      			exit while
    			end if
		end if
  	end while
  	file unload all
  	ReportRedone()
  	messbox(" Continue and process these invoices? (y/n) ",1,1,1)
  	if ptstr == "y"
    		ProcessInvoices()							'L157	
  	else
    		ReturnToMenu()
  	end if
  	ReturnToMenu()

END MAIN


FUNCTION ReturnToMenu()
  	Background()
  	file unload all
  	transfer cpath|"pm_menu.psl" in-memory
END FUNCTION ' ReturnToMenu()


FUNCTION Report()
  	messbox(" Print list of unprocessed Suppliers' invoices? (y/n) ",1,1,1)
  	if ptstr == "n"
    		return (-1)
  	else											'message "print list of unpaid items"
    		vloadif(dpath|"sinvproc.vw")		'
    		order change physical
    		data query execute "sinvprc1.dfq" index "sinvprc1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   not (deleted)
'   and
'   [Posted]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    		if cerror
      		messboxwait(" No unprocessed Suppliers' invoices",0,0,1)
      		return (1)
    		elseif [SUN_Period]=blank
      		messboxwait(" SUN Acct'g periods NOT entered - amend file",0,0,1)
      		return (1)
    		else
      		remove(X_path|"X_sinvpr.*")
      		order sort now dictionary "sinvprc2.idx" fields "[Name]" ascending
      		data query execute "not_del.dfq" Smart4 X_path|"X_sinvpr" fields "[Inv_Date;Inv_Nr;Net_Value;Gross_Value;Name;header;SUN_code;ACC631001;ACC631002;ACC631003;ACC631004;ACC631005;ACC631006;ACC631007;ACC631008;ACC631009;ACC631010]"
      		vunloadif("X_sinvpr.vws")
' message "SP L116\ report rem'd out"
       		_SWIP_Crystal(Xreppath|"sinvprc1","S",0,1,"")
    		end if
  	end if
  	return (0)
END FUNCTION 'Report()


FUNCTION ReportRedone()
    	vloadif(dpath|"sinvproc.vw")		'
    	order change physical
    	data query execute "sinvprc1.dfq" index "sinvprc1.idx"
' ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
'   not (deleted)
'   and
'   [Posted]=blank
' ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    	if cerror
      	messboxwait(" No unprocessed Suppliers' invoices",0,0,1)
      	return (1)
    	elseif [SUN_Period]=blank
      	messboxwait(" SUN Acct'g periods NOT entered - amend file",0,0,1)
      	return (1)
    	else
      	remove(X_path|"X_sinvpr.*")
      	order sort now dictionary "sinvprc2.idx" fields "[Name]" ascending
      	data query execute "not_del.dfq" Smart4 X_path|"X_sinvpr" fields "[Inv_Date;Inv_Nr;Net_Value;Gross_Value;Name;header;SUN_code;ACC631001;ACC631002;ACC631003;ACC631004;ACC631005;ACC631006;ACC631007;ACC631008;ACC631009;ACC631010]"
      	vunloadif("X_sinvpr.vws")
'       _SWIP_Crystal(Xreppath|"sinv_prc","P",0,1,"")
' message "SP L145\ report rem'd out"
       	_SWIP_Crystal(Xreppath|"sinvprc1","S",0,1,"")
    	end if
  	return (0)
END FUNCTION 'ReportRedone()


FUNCTION ProcessInvoices()
  	file unload all
  	vloadif(dpath|"sinvproc.vw")		'
  	order change index "sinvprc2.idx"

' messboxwait(" L157\ write rem'd out",0,0,1)
   	for i = 1 to records
    		lock-record                        ' update record with inv nr & date
       		[Posted]=today
    		write-record
    		data goto record next
   	end for

'print file copy of report - ref nr on report will be shopinit & date (e.g. H040806)
' message "L166\ report rem'd out"
   	_SWIP_Crystal(Xreppath|"sinv_lst","P",0,1,"")
  	$hdr=[header]				'message "$hdr is:"&str($hdr)
  	SUN_File()				'create text file for posting in SUN
END FUNCTION 'ProcessInvoices()


FUNCTION SUN_File()
' save using sheet ref nr (eg H040806.txt)

' for each record in subset
' structure of SUN import file
' line 1 - total amount			81???     crs account
' line 2 - total VAT			822
' line 3 etc - P&L a/c items		631???    stock account

  	thisday	=left(today,2)|mid(today,4,2)|right(today,4)
'   invdate	=right(date2([Inv_Date]),4)|mid(date2([Inv_Date]),4,2)|left(date2([Inv_Date]),2)
' message "L218\ invdate is:"&str(invdate)
  	txtfileday	=left(today,2)|mid(today,4,2)|right(today,4)

  	accpath="T:\"      		' message "accpath is:"&str(accpath)
  	$txtfile=txtfileday|".jif"			'message "$txtfile is:"&str($txtfile)
  	remove(accpath|$txtfile)

  	baccpath=$drive|"reports\SINV_PRC\"   'message "baccpath is:"&str(baccpath)
'   $bxtfile=$hdr|".bxt"			'
'   $bxtfile=thisday|".bxt"			'message "$bxtfile is:"&str($bxtfile)
'   $txtfile=txtfileday|".txt"			'
  	$bxtfile=txtfileday|".bsv"			'message "$bxtfile is:"&str($bxtfile)
  	remove(baccpath|$bxtfile)

  	SetConstants()
  	fopen accpath|$txtfile as 1
  	fopen baccpath|$bxtfile as 2

  	data goto record first
  	for i=1 to #lines			' write P&L code lines
    		acc_period=[SUN_Period]		' message "acc_period is:"&str(acc_period)
    		$entry_period=right(acc_period,4)|"0"|left(acc_period,2) 'message "$entry_period is:"&str($entry_period)
    		acc_period=$entry_period						' message "acc_period) is:"&str(acc_period)
    		invdate	=right(date2([Inv_Date]),4)|mid(date2([Inv_Date]),4,2)|left(date2([Inv_Date]),2)	' message "L218\ invdate is:"&str(invdate)

' write 1st part				'Cr entry to post to 621
    		acc_code	=[SUN_code]
    		acc_code	=left(acc_code|"               ",15)
    		CalcVal([Gross_Value])			'message "in write line 1 - $lineval is:"&str($lineval)
    		$dr_cr	="C"
    		$jnl_ref	=[Inv_Nr]
    		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
    		$jnl_desc	=left("Purchase Invoice"|"                         ",25)
    		WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)

' write 2nd part				'Dr entry to post to 822
    		acc_code	="822"
    		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
'     #vat	=val([Gross_Value]-[Net_Value])
    		#vat	=[Gross_Value]-[Net_Value]	' message "#vat is:"&str(#vat)		'     #vat	=val(#vat)
    		$value=str(#vat*1000)		'message "$value) is:"&str($value)
    		$lineval=right("000000000000000000"|$value,18)	' message "in CalcVal $lineval is:"&str($lineval)
'     CalcVal(#vat)			'message "in write line 2 - VAT is:"&str($lineval)
    		$dr_cr	="D"
    		$jnl_ref	=[Inv_Nr]
    		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
    		$jnl_desc	=left([Name]|"                         ",25)			'     $jnl_desc	=left("Purchase Invoice"|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)

		$disc_yn=[D_YN]							'message "$disc_yn) is:"&str($disc_yn)
		if $disc_yn="Y"
			#disc=[Disc_Amt]						'message "#disc) is:"&str(#disc)
' write 3rd part - CR entry to post to 822 IF Settlement Discount
	    		acc_code	="822"
    			acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
    			#vat	=[Gross_Value]-[Net_Value]				'message "#vat is:"&str(#vat)							'     #vat	=val(#vat)
	    		#vat=#vat*#disc							'message "#vat is:"&str(#vat)							'     #vat	=val(#vat)
    			$value=#vat*1000							'message "$value) is:"&str($value)
			#discvalue=str($value)						'message "sp L257 #discvalue) is:"&str(#discvalue)
			#discvalue=str(int($value))					'message "sp L260 #discvalue) is:"&str(#discvalue)
    			$lineval=right("000000000000000000"|#discvalue,18)	'message "in CalcVal $lineval is:"&str($lineval)
    			$dr_cr	="C"
	    		$jnl_ref	=[Inv_Nr]
    			$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
    			$jnl_desc	=left("Sett disc VAT "|[Name]|"                         ",25)			'     $jnl_desc	=left("Purchase Invoice"|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)

' write 4th part				'DR entry to post to 202 IF Settlement Discount
    			acc_code	="202"
    			acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
    			$dr_cr	="D"
    			$jnl_ref	=[Inv_Nr]
    			$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
		end if

' for each stock code
    		if [ACC631001]>.01
      		acc_code	="631001"
      		acc_code	=left(acc_code|"               ",15)	' message "acc_code is:"&str(acc_code)
		     #net	=fixed(([ACC631001]),2)					' message "#net for stock code is:"&str(#net)
		     CalcVal(val(#net))			'
' message "in write Stock Code lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631002]>.01
      		acc_code	="631002"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631002]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631003]>.01
      		acc_code	="631003"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631003]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631004]>.01
      		acc_code	="631004"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631004]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631005]>.01
      		acc_code	="631005"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631005]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631006]>.01
      		acc_code	="631006"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631006]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631007]>.01
      		acc_code	="631007"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631007]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631008]>.01
      		acc_code	="631008"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631008]),2)	'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631009]>.01
      		acc_code	="631009"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631009]),2)		'message "#net is:"&str(#net)
      		CalcVal(val(#net))			' message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if

    		if [ACC631010]>.01
      		acc_code	="631010"
      		acc_code	=left(acc_code|"               ",15)	'message "acc_code is:"&str(acc_code)
      		#net	=fixed(([ACC631010]),2)		'message "#net is:"&str(#net)
      		CalcVal(val(#net))			'message "in write PL lines - $lineval is:"&str($lineval)
      		$dr_cr	="D"
      		$jnl_ref	=[Inv_Nr]
      		$jnl_ref	=left($jnl_ref|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
      		$jnl_desc	=left([Name]|"                         ",25)
WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
    		end if
    		data goto record next
  	end for
  	fclose 1
  	fclose 2
END FUNCTION 'SUN_File()


FUNCTION SetConstants()
' message "thisday is:"&str(thisday)
  	blank1	="  "
  	fixed1	="N"
  	$jnl_nr	="0000000"
  	$jnl_line	="00000"
  	$jnl_type	="PI   "
  	$operator	="JDC"
  	$today	=left(today,2)|mid(today,4,2)|right(today,4)
'   $jnl_ref	=left("pe"&$today|"             ",13)	'message "$jnl_ref) is:"&str($jnl_ref)
  	$entry_date	=thisday
'   $entry_period	=acc_period
  	$due_date	="        "
$line_end="      000000000000000000000000                     000000000000000000000000000000000000"
END FUNCTION 'SetConstants()


FUNCTION WriteLine(acc_code,acc_period,invdate,blank1,fixed1,$jnl_nr,$jnl_line,blank1,$lineval,$dr_cr,blank1,$jnl_type,$operator,blank1,$jnl_ref,blank1,$jnl_desc,$entry_date,$entry_period,$due_date,$line_end)
'   $lineval=""
  fwrite 1 length 15 from acc_code
  fwrite 1 length 7 from acc_period
' message "acc_code is:"&str(acc_code)
' message "acc_period is:"&str(acc_period)
' message "invdate is:"&str(invdate)
  fwrite 1 length 8 from invdate
  fwrite 1 length 2 from blank1
  fwrite 1 length 1 from fixed1
  fwrite 1 length 7 from $jnl_nr
  fwrite 1 length 5 from $jnl_line
  fwrite 1 length 2 from blank1
  fwrite 1 length 18 from $lineval
  fwrite 1 length 1 from $dr_cr
  fwrite 1 length 1 from "F"   		' F or W - "Force" or "Withheld"
  fwrite 1 length 5 from $jnl_type
  fwrite 1 length 3 from $operator
  fwrite 1 length 2 from blank1
  fwrite 1 length 13 from $jnl_ref
  fwrite 1 length 2 from blank1
  fwrite 1 length 25 from $jnl_desc
'   fwrite 1 length 2 from blank1
  fwrite 1 length 8 from $entry_date
  fwrite 1 length 7 from $entry_period
  fwrite 1 length 8 from $due_date
  fwrite 1 from $line_end

  fwrite 2 length 15 from acc_code
  fwrite 2 length 7 from acc_period
  fwrite 2 length 8 from invdate
  fwrite 2 length 2 from blank1
  fwrite 2 length 1 from fixed1
  fwrite 2 length 7 from $jnl_nr
  fwrite 2 length 5 from $jnl_line
  fwrite 2 length 2 from blank1
  fwrite 2 length 18 from $lineval
  fwrite 2 length 1 from $dr_cr
  fwrite 2 length 1 from "F"   		' F or W - "Force" or "Withheld"
  fwrite 2 length 5 from $jnl_type
  fwrite 2 length 3 from $operator
  fwrite 2 length 2 from blank1
  fwrite 2 length 13 from $jnl_ref
  fwrite 2 length 2 from blank1
  fwrite 2 length 25 from $jnl_desc
'   fwrite 1 length 2 from blank1
  fwrite 2 length 8 from $entry_date
  fwrite 2 length 7 from $entry_period
  fwrite 2 length 8 from $due_date
  fwrite 2 from $line_end
END FUNCTION ' WriteLine(x)


FUNCTION CalcVal(z)										' message "z is:"&str(z)
  	$value=str(z*1000)									' message "$value) is:"&str($value)
  	$lineval=right("000000000000000000"|$value,18)			' message "in CalcVal $lineval is:"&str($lineval)
END FUNCTION ' CalcVal()


Function AmendRecords()
  	vloadif(dpath|"suppprc1.vw")
  	order change index "sinvprc1.idx"
  	order sort now dictionary "check.idx" fields "[SMW_code]" ascending
  	while true
    		repaint on
    		repaint
    		ptval=0
    		Titles()
    		ptval = navrecs()
    		if ptval = {u} or ptval = {U}
      		data update only-one
    		elseif ptval = {Esc}
      		Background()
      		vloadif(dpath|"sinvproc.vw")		'
      		order change index "sinvprc1.idx"
      		exit while
    		end if
  	end while
End Function ' AmendRecords()


FUNCTION Titles()
local y1 y2 y3 y4 y5 y6 y7
  repaint on
  repaint
  ptval=0
  y1 = format(" Amend Purchase Order Invoices ","M80")
  y2 = format(" {U}pdate - {Esc} ","M80")
  screen print 7 1 fgp bgp y1
  screen print 22 1 fgp bgp y2
END FUNCTION ' Titles()

