
	REMARK	#########################################################
	REMARK	#	A/R STATEMENTS PROGRAM		(A/R080)	#
	REMARK	#		VERS. OF 4.00 PM	3/6/79		#
	REMARK	#########################################################

	DIM L4(2),D$(2),D(20),M$(5),Y(2),G2$(5),G3(5),P(6)
%INCLUDE CURSOR
	GOTO 6000
%INCLUDE SUBS1
%INCLUDE GENINFO
%INCLUDE BINSEARC
%INCLUDE A/R-INFO
%INCLUDE READCUST
%INCLUDE A/R-INV
	DATA 0,3,3,6,8,11,13,16,19,21,24,26


4000	YEAR=100*(I/100-INT(I/100))					REMARK	COMPUTE THE NUMBER OF DAYS BETWEEN DATE "I" AND 00/00/00
	DAY=100*((I-YEAR)/10000-INT((I-YEAR)/10000))
	MONTH=(I-100*DAY-YEAR)/10000
	IF MONTH=0 OR MONTH>12 THEN A4=0:RETURN
	RESTORE
	FOR IX%=1 TO MONTH
	READ A4
	NEXT IX%
	A4=A4+YEAR*365+INT(YEAR/4)+1+(MONTH-1)*28+DAY
	IF INT(YEAR/4)=(YEAR/4) AND MONTH<3 THEN A4=A4-1
	RETURN 

4080	I=I2:GOSUB 4000							REMARK	COMPUTE THE NUMBER OF DAYS BETWEEN "I2" AND "J2"
	A=A4
	I=J2:GOSUB 4000
	A=A-A4
	RETURN 

4220	PRINT "** TOTAL DUE -->";TAB(62);				REMARK	PRINT CUSTOMER BALANCE
	PRINT USING MASKA$;B9
	PRINT CHR$(12)
	B9=0:LINE.COUNT%=60:PAGE.COUNT%=0				REMARK	ZERO BALANCE AND RESET LINE AND PAGE COUNTERS
	RETURN 


4500	XYZ$=W1$+"      "						REMARK	LOCATE AND RETRIEVE CUSTOMER DATA
	K$=LEFT$(XYZ$,6):GOSUB 1060					REMARK	LOCATE CUSTOMER DATA
	IF H=-1 OR VAR1=0 THEN \
		M$(2)="NO CUSTOMER INFO":\
		FOR I%=2 TO 5:\
		M$(I%)=" ":\
		NEXT I%:\
		Y(2)=0:Y(1)=0 \
	ELSE Y9=2:X0=L:GOSUB 3225					REMARK	RETRIEVE CUSTOMER DATA
	RETURN 


4620	IF B<>2 THEN RETURN						REMARK	REVERSE SIGNS ON CREDIT MEMOS
	FOR I%=1 TO 11
	IF D(I%)<>0 THEN D(I%)=-D(I%)
	NEXT I%
	RETURN 



									REMARK	START OF MAIN PROGRAM
6000	MASKA$=" #######.##"
	MASKB$="######"
	MASKC$="#####.#"
	OPEN "G/I0F010.DAT" AS 1, "A/R0F110.DAT" RECL 162 AS 2, \
	"A/R0F120.DAT" RECL 226 AS 3,"A/R0F130.DAT" AS 4
	FILE.NO=4:GOSUB 3.14						REMARK	RETRIEVE A/R EXTENT INFORMATION
	Y9=1:GOSUB 700							REMARK	RETRIEVE G/I FILE DATA
	RECORD.COUNT=AR.CUSTFILE.EXTENT
	Y2=2
6020	CONSOLE
	PRINT:PRINT CLEAR.SCREEN$;"A/R STATEMENTS"
	PRINT:PRINT:PRINT 
	PRINT "FIRST CUSTOMER"
	PRINT "LAST CUSTOMER"
6040	X1=271:X2=6:X3=0:X4=0:GOSUB 345					REMARK	ENTER FIRST CUSTOMER
	IF X0$<=" " THEN 6480
	X0$=X0$+"      "
	W8$=LEFT$(X0$,6)
	X1=335:X2=6:X3=0:X4=0:GOSUB 345					REMARK	ENTER LAST CUSTOMER
	X0$=X0$+"      "
	W0$=LEFT$(X0$,6)
	X2=1:X3=0:X4=1:X2$="ENTRY CORRECT?":GOSUB 665			REMARK	VERIFY ENTRY
	IF X0=0 THEN 6020
	X1=192:GOSUB 210
	PRINT "PROCESSING...";
	LPRINTER
	LINE.COUNT%=60
