
	REMARK	#########################################################
	REMARK	#	ACCOUNTS RECEIVABLE UPDATE	(A/R03B)	#
	REMARK	#	    VERS. OF 1.15 PM	6/28/79			#
	REMARK	#########################################################

%INCLUDE CURSOR
	DIM G(6),F(10,2),S(6,8),C.(7),D(13),G2$(5),G3(5),L4(2)
	DIM M$(5),Y(2),R1(10),R2(10),R$(10)
	GOTO 6000
	DATA "NEW","INV BILLING","INV PAYMENT","PROG PAYMENT","DELETE","MODIFY"
%INCLUDE SUBS1
%INCLUDE BINSEARC
%INCLUDE GENINFO
%INCLUDE A/RTAX
%INCLUDE A/R-INFO
%INCLUDE A/R-INV
%INCLUDE READCUST
%INCLUDE WRITCUST
.314	RETURN								REMARK	THESE LINE NUMBERS FOR G/L SUBROUTINES
.315	RETURN
3650	RETURN



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 LINE.COUNT%<>100 THEN \
		PRINT "REC   CUST INV #";TAB(24);"CASH  ACCT RCVB  SALES";:\
		PRINT " INC  DEFER INC   SHIPPING";TAB(78);"TAXES    INV";:\
		PRINT " AMT TAX TYPE   OP" \
	ELSE \
		PRINT TAB(34);"INV AMT";TAB(48);"SHIP";TAB(58);"TAXES  INV";:\
		PRINT " TOTAL";TAB(78);"INV PAY";TAB(89);"PR BILL   PROG PAY"
	PRINT
	LINE.COUNT%=6
	RETURN 


4000	PRINT USING MASKB$;P1;						REMARK	PRINT POSTING TOTALS
	PRINT " ";X0$;TAB(27);
	IF I1<>0 THEN PRINT USING MASKA$;I1;
	PRINT TAB(38);
	PRINT USING MASKA$;P5
4040	IF P1*P5=0 THEN RETURN						REMARK	UPDATE TRANSACTION TO G/L POSTING FILE
	P4=L1
	RETURN								REMARK	SKIP UNLESS G/L IMPLEMENTED
	EXTERNAL.POSTING.EXTENT%=EXTERNAL.POSTING.EXTENT%+1
	IF EXTERNAL.POSTING.EXTENT% + DIRECT.POSTING.EXTENT% \
	 >= MAX.POSTING.RECORDS THEN GL.FILE.FULL = 1
	FILE.NO%=8:RECORD.NO%=EXTERNAL.POSTING.EXTENT%:GOSUB 3650
	RETURN 


4140	FOR I%=1 TO 11							REMARK	REVERSE SIGN OF INVOICE AMOUNTS
	IF D(I%)<>0 THEN D(I%)=-D(I%)
	NEXT I%
	RETURN 


									REMARK	SAVE TRANSACTION RECORD ON WORKFILE
4160	IF C=5 THEN \							REMARK	ZERO ALL NUMERIC FIELDS ON DELETE-FLAGGED INVOICES
		FOR I%=1 TO 13:\
		D(I%)=0:\
		NEXT I%
	IF H2$<>" " THEN RETURN						REMARK	DO NOT SAVE TRANSACTION IF IT CAUSED AN ERROR
	IF B=2 THEN GOSUB 4140						REMARK	RE-REVERSE THE SIGNS ON A CREDIT MEMO
	GOSUB 6900							REMARK	SAVE THE TRANSACTION TO THE WORKFILE
	IF C>1 THEN INVOICE.POINTER%=INVOICE.POINTER%+1
	RETURN



4260	IF CUSTOMER.POINTER%=0 OR Y(2)=Y1 THEN RETURN
	W$=W1$
	W1$=I1$
	Y9=2:X0=CUSTOMER.POINTER%:GOSUB 3275			REMARK	RESAVE THE CUSTOMER RECORD
	W1$=W$
	RETURN 



