
	REMARK   #############################################
	REMARK   #     ACCOUNTS RECEIVABLE LEDGER PROGRAM    #
	REMARK   #    (A/R040)      VERS OF 3 PM   6/19/79   #
	REMARK   #############################################

	DIM A(7),B.(9),C(9),M$(5),Y(2),L4(2),G3(5),D(13),G2$(5)
	DATA "A/R OPEN ITEMS","A/R AGING ANALYSIS","A/R CLOSED ITEMS"
	DATA "A/R UNBILLED ITEMS",0,3,3,6,8,11,13,16,19,21,24,26
%INCLUDE CURSOR
	GOTO 6000
%INCLUDE SUBS1
%INCLUDE BINSEARC
%INCLUDE A/R-INFO
%INCLUDE READCUST
%INCLUDE GENINFO
%INCLUDE A/R-INV



825	IF LINE.COUNT%<55 AND PAGE.COUNT%>0 THEN RETURN			REMARK	LINE PRINTER ROUTINE
	PAGE.COUNT%=PAGE.COUNT%+1
	PRINT CHR$(12);
	PRINT TAB((A1-LEN(G2$(1)))/2);G2$(1);TAB(A1);"DATE ";
	X0=G3(1):GOSUB 680.5
	PRINT 
	PRINT TAB((A1-LEN(X4$))/2);X4$;TAB(A1);"PAGE";PAGE.COUNT%
	PRINT
	IF R3=2 AND S=2 THEN \
		PRINT " CUST #   CUSTOMER";TAB(35);"PHONE"; \
	ELSE \
		PRINT " INV # T CUST ORDER #  JOB # DESC  BILL DATE";

838	IF R3=2 THEN \
		PRINT TAB(46);"TOTAL BAL";TAB(59);"CURRENT";TAB(71);: \
		PRINT "30 DAY";TAB(82);"60 DAY";TAB(93);"90 DAY";TAB(102);: \
		PRINT "PROG CURR  PR 10-DAY PROG DUE" \
	ELSE \
		PRINT TAB(48);"INV AMT";TAB(62);"SHIP";TAB(72);"TAXES";: \
		PRINT TAB(83);"TOTAL";TAB(92);"INV PAY";TAB(102);"PROG BILL";:\
		PRINT "   PROG PAY PROG DUE"
	PRINT
	LINE.COUNT%=6
	RETURN 


4000	YEAR=100*((I/100)-INT(I/100))					REMARK	COMPUTE # 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 I%=1 TO MONTH + 4
	READ A4
	NEXT I%
	A4=A4+YEAR*365+INT(YEAR/4)+1+(MONTH-1)*28+DAY
	IF INT(YEAR/4)<>(YEAR/4) THEN RETURN	
	IF MONTH<=2 THEN A4=A4-1
	RETURN 

4080	I=I2:GOSUB 4000							REMARK	COMPUTE THE NUMBER OF DAYS BETWEEN DATES I2 & J2
	A.=A4
	I=J2:GOSUB 4000
	A.=A.-A4
	RETURN 

									REMARK	PRINT CUSTOMER TOTALS, AND ADD THEM TO GRAND TOTALS
4220	IF B.(8)=0 THEN RETURN						REMARK	BUT NOT IF CUSTOMER BALANCE IS ZERO
	IF R3<>2 THEN \
		PRINT "   TOTAL";: \
		PRINT USING MASKC$;B.(8),B.(9);
	PRINT TAB(44);
	PRINT USING MASKA$;B.(1),B.(2),B.(3),B.(4),B.(5);
	PRINT " ";
	PRINT USING MASKA$;B.(6),B.(7)
	FOR I5%=1 TO 9
	C(I5%)=C(I5%)+B.(I5%)
	B.(I5%)=0
	NEXT I5%
	X0$="----"
	FOR I%=1 TO 5:X0$=X0$+X0$:NEXT I%
	PRINT X0$
	LINE.COUNT%=LINE.COUNT%+2
	RETURN 

4500	Y2=2								REMARK	LOCATE, RETRIEVE, AND PRINT CUSTOMER DATA
	RECORD.COUNT =  AR.CUSTFILE.EXTENT
	XYZ$=W1$+"      "
	K$=LEFT$(XYZ$,6)
	GOSUB 1060							REMARK	LOCATE CUSTOMER DATA
	IF H=-1 OR VAR1=0 THEN \
		M$(2)="NO CUSTOMER INFO": \
		Y(1)=0:Y(2)=0 \
	ELSE \
		Y9=2:X0=L:GOSUB 3225					REMARK	RETRIEVE CUSTOMER DATA
	PRINT "CUST ";W1$;"   ";M$(2);
	IF R3=2 THEN \
		PRINT TAB(43);: \
		X0=P9:GOSUB 760.5: \
		PRINT TAB(58);: \
		PRINT USING MASKB$;Y(2),Y(1): \
		LINE.COUNT%=LINE.COUNT%+1:RETURN 
	IF R3<2 THEN PRINT USING MASKB$;Y(2),Y(1);
	PRINT 
	LINE.COUNT%=LINE.COUNT%+1
	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$="    SALES YTD #######.##  LAST YEAR #######.##"
	MASKC$="   BAL #######.##   #### INVOICES"
	MASKD$="######"
	MASKE$="#####.#"
	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, \
	"CRT" RECL 1100 AS 19
	Y9=1:GOSUB 700							REMARK	RETRIEVE G/I FILE DATA
	FILE.NO=4:GOSUB 3.14						REMARK	RETRIEVE A/R FILE EXTENTS
	IF END #3 THEN 6475						REMARK	IF NO INVOICES ON FILE, END PROGRAM
