
	REMARK	####################################################
	REMARK	#         ACCOUNTS PAYABLE LEDGER PROGRAM          #
	REMARK	#    (A/P070)     VERS OF 10.00 AM    6/20/79      #
	REMARK	####################################################

%INCLUDE CURSOR
	A4$="----"
	FOR I%=1 TO 4:A4$=A4$+A4$:NEXT I%
	DEF FNA(Z)=100*((Z/100)-INT(Z/100))				REMARK	ZERO OUT TENS AND ONES DIGITS
	MASKA$=" ######"
	MASKB$="#####.#"
	MASKC$="  #######.##"
	MASKD$=" #######.##"
	MASKE$="###"
	DIM W(4),W1.(4),A1(5),W2.(4),A2(6),M$(5),Y(2),C(27),D(27),G3(5),\
	G2$(5),P(5)
	GOTO 6000
	DATA 0,3,3,6,8,1,13,16,19,21,24,26
%INCLUDE SUBS1
%INCLUDE BINSEARC
%INCLUDE GENINFO
%INCLUDE READVEND
%INCLUDE READINV
%INCLUDE WRITEINV
%INCLUDE A/P-INFO


825	IF LINE.COUNT%<55 THEN RETURN					REMARK	LINE PRINTER ROUTINE
	PAGE.COUNT%=PAGE.COUNT%+1
	PRINT CHR$(12);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 TOTAL.FLAG%<>2 THEN \
		PRINT "  VENDOR  INV #  DESCR.   BUY INV DATE PAY DATE";: \
		PRINT"  CK REG  (G/L #)";
	PRINT TAB(69);"AMOUNT   DISCOUNT";TAB(92);"OTHER    NET DUE ";
	GOSUB 5660							REMARK	PRINT AGING HEADINGS
	PRINT
	LINE.COUNT%=6
	RETURN


5020	PRINT A6$;TAB(8);L5$;TAB(21);					REMARK	PRINT ONE TOTAL LINE
	PRINT USING MASKA$;I3
	RETURN 


5040	YEAR = FNA(I)							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
	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 


5140	X4$=L4$:A1=115:GOSUB 825					REMARK	PRINT ONE DETAIL LINE
	IF W9>1 AND LINE.COUNT%<7 THEN \
		PRINT M$(2);" - CONTINUED": \
		LINE.COUNT%=LINE.COUNT%+1
	PRINT TAB(3);W1$;TAB(9);
	PRINT USING MASKA$;W0;
	PRINT TAB(17);W2$;TAB(27);W3$;TAB(31);
	X0=D(23):GOSUB 680.5
	PRINT " ";
	X0=D(24):GOSUB 680.5
	D1=C(2)+C(3)+C(4)+C(5)+C(6)+C(7)+C(8)+C(9)+C(10)+C(11)
	PRINT USING MASKA$;D(25);
	IF D1=0 THEN PRINT "  ";:PRINT USING MASKB$;D(1);
	PRINT TAB(64);
	PRINT USING MASKD$;C(23);C(24);C(25);C0;
	LINE.COUNT%=LINE.COUNT%+1
	IF C3<>0 THEN PRINT TAB(C3);"X";				REMARK	AGING
	PRINT TAB(126);
	IF W1%=1 THEN X0$="INV"
	IF W1%=4 THEN X0$="CR"
	IF W1%=5 THEN X0$="DB"
	PRINT X0$
	RETURN 


5400	X4$=L4$:A1=115:GOSUB 825					REMARK	LOCATE, RETRIEVE AND PRINT VENDOR DATA
	Y2=2
	RECORD.COUNT = AP.VENDFILE.EXTENT
	XYZ$=W1$+"      "
	K$=LEFT$(XYZ$,6)
	GOSUB 1060
	IF H=-1 OR VAR1=0 THEN \
		M$(2)="NO VENDOR INFORMATION": \
		Y(1)=0:Y(2)=0 \
	ELSE \
		Y9=2:X0=L:GOSUB 3200

	PRINT M$(2);TAB(40);"(YEAR TO DATE";
	PRINT USING MASKC$;Y(2);
	PRINT ")  (LAST YEAR";
	PRINT USING MASKC$;Y(1);
	PRINT ")"
	LINE.COUNT%=LINE.COUNT%+1
	RETURN 