6000	MASKA$=" #######.##"						REMARK	START OF MAINLINE CODE
	MASKB$=" #####.#"
	MASKC$=" ######"
	MASKD$="###"
	PRINT CLEAR.SCREEN$;"A/R UPDATE"
	PRINT "WORKING... DO NOT INTERRUPT"
	OPEN "G/I0F010.DAT" AS 1,"A/R0F110.DAT" RECL 162 AS 2,\
	"A/R0F120.DAT" RECL 226 AS 3,"A/R0F020.DAT" RECL 226 AS 4,\
	"A/R0F030.DAT" AS 5, "A/R0F130.DAT" AS 6
	CREATE "WORKFILE.DAT" RECL 226 AS 7
6010	MAX.INVOICE.RECORDS = 200
	MAX.POSTING.RECORDS = 1000
	GOTO 6040							REMARK	SKIP OPENING THE G/L FILES
	OPEN "G/L0F020.DAT" RECL 36 AS 8,"G/L0F130.DAT" AS 9
	FILE.NO%=9:GOSUB .314
6040	Y9=1:GOSUB 700							REMARK	RETRIEVE G/I FILE DATA
	FILE.NO=6:GOSUB 3.14						REMARK	RETRIEVE A/R INFORMATION FILE DATA
	A1=5:GOSUB 3700							REMARK	RETRIEVE A/R TAX CODE INFORMATION
	I1$=" "								REMARK	INITIALIZE VARIABLES
	H2$=" "
	INVOICE.POINTER%=1
	P2=2
	P3=(INT(G3(1)/100))/100
	LINE.COUNT%=60
	LPRINTER

6060	FOR I%=1 TO 7							REMARK	ZERO TRANSACTION TOTALS
	C.(I%)=0
	NEXT I%
	IF R% THEN \
		C2=C2+10:\
		FILE.NO=4:REC.NO%=R%:GOSUB 3450
	IF INV.FILE.FULL THEN GOTO 6840
	IF GL.FILE.FULL THEN GOTO 6850
	R%=R%+1								REMARK	INCREMENT TRANSACTION FILE COUNTER
	IF R%>AR.TRANFILE.EXTENT THEN 6580				REMARK	BRANCH AT END OF TRANSACTION FILE
	FILE.NO=4:REC.NO%=R%:GOSUB 3400					REMARK	RETRIEVE NEXT TRANSACTION DATA
	IF B=2 THEN GOSUB 4140
	C=C2
	IF C>9 THEN 6060						REMARK	SKIP "USED" TRANSACTIONS
	Y2=3
	RECORD.COUNT=AR.INVFILE.EXTENT
	XYZ$=W1$+"      ":ZYX$="000000"+STR$(L1)
	NEW.KEY$=LEFT$(XYZ$,6)+RIGHT$(ZYX$,6)
	IF NEW.KEY$=TRAN.KEY$ THEN H2$="DOUBLE TRANSACTION":GOTO 6360
	TRAN.KEY$=NEW.KEY$
	IF INV.KEY$="ZZZZZZZZZZZZ" THEN 6100				REMARK	IF LAST INVOICE RECORD HAS BEEN READ, BRANCH
	K$=TRAN.KEY$
	GOSUB 1060							REMARK	LOCATE NEXT INVOICE RECORD
	IF INVOICE.POINTER% > AR.INVFILE.EXTENT THEN \
	INV.KEY$="ZZZZZZZZZZZZ":GOTO 6100
	IF INVOICE.POINTER%=L THEN 6070					REMARK	IF NEXT INVOICE HAS NOT CHANGED, BRANCH
	FOR I%=INVOICE.POINTER% TO L-1
	FILE.NO=3:REC.NO%=I%:GOSUB 3400					REMARK	COPY UNCHANGED INVOICE TO WORKFILE
	INVOICE.POINTER%=INVOICE.POINTER%+1
	IF B<>-1 THEN GOSUB 6900
	NEXT I%
	IF INV.FILE.FULL THEN GOTO 6840
	IF L>AR.INVFILE.EXTENT THEN INV.KEY$="ZZZZZZZZZZZZ":GOTO 6080