6020	X0=16:GOSUB 260							REMARK	DISPLAY CRT MASK
	CONSOLE
	R=0:S=0:PAGE.COUNT%=0
	FOR I%=1 TO 9:C(I%)=0:NEXT I%					REMARK	ZERO TOTALS
	X1=270:X2=1:X3=0:X4=4:GOSUB 345					REMARK	ENTER REPORT FORMAT
	IF X0=0 THEN 6480
	R3=X0
	S=1
	IF R3>2 THEN 6080
	X1=334:X2=1:X3=1:X4=3:GOSUB 345					REMARK	ENTER REPORT TYPE
	S=X0
	IF S=3 THEN \							REMARK	CUSTOMER RANGE REPORT TYPE
		X1=538:X2=6:X3=0:X4=0:GOSUB 345:\			REMARK	ENTER FIRST CUSTOMER
		X0$=X0$+"      ":\
		W8$=LEFT$(X0$,6):\
		X1=602:X2=6:X3=0:X4=0:GOSUB 345:\			REMARK	ENTER LAST CUSTOMER
		X0$=X0$+"      ":\
		W0$=LEFT$(X0$,6)
6080	IF R3=3 THEN \							REMARK	CLOSED ITEM LISTING
		X1=418:X2=1:X3=0:X4=1:GOSUB 345: \			REMARK	ENTER WHETHER TO DELETE CLOSED ITEMS
		R=X0
	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...";
	RESTORE
	FOR I%=1 TO R3
	READ X4$
	NEXT I%
	LPRINTER
	LINE.COUNT%=60
	IF S=3 THEN \						  	REMARK	FOR REPORT TYPE CUSTOMER RANGE, LOCATE FIRST INVOICE
		Y2=3: \
		RECORD.COUNT=AR.INVFILE.EXTENT: \
		XYZ$=W8$+"      ":\
		K$=LEFT$(XYZ$,6)+"000000":\
		GOSUB 1060: \
		START.RECORD.NO=L \
	ELSE \
		START.RECORD.NO=1

	IF START.RECORD.NO > AR.INVFILE.EXTENT THEN \
		X2$="FIRST CUSTOMER NUMBER TOO HIGH": \
		GOSUB 615: \
		GOTO 6020

	FOR RECORD.INDEX=START.RECORD.NO TO AR.INVFILE.EXTENT		REMARK	START PRINT LOOP
	FILE.NO=3:REC.NO%=RECORD.INDEX:GOSUB 3400			REMARK	READ NEXT INVOICE OFF OF FILE
	IF S=3 AND W1$>W0$ THEN 6430					REMARK	FOR CUSTOMER RANGE, BRANCH IF PAST LAST CUSTOMER
	GOSUB 4620							REMARK	REVERSE SIGNS, IF CREDIT MEMO
	IF R3=3 THEN 6380						REMARK	BRANCH FOR CLOSED ITEMS LISTINGS
	IF R3=4 THEN 6400						REMARK	BRANCH FOR UNBILLED REPORT

									REMARK	OPEN ITEMS AND AGING ANALYSIS ROUTINES
	IF D(7)+D(11)=0 THEN 6430					REMARK	SKIP CLOSED ITEMS
	IF PAGE.COUNT%=0 THEN W6$=W1$
	IF W6$<>W1$ THEN GOSUB 4220:GOSUB 4500:W6$=W1$			REMARK	WHEN CUSTOMERS CHANGE, PRINT LAST CUSTOMER TOTALS,\
										AND NEW CUSTOMER DATA
	IF L4(1)=0 THEN D(1)=0:D(2)=0:D(3)=0:D(4)=0			REMARK	IF BILL DATE IS ZERO, FORCE INVOICE AMOUNT TO ZERO
	IF L4(2)<>0 THEN 6300
	D(8)=0								REMARK	IF PROGRESS DUE DATE IS ZERO,\
										FORCE PROGRESS BILLING AMT TO ZERO
	IF L4(1)=0 THEN 6430						REMARK	IF BOTH ARE ZERO, SKIP THIS INVOICE
	GOTO 6300
6280	IF W6$=W1$ THEN 6300						REMARK	CLOSED ITEM AND UNBILLED REPORT FORMATS
	W6$=W1$
	IF PAGE.COUNT%<>0 THEN GOSUB 4500				REMARK	PRINT NEW CUSTOMER DATA WHEN CUSTOMERS CHANGE
