**************************  SALES TAX COMMAND FILE  *********************
* This file summarizes the invoice file for a specified period.
*      It shows the invoices and the type of billing (taxable or
* service) along with the totals for the two types and the total
* sales tax liability for the period.
*      It also includes materials and equipment subject to a use tax
* that has not been paid.  These are entered in the invoices database
* when they come in as well as in the Postfile.
*************************************************************************

USE B:Invoices
ERASE
? 'This file summarizes the data you need to prepare the End-of-Quarter'
? 'report to the State Board of Equalization for SALES TAX collected by'
? 'the agency.  It includes use tax on materials bought out of state or'
? 'bought with our resale number without paying a use tax.'

STORE 'C' TO Dating
DO WHILE !(Dating) = 'C'
   STORE 'YYMMDD' TO Start
   STORE 'YYMMDD' TO Finish
   @ 7, 0 SAY 'This summary is for the period FROM 'GET Start
   @ 7,45 SAY '  TO ' GET Finish
   READ
   @ 9,0 SAY ' '
   ? '   C to CHANGE,'
   ? '<Return> to continue.'
   WAIT TO Dating
   @ 7,0
   ? CHR(27) + CHR(74)
ENDDO Dating

ERASE
@ 5,10 SAY '***********  DO NOT INTERRUPT  ***********'
@ 7,10 SAY 'COMPUTING THE QUARTERLY SALES TAX REPORT'
?
COPY TO Temp FIELDS Inv:Nmbr, Inv:Date, Taxable, Sales:Tax, taxFree, Amount;
 FOR Inv:Date >= Start .AND. Inv:Date <= Finish
USE Temp
SORT ON Inv:Nmbr TO Temp2
USE Temp2 
REPLACE Inv:Nmbr WITH ' USED' FOR VAL(Inv:Nmbr) < 1000

STORE $(Start,3,2)+'/'+$(Start,5,2)+'/'+$(Start,1,2) TO Start
STORE $(Finish,3,2)+'/'+$(Finish,5,2)+'/'+$(Finish,1,2) TO Finish

@  5,0
* SET MARGIN TO 45
SET MARGIN TO 17

SET PRINT ON
STORE 1 TO PageCnt
? 'SALES TAX SUMMARY FROM '+Start+' TO '+Finish+':  Page '+STR(PageCnt,3)
?
? 'INV#    DATE     TAXABLE        TAX    SERVICE       TOTAL'
?
STORE 0 TO Count
STORE 0 TO PageMark
GO TOP
DO WHILE .NOT. EOF
   DISPLAY Inv:Nmbr,Inv:Date,Taxable,Sales:Tax,TaxFree,'  '+STR(Amount,9,2) OFF
   STORE (Count + 1) TO Count
   SKIP
   IF Count = 10
      STORE 0 TO Count
      * Inserts a space every ten records, then waits. The printer
      * is turned off so that "WAIT" does not print on the hardcopy.
      ?
      * The following routine prints 50 entries to a page,
      * then moves to the next page and prints a heading.
      
      STORE (PageMark + 1) TO PageMark
      IF PageMark = 5
         STORE 0 TO PageMark
         ? CHR(12)
         STORE (PageCnt + 1) TO PageCnt

         * Compensates for an offset caused by the 7 lines/inch printing
         IF INT(PageCnt/7) = PageCnt/7
            ?
         ENDIF

         ? 'SALES TAX SUMMARY FROM ' + Start + ' TO ' + Finish+':   Page ' +;
                  STR(PageCnt,3)
         ?
         ? 'INV#    DATE     TAXABLE        TAX    SERVICE       TOTAL'
         ?
      ENDIF
   ENDIF
ENDDO
?
SET PRINT OFF
?
? '             COMPUTING TOTALS NOW.'
?
REPLACE ALL Inv:Nmbr WITH ' ' FOR VAL(Inv:Nmbr) > 1000
TOTAL ON Inv:Nmbr TO Other
USE Other
REPLACE All Inv:Date WITH 'TOTAL'
REPLACE All Inv:Nmbr WITH 'SALES' FOR Inv:Nmbr = '    '
SUM Taxable TO Used FOR Inv:Nmbr = ' USED' 
SUM Amount TO Sold
STORE Sold + Used TO Gross
SUM Sales:Tax TO Collected
SUM TaxFree TO Service
STORE Collected + Service TO Exempt
STORE Gross - Exempt TO Subject
STORE 0.06*Subject + 0.005 TO Payable

* Print totals of all the invoices
GO TOP
SET PRINT ON
DO WHILE .NOT. EOF
   DISPLAY Inv:Nmbr,Inv:Date,Taxable,Sales:Tax,TaxFree,'  '+STR(Amount,9,2) OFF
   STORE Count + 1 TO Count
   SKIP
ENDDO
IF PageMark > 3
   * Formfeed if not enough room to print the following list = CHR(12)
   ? CHR(12)
ENDIF
?
?
? 'ENTER THE FOLLOWING DATA ON THE BOARD OF EQUALIZATION FORM:'
?
* The following segment is not the final, but the state auditor is in right now
* and I've got to get the info out to him, and to the state for this month.
* The final version will include all lines in the form, to allow for changes
* in the way we do our business.  Obviously, this is also the palce to
* print the form if ypu want to do that.  Since the form is used only once
* every three months, we won't automate it entirely.

? '      LINE  1>     TOTAL GROSS SALES:  ' + STR(Sold,9,2)
? '      LINE  2>    SUBJECT TO USE TAX:  ' + STR(Used,9,2)
? '      LINE  3>    TOTAL TRANSACTIONS:  ' + STR(Gross,9,2)
?
? '      LINE  9>    SALES TAX INCLUDED:  ' + STR(Collected,9,2)
? '      LINE 10>  ADVERTISING SERVICES:  ' + STR(Service,9,2) 
? '      LINE 11>      TOTAL EXEMPTIONS:  ' + STR(Exempt,9,2)
? '      LINE 12>  SUBJECT TO STATE TAX:  ' + STR(Subject,9,2)
? '      LINE 13>   AMOUNT OF STATE TAX:  ' + STR(0.05*Subject+0.005,9,2)
? '      LINE 14>  SUBJECT TO LOCAL TAX:  ' + STR(Subject,9,2)
?
? '      LINE 19>   AMOUNT OF LOCAL TAX:  ' + STR(0.01*Subject+0.005,9,2)
?
? '      LINE 21>           TOTAL TAXES:  ' + STR(Payable,9,2)
?
? '      LINE 28> TOTAL DUE AND PAYABLE:  ' + STR(Payable,9,2)
? CHR(12)
* SET MARGIN TO 38
SET MARGIN TO 10

SET PRINT OFF

RELEASE All
USE
DELETE FILE Temp
DELETE FILE Temp2
DELETE FILE Other
RETURN