6070	FILE.NO=3:REC.NO%=INVOICE.POINTER%:GOSUB 3400			REMARK	READ NEXT INVOICE FROM INVOICE FILE
	IF B=2 THEN GOSUB 4140
	XYZ$=W1$+"      ":ZYX$="000000"+STR$(L1)
	INV.KEY$=LEFT$(XYZ$,6)+RIGHT$(ZYX$,6)
	IF B=-1 AND INV.KEY$=TRAN.KEY$ THEN 6060
6080	FILE.NO=4:REC.NO%=R%:GOSUB 3400					REMARK	RE-LOAD TRANSACTION DATA
	IF B=2 THEN GOSUB 4140
6100	IF C=1 AND TRAN.KEY$=INV.KEY$ THEN H2$="DUPLICATE":GOTO 6360	REMARK	CHECK FOR ERRORS
	IF C>1 AND TRAN.KEY$<>INV.KEY$ THEN H2$="NOT ON INV FILE":GOTO 6360
	S(C,8)=S(C,8)+1
	ON C GOTO 6140,6320,6200,6260,6120,6320				REMARK	BRANCH ON OPERATION CODE


6120	D(5)=D(6)							REMARK	OPERATION IS DELETE
	D(9)=D(10)
	GOSUB 4140							REMARK	REVERSE SIGNS TO SUBTRACT VALUES FROM TOTALS
									REMARK	FOR TRANSACTIONS WITH NON-ZERO BILL DATES
6140	IF L4(1)=0 THEN 6240						REMARK	ADD INVOICE AMOUNTS, ETC. TO TOTALS
	C.(5)=C.(5)+D(2)
	F(L6+1,1)=F(L6+1,1)+D(3)
	C.(6)=C.(6)+D(3)
	C.(3)=C.(3)+D(4)
	C.(2)=C.(2)+D(4)
	F(L6+1,2)=F(L6+1,2)+D(1)
	C.(7)=C.(7)+D(1)
	FOR I%=1 TO 4
	S(C,I%)=S(C,I%)+D(I%)
	NEXT I%
	IF L4(2)<>0 THEN C.(2)=C.(2)-D(8):C.(4)=C.(4)-D(8)		REMARK	ADJUST A/R AND DEFERRED INCOME TOTALS
	IF D(13)<>0 THEN P1=ABS(D(13)):P5=SGN(D(13))*D(1):GOSUB 4040	REMARK	POST AMOUNT D(1) TO ACCOUNT D(13)
	IF D(13)<0 THEN F(1,1)=F(1,1)-D(1)
	IF D(13)<=0 THEN F(1,2)=F(1,2)-D(1)
6200	IF D(5)<>0 THEN \						REMARK	ADJUST CASH AND A/R TOTALS WITH NON-ZERO PAYMENTS
		C.(1)=C.(1)+D(5):\
		C.(2)=C.(2)-D(5):\
		S(C,5)=S(C,5)+D(5)
	IF C=3 THEN 6360						REMARK	END OF INVOICE PAYMENT OPERATION
6240	IF L4(2)=0 THEN 6300						REMARK	IF PROGRESS DUE DATE IS NON-ZERO...
	S(C,6)=S(C,6)+D(8)						REMARK	ADJUST TOTALS BY PROGRESS BILLING AMOUNT
	C.(2)=C.(2)+D(8)
	C.(4)=C.(4)+D(8)
6260	IF D(9)<>0 THEN \						REMARK	IF PROGRESS PAYMENT AMOUNT IS NON-ZERO...
		C.(1)=C.(1)+D(9):\					REMARK	ADJUST CASH AND A/R TOTALS
		C.(2)=C.(2)-D(9):\
		S(C,7)=S(C,7)+D(9)
	IF C=4 THEN 6360						REMARK	END OF PROGRESS PAYMENT OPERATION
6300	IF F7=1 THEN GOTO 6340 \
	ELSE GOTO 6360
									REMARK	START MODIFY OPERATION
6320	FILE.NO=3:REC.NO%=INVOICE.POINTER%:GOSUB 3400			REMARK	RETRIEVE OLD INVOICE
	IF B=2 THEN GOSUB 4140
	IF C2=5 THEN 6340
	GOSUB 4140							REMARK	REVERSE SIGNS
	F7=1
	GOTO 6140							REMARK	BACK INVOICE AMOUNTS OUT OF TOTALS