5460	IF W9=0 THEN RETURN						REMARK	PRINT AND ZERO OVERALL REPORT TOTALS
	IF W9>1 OR S=1 THEN \
		PRINT "   TOTAL";TAB(25);: \
		PRINT USING MASKE$;W9;: \
		PRINT " INVOICES";: \
		PRINT TAB(64);: \
		PRINT USING MASKD$;W(1);W(2);W(3);W(4): \
		PRINT: \
		LINE.COUNT%=LINE.COUNT%+2
	W9=0:W(1)=0:W(2)=0:W(3)=0:W(4)=0
	RETURN 


5540	IF D1=0 THEN RETURN						REMARK	PRINT MULTIPLE GENERAL LEDGER NUMBERS
	PRINT TAB(7);"G/L";
	FOR I1%=1 TO 11
	IF C(I1%)<>0 THEN PRINT "    ";:PRINT USING MASKB$;D(I1%);
	NEXT I1%
	PRINT 
	PRINT TAB(7);"AMT";
	FOR I1%=1 TO 11
	IF C(I1%)<>0 THEN PRINT USING MASKD$;C(I1%);
	NEXT I1%
	PRINT 
	LINE.COUNT%=LINE.COUNT%+2
	RETURN 



5620	IF A9=0 THEN RETURN						REMARK	PRINT AND ZERO ACCOUNT TOTALS
	PRINT "--ACCOUNT TOTALS---";LEFT$(A4$,44);
	PRINT USING MASKD$;W2.(1);W2.(2);W2.(3);W2.(4);
	PRINT LEFT$(A4$,23)
	PRINT
	A9=0:W2.(1)=0:W2.(2)=0:W2.(3)=0:W2.(4)=0
	LINE.COUNT%=LINE.COUNT%+2
	RETURN 


5660	PRINT USING MASKE$;P(1);P(2);P(3);P(4);				REMARK	PRINT COLUMN HEADINGS FOR AGING
	PRINT"  >"
	RETURN 



6000	OPEN "G/I0F010.DAT" AS 1, "A/P0F110.DAT" RECL 162 AS 2, \	REMARK	MAIN PROGRAM STARTS HERE
	"A/P0F120.DAT" RECL 580 AS 3, "A/P0F130.DAT" AS 4, \
	"CRT" RECL 1100 AS 19
	Y9=1:GOSUB 700							REMARK	RETREIVE G/I FILE DATA
	I=G3(1):GOSUB 5040						REMARK	COMPUTE # OF DAYS BETWEEN TODAY & 00/00/00
	D3=A4
	X0=4:GOSUB 3310							REMARK	RETREIVE A/P GENERAL INFORMATION
6040	FOR I%=1 TO 4							REMARK	CLEAR TOTAL AND INVOICE FILE VARIABLES
	A1(I%)=0:A2(I%)=0:W(I%)=0:W1.(I%)=0:W2.(I%)=0
	NEXT I%
	DELETE.COUNT%=0:INVOICE.RECORD.NO=0:TOTAL.FLAG%=0
	A1(5)=0:A2(5)=0:A2(6)=0
	L5$=" INVOICES"
	L4$="A/P LEDGER OPEN ITEM LISTING"
	CONSOLE
	X0=7:GOSUB 260
	W8=0:W9=0:R1=0:R=0:S=0:PAGE.COUNT%=0:OPEN.COUNT%=0:CLOSED.COUNT%=0
	LINE.COUNT%=62
	X1=270:X2=1:X3=0:X4=2:GOSUB 345					REMARK	ENTER REPORT FORMAT
	ON X0+1 GOTO 6060,6120,6080


6060	CONSOLE								REMARK	END PROGRAM ROUTINE
	PRINT CLEAR.SCREEN$;"A/P LEDGER LOADING MENU"
	CHAIN "A/P000"


6080	R=1								REMARK	CLOSED ITEM LISTING CHOSEN
	L4$="A/P LEDGER CLOSED ITEM LISTING"
	X1=355:X2=1:X3=0:X4=1:GOSUB 345					REMARK	ENTER WHETHER TO DELETE	CLOSED ITEMS
	R1=X0
6120	X1=398:X2=1:X3=1:X4=3:GOSUB 345					REMARK	ENTER REPORT TYPE
	ON X0 GOTO 6180,6160,6140

6140	S=3								REMARK	ONE-VENDOR-ONLY TYPE CHOSEN
	X1=410:X2=6:X3=0:X4=0:GOSUB 345					REMARK	ENTER VENDOR NUMBER
	XYZ$=X0$+"      "
	W7$=LEFT$(XYZ$,6)
	GOTO 6180
