	REMARK	*******************************************\
		*   P/R190.BAS   PAYROLL HISTORY UPDATE   *\
		*    4/6/79                     6:25 PM   *\
		*******************************************

%INCLUDE CURSOR

	DIM S(96),R$(5),R1(2),R2(5),H1(3),H2(9),I1(3),I2(9)
	DIM G2$(5),G3(5)

	DEF FNR(Z1)=INT(Z1*100+.5)/100					REMARK  ROUNDING FUNCTION

	DEF FNEXACT(X0,X1)=X0*1000000+X1				REMARK  FUNCTION FOR KEY COMPARISON

	WRITTEN=999999							REMARK  SET 'RECORD WRITTEN' FLAG

	GOTO 6000

%INCLUDE GENINFO
%INCLUDE MSTRIN

1900	PRINT #Y4;H1(1),H1(2),H1(3),H2(1),H2(2),H2(3),H2(4),\		REMARK  WRITE HISTORY RECORD ON WORKFILE
	H2(5),H2(6),H2(7),H2(8),H2(9)
	OUTPUT.COUNT%=OUTPUT.COUNT%+1
	RETURN


2000	IF END #Y2 THEN 2010
	READ #Y2;H1(1),H1(2),H1(3),H2(1),H2(2),H2(3),H2(4),\		REMARK  READ PAYROLL HISTORY RECORD
	H2(5),H2(6),H2(7),H2(8),H2(9)
	RETURN

2010	H1(1)=WRITTEN
	RETURN

5000	IF J1% > MSTR.RECORDS THEN I1(1)=WRITTEN:RETURN			REMARK  READ SEQUENTIALLY FROM EMPLOYEE MASTER FILE
	X0=J1%
	GOSUB 745							REMARK  GET EMPLOYEE RECORD
	J1%=J1%+1
	IF S(5)=0 OR S(1)=0 OR R2(1)=99 THEN GOTO 5000			REMARK  IF NO CHECK WAS WRITTEN FOR THIS EMPLOYEE, SKIP IT

	IF S(4)=0 THEN S(4)=G3(1)
	I1(1)=S(1)

	I1(2)=INT(S(4)/100)						REMARK  CONVERT LAST CHECK DATE TO YYMMDD FORMAT
	I1(2)=(S(4)-I1(2)*100)*10000+I1(2)

	I1(3)=S(5)							REMARK  SET REMAINING PAYROLL HISTORY FIELDS
	I2(1)=S(73)+S(77)
	I2(2)=S(75)
	I2(3)=S(80)
	I2(4)=S(83)
	FOR I%=5 TO 8
	I2(I%)=S(80+I%)
	NEXT I%
	I2(9)=S(90)
	RETURN


6000	PRINT CLEAR.SCREEN$;"PAYROLL HISTORY UPDATE"			REMARK  DISPLAY PROGRAM I.D.
	PRINT "KEY RETURN TO BEGIN; CTRL-C TO EXIT"
6030	IF CONSTAT%=0 THEN GOTO 6030					REMARK  WAIT FOR KEYBOARD DEPRESSION
	A%=CONCHAR%
	IF A%= 03H THEN GOTO 9010					REMARK  IF CTRL-C WAS HIT, EXIT FFROM PROGRAM
	IF A% <> 0DH THEN GOTO 6030
	Y9=3
	Y2=2
	Y4=4
	OPEN "P/R0F110.DAT" RECL 1150 AS 1
	OPEN "P/R0F120.DAT" RECL 102 AS 2
	OPEN "G/I0F010.DAT" RECL 200 AS Y9
	CREATE "WORKFILE.DAT" RECL 102 AS 4 BUFF 40 RECS 128
	GOSUB 700							REMARK  LOAD SYSTEM GENERAL INFORMATION
	J1%=1
	GOSUB 5000							REMARK  GET FIRST EMPLOYEE RECORD FOR UPDATE
	GOSUB 2000							REMARK  GET FIRST PAYROLL HISTORY RECORD


6035	IF H1(1)=WRITTEN AND I1(1)=WRITTEN THEN GOTO 9000		REMARK  END PROGRAM IF EOF ON BOTH FILES

	IF I1(1) = WRITTEN THEN GOTO 6050				REMARK  WRITE REMAINING HISTORY RECORDS IF EOF MASTER

	IF FNEXACT(H1(1),H1(2)) >= FNEXACT(I1(1),I1(2)) THEN\    	REMARK  WRITE THE NEW HISTORY RECORD IF IT IS LOWER
	OUTPUT.COUNT%=OUTPUT.COUNT%+1:\
	PRINT #Y4;I1(1),I1(2),I1(3),I2(1),I2(2),I2(3),I2(4),\
	I2(5),I2(6),I2(7),I2(8),I2(9):I1(1)=WRITTEN:GOSUB 5000

	IF H1(1)=WRITTEN THEN GOTO 6035

6050	IF FNEXACT(I1(1),I1(2)) >= FNEXACT(H1(1),H1(2)) THEN\		REMARK  WRITE PAYROLL HISTORY RECORD IF IT IS LOWER
	GOSUB 1900:H1(1)=WRITTEN:GOSUB 2000
	GOTO 6035

9000	DELETE 2							REMARK  REPLACE HISTORY FILE WITH WORKFILE
	CLOSE 4
	A%=RENAME("P/R0F120.DAT","WORKFILE.DAT")
	HISTORY.RECORDS=OUTPUT.COUNT%
	GOSUB 720							REMARK  WRITE OUT NEW FILE LENGTH

9010	PRINT CLEAR.SCREEN$;"P/R HISTORY UPDATE LOADING MENU"		REMARK  DISPLAY EXIT MESSAGE
	CHAIN "P/R000"