6140	INVOICE.POINTER% = INVOICE.POINTER% + 1
	IF AR.INVFILE.EXTENT=0 THEN 6480
	IF INVOICE.POINTER%>AR.INVFILE.EXTENT THEN GOSUB 4220:GOTO 6480	REMARK	CHECK FOR END OF FILE
	FILE.NO=3:REC.NO%=INVOICE.POINTER%: GOSUB 3400			REMARK	RETRIEVE NEXT INVOICE
	IF W1$>W0$ THEN GOSUB 4220:GOTO 6480				REMARK	END CUSTOMER HAS BEEN PASSED
	GOSUB 4620							REMARK	REVERSE SIGNS, IF A CREDIT MEMO
	IF D(7)+D(11)=0 THEN 6140					REMARK	SKIP UNBILLED ITEMS
	IF W6$=W1$ THEN 6240						REMARK	PRINT CUSTOMER TOTALS WHEN CUSTOMERS CHANGE
	IF PAGE.COUNT%<>0 THEN GOSUB 4220
	W6$=W1$
	GOSUB 4500							REMARK	RETRIEVE NEXT CUSTOMER DATA
6240	IF L4(1)=0 AND L4(2)=0 THEN 6140				REMARK	IF BILL DATE AND PROGRESS DUE DATE ARE ZERO, SKIP THIS INVOICE
	IF L4(1)=0 THEN D(1)=0:D(2)=0:D(3)=0:D(4)=0			REMARK	IF BILL DATE IS ZERO, PRINT INVOICE AMOUNTS AS ZERO
	IF L4(2)=0 THEN D(8)=0						REMARK	IF PROGRESS DUE DATE IS ZERO, PRINT PROGRESS BALANCE AS ZERO
	IF LINE.COUNT%>17 THEN \					REMARK	WHEN STATEMENT FORM FILLS UP...
		PAGE.COUNT%=PAGE.COUNT%+1:\				REMARK	ADVANCE TO NEXT FORM
		PRINT W1$;:\						REMARK	AND REPRINT CUSTOMER DATA
		FOR I%=2 TO 5:\
		PRINT TAB(11);M$(I%):\
		NEXT I%:\
		PRINT TAB(62);:\
		X0=G3(1):GOSUB 680.5:\
		PRINT "    PAGE";PAGE.COUNT%:\
		PRINT:PRINT:PRINT:PRINT:PRINT:\
		LINE.COUNT%=1
	PRINT " ";L1$;TAB(14);						REMARK	PRINT THIS INVOICE
	PRINT USING MASKB$;L1;
	PRINT TAB(21);

	IF L4(1)>0 THEN AGE.DATE=L4(1)\					REMARK	FOR AGING, USE THE BILL DATE IF IT'S NON-ZERO
	ELSE AGE.DATE=L4(2)						REMARK	OTHERWISE, USE THE PROGRESS DUE DATE
	X0=AGE.DATE:GOSUB 680.5
	PRINT USING MASKA$;D(4);D(7);D(11);D(7)+D(11);
	I2=G3(1):J2=AGE.DATE:GOSUB 4080					REMARK	COMPARE AGING DATE WITH TODAY'S DATE
6360	IF A<30 THEN I=79:X$="C" \					REMARK	LESS THAN 30 DAYS SINCE INVOICE DATE IS CURRENT
	ELSE I=81:X$="P"						REMARK	MORE THAN 30 DAYS IS PAST DUE
	PRINT TAB(I);X$
	LINE.COUNT%=LINE.COUNT%+1
	B9=B9+D(7)+D(11)						REMARK	ACCUMULATE INVOICE TOTAL TO CUSTOMER BALANCE
	GOTO 6140



6480	CONSOLE								REMARK	END PROGRAM AND RELOAD MENU
	PRINT CLEAR.SCREEN$;"A/R STATEMENTS LOADING MENU"
	CHAIN "A/P000"