6340	F7=0								REMARK	MODIFY OPERATION, PART TWO
	FILE.NO=4:REC.NO%=R%:GOSUB 3400					REMARK	RETRIEVE MODIFY TRANSACTION DATA
	IF B=2 THEN GOSUB 4140
	GOTO 6140							REMARK	ADD TRANSACTION AMOUNTS TO TOTALS
6360	GOSUB 4160							REMARK	SAVE TRANSACTION ON WORKFILE
	FOR I%=1 TO 4							REMARK	ACCUMULATE TRANSACTION TOTALS TO GRAND TOTALS
	G(I%)=G(I%)+C.(I%)
	NEXT I%
	IF L6=0 THEN G(6)=G(6)+C.(5):\
	ELSE G(5)=G(5)+C.(5)
	X4$="A/R UPDATE":A1=115:GOSUB 825				REMARK	PRINT TRANSACTION TOTALS
	PRINT USING MASKD$;R%;
	PRINT TAB(5);W1$;
	PRINT USING MASKC$;L1;
	FOR I%=1 TO 7
	PRINT USING MASKA$;C.(I%);
	NEXT I%
	PRINT " ";L6;"  ";B;"   ";C;
	IF D(12)<>0 THEN PRINT " (CR) ";
	PRINT TAB(112);H2$
	H2$=" "
	LINE.COUNT%=LINE.COUNT%+1
	IF D(13)<>0 THEN \						REMARK	PRINT G/L NUMBER, IF ANY, ON A SEPARATE LINE
		PRINT "   G/L #";:\
		PRINT USING MASKB$;D(13):\
		LINE.COUNT%=LINE.COUNT%+1
	IF C.(3)+C.(4)=0 THEN 6060
	IF I1$=" " THEN 6460
	IF I1$=W1$ THEN 6500						REMARK	WHEN CUSTOMERS CHANGE...
	GOSUB 4260							REMARK	UPDATE THE OLD CUSTOMER RECORD
6460	XYZ$=W1$+"      "
	Y2=2
	K$=LEFT$(XYZ$,6)
	RECORD.COUNT=AR.CUSTFILE.EXTENT
	GOSUB 1060							REMARK	LOCATE THE NEW CUSTOMER RECORD
	IF H=-1 OR VAR1=0 THEN \
		I1$=" ":\
		PRINT W1$," NOT IN CUSTOMER FILE":\
		CUSTOMER.POINTER%=0:\
		LINE.COUNT%=LINE.COUNT%+1:\
		GOTO 6060
	Y9=2:X0=L:GOSUB 3225						REMARK	AND RETRIEVE THE NEW CUSTOMER DATA
	CUSTOMER.POINTER%=L
	I1$=W1$
	Y1=Y(2)
6500	Y(2)=Y(2)+C.(3)+C.(4)						REMARK	ADD NEW AMOUNTS TO CUSTOMER BILLING TOTAL
	IF L4(1)>D THEN D=L4(1)
	GOTO 6060


6580	LPRINTER							REMARK	END PROGRAM AND PRINT TOTALS
	GOSUB 4260							REMARK	RESAVE LAST CUSTOMER RECORD
	IF INVOICE.POINTER% >= AR.INVFILE.EXTENT THEN 6620		REMARK	COPY THE REST OF THE INVOICE FILE TO THE WORKFILE
	FOR I%=INVOICE.POINTER% TO AR.INVFILE.EXTENT
	FILE.NO=3:REC.NO%=I%:GOSUB 3400
	INVOICE.POINTER%=INVOICE.POINTER%+1
	IF B<>-1 THEN GOSUB 6900
	NEXT I%