6160	S=1
6180	X1=534:GOSUB 673						REMARK	ENTER START DATE
	I=X0:GOSUB 5040							REMARK	FIND # OF DAYS BETWEEN START DATE AND 00/00/00
	B0=X0
	B=A4
	X1=598:GOSUB 673						REMARK	ENTER END DATE
	I=X0:GOSUB 5040							REMARK	FIND # OF DAYS BETWEEN END DATE AND 00/00/00
	E0=X0
	E=A4
	X2=1:X3=0:X4=1:X2$="ENTRY CORRECT?":GOSUB 665
	IF X0=0 THEN 6040
	LPRINTER
	IF S=3 THEN \							REMARK	IF TYPE IS ONE-VENDOR-ONLY FIND THAT VENDOR
		Y2=3: \
		RECORD.COUNT=AP.INVOICE.EXTENT: \
		K$=W7$+"000000":\
		GOSUB 1060: \
		INVOICE.RECORD.NO=L-1 \
	ELSE\
		INVOICE.RECORD.NO=0

	IF INVOICE.RECORD.NO<0 OR INVOICE.RECORD.NO>AP.INVOICE.EXTENT-1 THEN\
		X2$="VENDOR NUMBER OUT OF RANGE": \
		GOSUB 615: \
		GOTO 6040
6260	INVOICE.RECORD.NO = INVOICE.RECORD.NO + 1
	IF INVOICE.RECORD.NO > AP.INVOICE.EXTENT THEN 6680
	FILE.NO=3:X0%=INVOICE.RECORD.NO:GOSUB 3000			REMARK	GET INVOICE RECORD
	IF S=3 AND W1$<>W7$ THEN 6680					REMARK	IF TYPE IS ONE-VENDOR, BRANCH WHEN PAST THAT VENDOR
	IF W2%=2 THEN DELETE.COUNT% = DELETE.COUNT% + 1: GOTO 6300
	IF D(25)<>0 THEN CLOSED.COUNT%=CLOSED.COUNT%+1:GOTO 6300
	IF W1%<>4 THEN OPEN.COUNT%=OPEN.COUNT%+1:GOTO 6300
	IF C(23)+C(24)=0 THEN CLOSED.COUNT%=CLOSED.COUNT%+1\
	ELSE OPEN.COUNT%=OPEN.COUNT%+1
6300	I=D(24):GOSUB 5040
	IF A4<B OR A4>E THEN 6260					REMARK	CHECK INVOICE DATE AGAINST START & END DATES
	IF W2%>9 THEN W2%=W2%-10					REMARK	STRIP OFF TENS DIGIT, IF ANY, FROM OPERATION CODE
	IF R=1 THEN 6400						REMARK	IF CLOSED ITEM LISTING, BRANCH

									REMARK	OPEN ITEM LISTING ROUTINES
	IF W2%=2 THEN \	 						REMARK	SKIP DELETE-FLAGGED INVOICES ON OPEN ITEM LISTING
		GOTO 6260
	IF W6$=W1$ THEN 6480
	IF PAGE.COUNT%=0 THEN 6380
	GOSUB 5460
	IF LEFT$(W1$,2)<>LEFT$(W6$,2) THEN GOSUB 5620
6380	W6$=W1$								REMARK	SET CURRENT VENDOR
	S3=1
	GOTO 6480

									REMARK	CLOSED ITEM LISTING ROUTINES
6400	IF W2%=2 THEN \							REMARK	ZERO INVOICE AMOUNTS ON DELETE-FLAGGED INVOICES
		C(23)=0:C(24)=0:C(25)=0:C(26)=0:GOTO 6540
	IF D(25)=0 THEN 6260						REMARK	SKIP OPEN ITEMS
	IF W1%<>4 THEN 6540						REMARK	IF NOT A CREDIT MEMO, BRANCH
	C1=C(25)
	C2=D(25)
	IF C(23)+C(24)<=0 THEN W2%=2:GOTO 6460
	IF C(25)=0 THEN 6260
	D(25)=0:C(25)=0:W2%=0
	GOSUB 3050							REMARK	RESAVE CREDIT MEMO 
6460	C(23)=-C1
	D(25)=C2
	GOTO 6500
									REMARK	RESUME OPEN ITEM LISTING ROUTINES
6480	IF W1%<>4 THEN 6520						REMARK	IF NOT A CREDIT MEMO, BRANCH
	IF C(23)+C(24)=0 THEN 6260					REMARK	SKIP TOTALLY USED CREDIT MEMOS
	C(23)=-C(23)-C(24)
	D(25)=0