6300	IF R3=2 THEN 6320						REMARK	FOR ALL FORMATS EXCEPT AGING ANALYSIS...
	A(1)=D(1)							REMARK	ASSIGN VALUES TO PRINT, AND ACCUMULATE THEM TO TOTALS
	A(2)=D(2)
	A(3)=D(3)
	A(4)=D(4)
	A(5)=D(6)
	A(6)=D(8)
	A(7)=D(10)
	FOR I%=1 TO 7
	B.(I%)=B.(I%)+A(I%)
	NEXT I%
	GOTO 6330
6320	A(2)=0:A(3)=0:A(4)=0:A(5)=0:A(6)=0:A(7)=0			REMARK	ASSIGN VALUES TO PRINT FOR AGING ANALYSIS
	A(1)=D(7)+D(11)
	B.(1)=B.(1)+A(1)
	IF D(7)=0 THEN 6326						REMARK	UNLESS INVOICE BALANCE IS ZERO, AGE INVOICE
	I2=G3(1):J2=L4(1):GOSUB 4080
	IF A.<1 THEN A.=1
6322	I=INT(A./30)+2
	IF I>5 THEN I=5
	A(I)=D(7)
	B.(I)=B.(I)+D(7)
6326	IF D(11)=0 THEN 6330						REMARK	UNLESS PROGRESS BALANCE IS ZERO, AGE IT
	I2=G3(1):J2=L4(2):GOSUB 4080
	IF A.<10 THEN I=6 \
	ELSE I=7
	A(I)=D(11)
	B.(I)=B.(I)+D(11)
6330	B.(8)=B.(8)+D(7)+D(11)
	B.(9)=B.(9)+1

	A1=115:GOSUB 825						REMARK	START PRINT ROUTINE
	IF LINE.COUNT% < 7 THEN GOSUB 4500				REMARK	PRINT CURRENT CUSTOMER AT THE TOP OF A NEW PAGE
	IF S=2 THEN 6430						REMARK	EXCEPT FOR SUMMARY ONLY REPORT, PRINT INVOICE DETAILS
	PRINT USING MASKD$;L1;
	PRINT B;L1$;
	PRINT TAB(22);
	PRINT USING MASKD$;L2;
	PRINT " ";L2$;
	IF L4(1)<>0 THEN PRINT TAB(36);:X0=L4(1):GOSUB 680.5
	PRINT TAB(44);
	PRINT USING MASKA$;A(1),A(2),A(3),A(4),A(5);
	IF B=2 OR D(12)<>0 THEN PRINT "C";
	PRINT TAB(100);
	PRINT USING MASKA$;A(6),A(7);
	IF L4(2)<>0 THEN PRINT TAB(123);:X0=L4(2):GOSUB 680.5
	PRINT 
	LINE.COUNT%=LINE.COUNT%+1
	IF D(13)<>0 THEN \
		PRINT TAB(10);"G/L #";: \
		PRINT USING MASKE$;D(13): \
		LINE.COUNT%=LINE.COUNT%+1
	IF R=1 THEN GOTO 6420\						REMARK	IF DELETE OPTION SELECTED, BRANCH
	ELSE GOTO 6430


									REMARK	CLOSED ITEM LISTING CHOSEN
6380	IF C2=5 THEN 6280						REMARK	UNLESS DELETE FLAGGED...
	IF L4(1)=0 THEN 6430						REMARK	SKIP UNBILLED ITEMS
	IF D(7)+D(11)=0 THEN GOTO 6280 \				REMARK	AND OPEN ITEMS
	ELSE GOTO 6430


									REMARK	UNBILLED ITEM LISTING CHOSEN
6400	IF L4(1)=0 THEN 6280						REMARK	SKIP INVOICES WITH NON-ZERO BILL DATES
	IF L4(2)=0 THEN 6430
	IF D(8)=0 THEN 6280						REMARK	UNLESS THEY HAVE A POSTIVE PROGRESS BALANCE DUE
	GOTO 6430


									REMARK	DELETE CLOSED ITEMS
6420	B=-1
	FILE.NO=3:REC.NO%=RECORD.INDEX:GOSUB 3450

6430	NEXT RECORD.INDEX						REMARK	END OF MAIN PRINT LOOP

	IF R3>2 THEN \							REMARK	ZERO TOTALS ON CLOSED ITEM AND UNBILLED FORMATS
		FOR I%=1 TO 9: \
		B.(I%)=0: \
		NEXT I%: \
		GOTO 6020						REMARK	AND DO NOT PRINT GRAND TOTALS

	GOSUB 4220							REMARK	PRINT LAST CUSTOMER TOTALS ON\
										OPEN ITEM AND AGING ANALYSIS FORMATS
	FOR I%=1TO 9
	B.(I%)=C(I%)
	NEXT I%
	PRINT "   GRAND"
	IF R3=2 THEN PRINT "   TOTAL";
	GOSUB 4220							REMARK	PRINT GRAND TOTALS
	GOTO 6020

6475	X2$="ZERO INVOICES ON FILE":GOSUB 615
6480	PRINT CLEAR.SCREEN$;"A/R LEDGER LOADING MENU"			REMARK	END PROGRAM AND RELOAD MENU
	CHAIN"A/P000"