6620	LINE.COUNT%=100
	X4$="A/R UPDATE":A1=115:GOSUB 825				REMARK	PRINT TOTALS
	RESTORE 
	FOR I%=1 TO 6
	READ A$
	PRINT USING MASKC$;S(I%,8);
	PRINT TAB(8);" ";
	PRINT A$;" TRANS";TAB(30);
	FOR J%=1 TO 7
	PRINT USING MASKA$;S(I%,J%);
	NEXT J%
	PRINT
	NEXT I%
	PRINT:PRINT:PRINT TAB(9);"GENERAL LEDGER POSTING TOTALS":PRINT
	PRINT "  ACCT # NAME";TAB(43);"AMOUNT"
	L1=0
	P1=2:I1=0:P5=G(1):X0$="CASH":GOSUB 4000
	P1=5:I1=0:P5=G(2):X0$="ACCT. RECEIVABLE":GOSUB 4000
	P1=2029:I1=0:P5=F(2,1)+F(3,1)+F(4,1)+F(5,1)+F(6,1)+F(7,1)+F(8,1)+F(9,1)
	P5=P5+F(10,1):X0$="SALES TAX PAYABLE":GOSUB 4000
	P1=2230:I1=0:P5=G(4):X0$="DEFERRED INCOME":GOSUB 4000
	P1=2611:I1=0:P5=-G(5):X0$="SHIPPING":GOSUB 4000
	P1=3325:I1=0:P5=-G(6):X0$="TRAVEL, ETC.":GOSUB 4000
	PRINT:PRINT:PRINT "  ACCT # SALES ACCOUNTS";TAB(35);"TAX     AMOUNT"
	FOR I%=2 TO 10
	P1=R2(I%):I1=F(I%,1):P5=F(I%,2):X0$=R$(I%):GOSUB 4000
	NEXT I%
	PRINT:PRINT:PRINT TAB(30);"DECREASE   INCREASE"
	P1=0:I1=F(1,1):P5=F(1,2):X0$=R$(1):GOSUB 4000
	PRINT
	GOTO 6800							REMARK	BYPASS SAVING NEW G/L EXTENT INFORMATION
	CLOSE 9
	OPEN "G/L0F130.DAT" AS 9
	FILE.NO%=9:GOSUB .315
6800	IF INV.FILE.FULL OR GL.FILE.FULL THEN GOTO 6810			REMARK	IF UPDATE CONCLUDED SUCCESSFULLY...
	DELETE 4							REMARK	DELETE THE OLD TRANSACTION FILE
	CREATE "A/R0F020.DAT" RECL 226 AS 4				REMARK	CREATE AN EMPTY TRANSACTION FILE
	AR.TRANFILE.EXTENT=0
6810	CLOSE 6
	OPEN "A/R0F130.DAT" AS 6
	AR.INVFILE.EXTENT=OUTPUT.COUNT%
	FILE.NO=6:GOSUB 3.15						REMARK	RESET THE A/R EXTENT INFORMATION
	CLOSE 7
	DELETE 3
	A=RENAME("A/R0F120.DAT","WORKFILE.DAT")
6820	CONSOLE
	PRINT CLEAR.SCREEN$;"A/R UPDATE LOADING MENU"
	CHAIN "A/P000"

6840	CONSOLE								REMARK	INVOICE FILE OVERFLOW DETECTED
	PRINT "INVOICE FILE FULL. PRESS 'RETURN' TO PRINT TOTALS"
6841	IF CONSTAT% THEN PRINT:GOTO 6580 ELSE GOTO 6841


6850	CONSOLE								REMARK	G/L FILE OVERFLOW DETECTED
	PRINT "G/L FILE FULL. PRESS 'RETURN' TO PRINT TOTALS"
6851	IF CONSTAT% THEN PRINT:GOTO 6580 ELSE GOTO 6851
 

6900	OUTPUT.COUNT%=OUTPUT.COUNT%+1					REMARK	SUBROUTINE TO ADD A RECORD TO THE WORKFILE
	IF OUTPUT.COUNT% + AR.INVFILE.EXTENT - INVOICE.POINTER% >= \
	MAX.INVOICE.RECORDS - 1 THEN INV.FILE.FULL = 1
	FILE.NO=7
	REC.NO%=OUTPUT.COUNT%
	GOSUB 3450
	RETURN