6500	C(24)=0:C(25)=0:C(26)=0
	GOTO 6540
6520	IF D(25)<>0 THEN 6260						REMARK	SKIP CLOSED ITEMS
6540	C(25)=C(25)+C(26)						REMARK	ACCUMULATE TOTALS
	FOR I%=1 TO 3
	W(I%)=W(I%)+C(22+I%)
	W1.(I%)=W1.(I%)+C(22+I%)
	W2.(I%)=W2.(I%)+C(22+I%)
	NEXT I%
	W8=W8+1
	IF S<>3 THEN A9=1
	IF R=0 THEN W9=W9+1
	C0=C(23)+C(24)+C(25)
	W(4)=W(4)+C0
	W1.(4)=W1.(4)+C0
	W2.(4)=W2.(4)+C0
	C3=0
	IF R=1 THEN 6640						REMARK	IF CLOSED ITEM LISTING, SKIP AGING

	A=D3-A4								REMARK	AGE OPEN ITEMS
	I%=1
6580	IF A < P(I%) THEN 6600
	I%=I%+1
	IF I% < 5 THEN 6580
6600	A1(I%) = A1(I%)+C0
	C3 = I%*3 + 108
	IF W1%<>4 THEN A2(I%)=A2(I%)+C(24)
	IF S3=1 THEN GOSUB 5400:S3=0
6640	IF S=1 THEN 6260						REMARK	IF REPORT TYPE IS SUMMARY, GET NEXT INVOICE
	GOSUB 5140
	GOSUB 5540
	IF R1=0 THEN 6260						REMARK	IF NOT DELETING CLOSED ITEMS, GET NEXT INVOICE
	IF W2%=2 OR W1%<>4 THEN\
		W1%=-1:\
		FILE.NO=3:X0%=INVOICE.RECORD.NO:GOSUB 3050
	GOTO 6260


6680	IF R=0 THEN GOSUB 5460:GOSUB 5620				REMARK	-   * * *  TOTALS SECTION  * * *   -
	TOTAL.FLAG%=2
	LINE.COUNT%=66
	X4$=L4$:A1=115:GOSUB 825
	PRINT:PRINT TAB(30);"TOTALS";
	PRINT TAB(45);
	PRINT USING MASKA$;W8;
	PRINT " INVOICES";TAB(64);
	FOR I%=1 TO 4
	PRINT USING MASKD$;W1.(I%);
	NEXT I%
	PRINT:PRINT:PRINT:PRINT
	IF R=1 THEN 6780						REMARK	SKIP AGING SUMMARY FOR CLOSED ITEMS

	PRINT TAB(44);"AGING";TAB(71);"AMOUNT    DISCOUNT"		REMARK	AGING SUMMARY
	PRINT
	FOR I%=1 TO 5
	PRINT TAB(40);
	IF I<5 THEN \
		PRINT "UNDER";: \
		PRINT USING MASKE$;P(I%); \
	ELSE \
		PRINT "OVER ";: \
		PRINT USING MASKE$;P(I%-1);
	PRINT " DAYS";
	PRINT TAB(65);
	PRINT USING MASKC$;A1(I%);A2(I%)
	PRINT
	NEXT I%
	PRINT:PRINT:PRINT TAB(53);"TOTAL";
	PRINT TAB(65);
	FOR I%=2 TO 5
	A1(1)=A1(1)+A1(I%)
	A2(1)=A2(1)+A2(I%)
	NEXT I%
	PRINT USING MASKC$;A1(1);A2(1)
6780	PRINT:PRINT
	PRINT "THIS REPORT INCLUDES INVOICES";
	IF S=3 THEN PRINT" FOR VENDOR # ";W7$;
	PRINT" FROM ";
	X0=B0:GOSUB 680.5
	PRINT " TO ";
	X0=E0:GOSUB 680.5
	PRINT:PRINT
	A6$="OPEN":I3=OPEN.COUNT%:GOSUB 5020
	A6$="CLOSED":I3=CLOSED.COUNT%:GOSUB 5020
	A6$="DELETED":I3=DELETE.COUNT%:GOSUB 5020
	IF S=3 THEN I3=OPEN.COUNT%+CLOSED.COUNT%+DELETE.COUNT%\
	ELSE I3=AP.INVOICE.EXTENT
	A6$="TOTAL":GOSUB 5020
	GOTO 6040
