	REMARK	*********************************************\
		*  P/R130.BAS  PAYROLL DEDUCTION CALCULATE  *\
		*   5/17/79                       9:55 AM   *\
		*********************************************

%INCLUDE CURSOR

	DIM E$(2),G3(5),G2$(5),S(96),R$(5),R1(2),R2(5)

	GOTO 6000

825	Z1=59								REMARK  ****    LINE PRINTER ROUTINE    ****

	IF LINE.COUNT%<55  THEN RETURN					REMARK  IF SPACE REMAINS ON REPORT PAGE, RETURN
	P=P+1
	PRINT CHR$(0CH);
	PRINT TAB((Z1-LEN(G2$(1)))/2);G2$(1);TAB(Z1);"DATE ";		REMARK  PRINT COMPANY NAME AND REPORT DATE
	X0=G3(1):GOSUB 680.5
	PRINT
	PRINT TAB((Z1-LEN(X4$))/2);X4$;TAB(Z1);"PAGE ";P		REMARK  PRINT REPORT TITLE AND PAGE NUMBER
	PRINT
	PRINT
	PRINT "EMPLOYEE  TR  TC  FREQ  DESCRIPTION  ERROR DESCRIPTION"	REMARK  PRINT PAGE HEADINGS
	PRINT
	LINE.COUNT%=6							REMARK  RESET LINE COUNTER FOR NEW REPORT PAGE
	RETURN

%INCLUDE SUBS1
%INCLUDE MSTRIN
%INCLUDE MSTROUT
%INCLUDE GENINFO

4600	IF P=0 THEN LINE.COUNT%=60					REMARK  PRINT DEDUCTION ERROR ON PRINTER
	GOSUB 825							
	PRINT USING MASKA$;D1,D2,D3,D4,D1$,E$(A4)
	LINE.COUNT%=LINE.COUNT%+1
	RETURN


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

	MASKA$="  ######   #   #   ##   /##########/  /##################/"

	PRINT CLEAR.SCREEN$;"P/R DEDUCTION CALCULATE"			REMARK  DISPLAY PROGRAM I.D. ON SCREEN
	PRINT "ENTER START EMPLOYEE NUMBER OF ZERO TO EXIT"
	PRINT 
	PRINT 
	PRINT "START EMPLOYEE NUMBER"
	PRINT "END EMPLOYEE NUMBER"

	X1=279:X2=3:X3=0:X4=999:GOSUB 345				REMARK  ENTER START EMPLOYEE; IF ZERO, END PROGRAM
	IF X0=0 THEN 7000
	E1=X0

6005	X1=343:X2=3:X3=E1:X4=999:GOSUB 345				REMARK  ENTER END EMPLOYEE NUMBER
	E2=X0

	X2$="ENTRY CORRECT?":X2=1:X3=0:X4=1:GOSUB 665			REMARK  VERIFY ENTRY: '1'=O.K., '0'=RETRY
	IF X0 <> 1 THEN 6000

6100	Y3=3
	OPEN "P/R0F030.DAT" RECL 38 AS 3				REMARK  OPEN DEDUCTION/MISCELLANEOUS PAY FILE
	Y9=2
	OPEN "P/R0F110.DAT" RECL 1150 AS 1				REMARK OPEN EMPLOYEE MASTER FILE
	OPEN "G/I0F010.DAT" RECL 200 AS 2:GOSUB 700			REMARK OPEN AND READ GENERAL INFORMATION FILE
	IF E2>MSTR.RECORDS THEN E2=MSTR.RECORDS
	E$(1)="NO MASTER/RELEASED"
	E$(2)="INSUFFICIENT FUNDS"
	LPRINTER							REMARK  SELECT PRINTER AS OUTPUT DEVICE

6135	WHILE D1 <= E2							REMARK  PROCESS RECORDS WHILE IN EMPLOYEE RANGE
	INPUT.COUNT=INPUT.COUNT+1
	READ #Y3,INPUT.COUNT;D1,D2,D3,D4,D1$,D5,D6			REMARK  READ DEDUCTION/MISCELLANEOUS PAY RECORD

	IF D1 > E2 \							REMARK  IF ABOVE EMPLOYEE RANGE
	OR D1 < E1 \
	OR D4 > 9  \							REMARK  OR DEDUCTION RECORD WAS USED
	OR D2 = 1  \							REMARK  OR RECORD IS MISCELLANEOUS PAY,
	THEN GOTO 6230


	IF D4=5 AND G3(4) <> 1 THEN GOTO 6230				REMARK  REJECT DEDUCTIONS SLATED FOR OTHER PERIODS
	IF D4=6 AND G3(4) <> 2 THEN GOTO 6230

	IF D1 > MSTR.RECORDS THEN A4=1:GOSUB 4600:GOTO 6230
	X0=D1:GOSUB 745							REMARK  READ EMPLOYEE MASTER RECORD
	IF S(1)=0 OR R2(1)=99 THEN A4=1:GOSUB 4600:GOTO 6230		REMARK  IF EMPLOYEE IS INACTIVE OR DELETED, PRINT ERROR

6195	A2=D6
	IF D5 > 0 THEN A2=FNR(D5*(S(83))/100):GOTO 6215			REMARK  CALCULATE DEDUCTION AMOUNT BASED ON RATE
6205	IF S(83)-S(90) < A2 THEN A4=2:A2=S(83)-S(90):GOSUB 4600		REMARK  IF DEDUCTION EXCEEEDS NET CHECK FOR EMPLOYEE,\
									        THEN PRINT ERROR OR PRINTER
6215	IF D2 <> 2 THEN A1=D2 ELSE A1=0

6220	FOR I%=41 TO 89 STEP 24						REMARK  ACCUMULATE DEDUCTION AMOUNT TO EMPLOYEE RECORD
	S(I%-A1)=S(I%-A1)+A2
	S(I%+1)=S(I%+1)+A2
	NEXT I%

	D6=A2								REMARK  SET DEDUCTION AMOUNT; FLAG RECORD AS USED
	D4=D4+10

	PRINT #Y3,INPUT.COUNT;D1,D2,D3,D4,D1$,D5,D6			REMARK  RESAVE RECORD AS 'USED' ON DEDUCTION FILE

	X0=D1:GOSUB 750							REMARK  RESAVE EMPLOYEE MASTER RECORD
6230	WEND

7000	CONSOLE								REMARK  TERMINATE PROGRAM AND LOAD MENU
	PRINT CLEAR.SCREEN$;"P/R DEDUCTION CALCULATE LOADING MENU"
	CHAIN "P/R000"

